mirror of
https://github.com/elk-zone/elk.git
synced 2024-12-18 09:01:46 +03:00
fix: poll would sometimes remove last entry (#2117)
This commit is contained in:
parent
e251a8a50b
commit
9c9a1f7c35
1 changed files with 23 additions and 3 deletions
|
@ -34,6 +34,8 @@ export function usePublish(options: {
|
||||||
|
|
||||||
const shouldExpanded = $computed(() => expanded || isExpanded || !isEmpty)
|
const shouldExpanded = $computed(() => expanded || isExpanded || !isEmpty)
|
||||||
const isPublishDisabled = $computed(() => {
|
const isPublishDisabled = $computed(() => {
|
||||||
|
const firstEmptyInputIndex = draft.params.poll?.options.findIndex(option => option.trim().length === 0)
|
||||||
|
|
||||||
return isEmpty
|
return isEmpty
|
||||||
|| isUploading
|
|| isUploading
|
||||||
|| isSending
|
|| isSending
|
||||||
|
@ -42,8 +44,10 @@ export function usePublish(options: {
|
||||||
|| (draft.attachments.length > 0 && draft.params.poll !== null && draft.params.poll !== undefined)
|
|| (draft.attachments.length > 0 && draft.params.poll !== null && draft.params.poll !== undefined)
|
||||||
|| ((draft.params.poll !== null && draft.params.poll !== undefined)
|
|| ((draft.params.poll !== null && draft.params.poll !== undefined)
|
||||||
&& (
|
&& (
|
||||||
draft.params.poll.options.length <= 1
|
(firstEmptyInputIndex !== -1
|
||||||
|| (![-1, draft.params.poll.options.length - 1].includes(draft.params.poll.options.findIndex(option => option.trim().length === 0)))
|
&& firstEmptyInputIndex !== draft.params.poll.options.length - 1
|
||||||
|
)
|
||||||
|
|| draft.params.poll.options.findLastIndex(option => option.trim().length > 0) + 1 < 2
|
||||||
|| (new Set(draft.params.poll.options).size !== draft.params.poll.options.length)
|
|| (new Set(draft.params.poll.options).size !== draft.params.poll.options.length)
|
||||||
|| (currentInstance.value?.configuration?.polls.maxCharactersPerOption !== undefined
|
|| (currentInstance.value?.configuration?.polls.maxCharactersPerOption !== undefined
|
||||||
&& draft.params.poll.options.find(option => option.length > currentInstance.value!.configuration!.polls.maxCharactersPerOption) !== undefined
|
&& draft.params.poll.options.find(option => option.length > currentInstance.value!.configuration!.polls.maxCharactersPerOption) !== undefined
|
||||||
|
@ -65,13 +69,29 @@ export function usePublish(options: {
|
||||||
if (draft.mentions?.length)
|
if (draft.mentions?.length)
|
||||||
content = `${draft.mentions.map(i => `@${i}`).join(' ')} ${content}`
|
content = `${draft.mentions.map(i => `@${i}`).join(' ')} ${content}`
|
||||||
|
|
||||||
|
let poll
|
||||||
|
|
||||||
|
if (draft.params.poll) {
|
||||||
|
let options = draft.params.poll.options
|
||||||
|
|
||||||
|
if (currentInstance.value?.configuration !== undefined
|
||||||
|
&& (
|
||||||
|
options.length < currentInstance.value.configuration.polls.maxOptions
|
||||||
|
|| options[options.length - 1].trim().length === 0
|
||||||
|
)
|
||||||
|
)
|
||||||
|
options = options.slice(0, options.length - 1)
|
||||||
|
|
||||||
|
poll = { ...draft.params.poll, options }
|
||||||
|
}
|
||||||
|
|
||||||
const payload = {
|
const payload = {
|
||||||
...draft.params,
|
...draft.params,
|
||||||
spoilerText: publishSpoilerText,
|
spoilerText: publishSpoilerText,
|
||||||
status: content,
|
status: content,
|
||||||
mediaIds: draft.attachments.map(a => a.id),
|
mediaIds: draft.attachments.map(a => a.id),
|
||||||
language: draft.params.language || preferredLanguage,
|
language: draft.params.language || preferredLanguage,
|
||||||
poll: draft.params.poll ? { ...draft.params.poll, options: draft.params.poll.options.slice(0, draft.params.poll.options.length - 1) } : undefined,
|
poll,
|
||||||
...(isGlitchEdition.value ? { 'content-type': 'text/markdown' } : {}),
|
...(isGlitchEdition.value ? { 'content-type': 'text/markdown' } : {}),
|
||||||
} as mastodon.v1.CreateStatusParams
|
} as mastodon.v1.CreateStatusParams
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue