diff --git a/src/lib/api/piefed/schema.d.ts b/src/lib/api/piefed/schema.d.ts index 8583181a..44d14037 100644 --- a/src/lib/api/piefed/schema.d.ts +++ b/src/lib/api/piefed/schema.d.ts @@ -5888,7 +5888,7 @@ export interface components { } PollVoteRequest: { post_id: number - choice_id: number + choice_id: number[] } PollVoteResponse: { banned_from_community: boolean diff --git a/src/lib/api/types/generated.ts b/src/lib/api/types/generated.ts index 189158ee..5ac19930 100644 --- a/src/lib/api/types/generated.ts +++ b/src/lib/api/types/generated.ts @@ -2432,6 +2432,7 @@ export interface PostPoll { local_only: boolean latest_vote?: string choices: PollChoice[] + my_votes?: number[] } export interface PollChoice { @@ -2463,7 +2464,7 @@ export interface PostEvent { export interface PollVote { post_id: number - choice_id: number + choice_id: number[] } export interface SetNote { diff --git a/src/lib/app/error.ts b/src/lib/app/error.ts index 9249379f..62df024b 100644 --- a/src/lib/app/error.ts +++ b/src/lib/app/error.ts @@ -1,4 +1,4 @@ -import { t } from "./i18n" +import { t } from './i18n' // eslint-disable-next-line export function errorMessage(error: any, instance?: string): string { @@ -6,13 +6,17 @@ export function errorMessage(error: any, instance?: string): string { if (typeof error == 'string') { try { error = JSON.parse(error) - } catch { + } catch { /* try without catch would be cool imo */ } } if (error?.body?.message) { - error = JSON.parse(error?.body?.message).error + error = JSON.parse(error?.body?.message) + if (error?.message) { + // probably piefed weird error format + error = error.message + } } else if (error?.message) { error = error?.message } else if (error?.error && typeof error?.error === 'string') { diff --git a/src/lib/feature/post/media/PostPoll.svelte b/src/lib/feature/post/media/PostPoll.svelte index ac93e465..9152c4de 100644 --- a/src/lib/feature/post/media/PostPoll.svelte +++ b/src/lib/feature/post/media/PostPoll.svelte @@ -19,13 +19,18 @@ let { post }: Props = $props() - let selected = $state() + let selected = $state( + post.poll.my_votes?.length == 1 + ? post.poll.my_votes[0] + : post.poll.my_votes, + ) let canVote = $state( !( (post.poll.end_poll && publishedToDate(post.poll.end_poll).getTime() < Date.now()) || - !profile.current.jwt + !profile.current.jwt || + (post.poll.my_votes?.length ?? 0) > 0 ), ) let chosen = $state(canVote ? undefined : -1) @@ -53,18 +58,10 @@ canVote = false if (typeof id !== 'number') { - await Promise.all([ - id.map((i) => - api - .voteOnPoll({ - post_id: post.id, - choice_id: i, - }) - .catch((err) => { - throw err - }), - ), - ]) + await api.voteOnPoll({ + post_id: post.id, + choice_id: id, + }) } else { await api.voteOnPoll({ post_id: post.id,