fix: use piefed post poll my_votes
This commit is contained in:
4 files changed
+20
-18
No files matched your search
Vendored
+1
-1
@@ -5888,7 +5888,7 @@ export interface components {
|
|||||||
}
|
}
|
||||||
PollVoteRequest: {
|
PollVoteRequest: {
|
||||||
post_id: number
|
post_id: number
|
||||||
choice_id: number
|
choice_id: number[]
|
||||||
}
|
}
|
||||||
PollVoteResponse: {
|
PollVoteResponse: {
|
||||||
banned_from_community: boolean
|
banned_from_community: boolean
|
||||||
|
|||||||
@@ -2432,6 +2432,7 @@ export interface PostPoll {
|
|||||||
local_only: boolean
|
local_only: boolean
|
||||||
latest_vote?: string
|
latest_vote?: string
|
||||||
choices: PollChoice[]
|
choices: PollChoice[]
|
||||||
|
my_votes?: number[]
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface PollChoice {
|
export interface PollChoice {
|
||||||
@@ -2463,7 +2464,7 @@ export interface PostEvent {
|
|||||||
|
|
||||||
export interface PollVote {
|
export interface PollVote {
|
||||||
post_id: number
|
post_id: number
|
||||||
choice_id: number
|
choice_id: number[]
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface SetNote {
|
export interface SetNote {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { t } from "./i18n"
|
import { t } from './i18n'
|
||||||
|
|
||||||
// eslint-disable-next-line
|
// eslint-disable-next-line
|
||||||
export function errorMessage(error: any, instance?: string): string {
|
export function errorMessage(error: any, instance?: string): string {
|
||||||
@@ -12,7 +12,11 @@ export function errorMessage(error: any, instance?: string): string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (error?.body?.message) {
|
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) {
|
} else if (error?.message) {
|
||||||
error = error?.message
|
error = error?.message
|
||||||
} else if (error?.error && typeof error?.error === 'string') {
|
} else if (error?.error && typeof error?.error === 'string') {
|
||||||
|
|||||||
@@ -19,13 +19,18 @@
|
|||||||
|
|
||||||
let { post }: Props = $props()
|
let { post }: Props = $props()
|
||||||
|
|
||||||
let selected = $state<number | number[]>()
|
let selected = $state<number | number[] | undefined>(
|
||||||
|
post.poll.my_votes?.length == 1
|
||||||
|
? post.poll.my_votes[0]
|
||||||
|
: post.poll.my_votes,
|
||||||
|
)
|
||||||
|
|
||||||
let canVote = $state<boolean>(
|
let canVote = $state<boolean>(
|
||||||
!(
|
!(
|
||||||
(post.poll.end_poll &&
|
(post.poll.end_poll &&
|
||||||
publishedToDate(post.poll.end_poll).getTime() < Date.now()) ||
|
publishedToDate(post.poll.end_poll).getTime() < Date.now()) ||
|
||||||
!profile.current.jwt
|
!profile.current.jwt ||
|
||||||
|
(post.poll.my_votes?.length ?? 0) > 0
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
let chosen = $state<number | undefined>(canVote ? undefined : -1)
|
let chosen = $state<number | undefined>(canVote ? undefined : -1)
|
||||||
@@ -53,18 +58,10 @@
|
|||||||
canVote = false
|
canVote = false
|
||||||
|
|
||||||
if (typeof id !== 'number') {
|
if (typeof id !== 'number') {
|
||||||
await Promise.all([
|
await api.voteOnPoll({
|
||||||
id.map((i) =>
|
post_id: post.id,
|
||||||
api
|
choice_id: id,
|
||||||
.voteOnPoll({
|
})
|
||||||
post_id: post.id,
|
|
||||||
choice_id: i,
|
|
||||||
})
|
|
||||||
.catch((err) => {
|
|
||||||
throw err
|
|
||||||
}),
|
|
||||||
),
|
|
||||||
])
|
|
||||||
} else {
|
} else {
|
||||||
await api.voteOnPoll({
|
await api.voteOnPoll({
|
||||||
post_id: post.id,
|
post_id: post.id,
|
||||||
|
|||||||
Reference in new issue
Block a user