diff --git a/src/lib/api/base.ts b/src/lib/api/base.ts index 87c90a9f..c26f1700 100644 --- a/src/lib/api/base.ts +++ b/src/lib/api/base.ts @@ -235,6 +235,7 @@ export abstract class BaseClient { abstract getTopics?(form: types.GetTopics): Promise abstract assignFlair?(form: types.AssignFlair): Promise abstract listMedia(form: types.ListMedia): Promise + abstract voteOnPoll?(form: types.PollVote): Promise } export type NullableFnArg = T extends ( diff --git a/src/lib/api/piefed/adapter.ts b/src/lib/api/piefed/adapter.ts index 2efea6d2..476a3f19 100644 --- a/src/lib/api/piefed/adapter.ts +++ b/src/lib/api/piefed/adapter.ts @@ -1020,4 +1020,14 @@ export class PiefedClient implements BaseClient { async listMedia(): ReturnType { throw new Error('unsupported') } + + async voteOnPoll( + params: NullableFnArg[0], + ): NullableFnReturn { + const response = ( + await this.#client.POST('/api/alpha/post/poll_vote', { body: params }) + ).data! + + return toPostView(response) + } } diff --git a/src/lib/api/piefed/schema.d.ts b/src/lib/api/piefed/schema.d.ts index 2c60c1cb..d0627795 100644 --- a/src/lib/api/piefed/schema.d.ts +++ b/src/lib/api/piefed/schema.d.ts @@ -5888,6 +5888,7 @@ export interface components { } PollVoteRequest: { post_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 3e08a9c7..2eeb6c5b 100644 --- a/src/lib/api/types/generated.ts +++ b/src/lib/api/types/generated.ts @@ -2450,3 +2450,8 @@ export interface PostEvent { [key: string]: unknown } } + +export interface PollVote { + post_id: number + choice_id: number +} diff --git a/src/lib/app/i18n/en.json b/src/lib/app/i18n/en.json index f61ab8f5..ed7444fc 100644 --- a/src/lib/app/i18n/en.json +++ b/src/lib/app/i18n/en.json @@ -581,7 +581,12 @@ "created": "Created {{default}}" }, "poll": { - "votes": "{{votes:number}} votes" + "votes": "{{votes:number}} votes", + "results": { + "show": "Show results", + "hide": "Hide results", + "ends": "Ends {{time}}" + } } }, "comment": { diff --git a/src/lib/feature/post/feed/VirtualFeed.svelte b/src/lib/feature/post/feed/VirtualFeed.svelte index c8729e18..92e69019 100644 --- a/src/lib/feature/post/feed/VirtualFeed.svelte +++ b/src/lib/feature/post/feed/VirtualFeed.svelte @@ -203,7 +203,7 @@ onhide={() => { posts = posts.toSpliced(row, 1) }} - class="px-3 sm:px-6 hover:bg-slate-100/50 hover:dark:bg-zinc-900/50 transition-colors" + class="px-3 sm:px-6 hover:bg-slate-100/30 hover:dark:bg-zinc-900/30 transition-colors" > {/snippet} diff --git a/src/lib/feature/post/media/PostPoll.svelte b/src/lib/feature/post/media/PostPoll.svelte index 9e43e8f1..70981ee4 100644 --- a/src/lib/feature/post/media/PostPoll.svelte +++ b/src/lib/feature/post/media/PostPoll.svelte @@ -1,11 +1,14 @@
- {#each post.poll.choices as choice} -
  • + {#each options.toSorted((a, b) => a.sort_order - b.sort_order) as choice} + {@const active = selected == choice.id} + {@const percentage = Math.floor( + (choice.num_votes / totalVotes || 0) * 100, + )} +
  • {#if chosen}
    {/if}