Skip to content

Commit

Permalink
Merge pull request #46 from nimbus-town/chore/remove-polls
Browse files Browse the repository at this point in the history
  • Loading branch information
shuuji3 authored Jan 20, 2025
2 parents 0a8e017 + 02031ea commit 8dc27b1
Show file tree
Hide file tree
Showing 42 changed files with 5 additions and 756 deletions.
2 changes: 1 addition & 1 deletion components/notification/NotificationCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ if (unsupportedEmojiReactionTypes.includes(notification.type))
</template>
</StatusCard>
</template>
<template v-else-if="notification.type === 'mention' || notification.type === 'poll' || notification.type === 'status'">
<template v-else-if="notification.type === 'mention' || notification.type === 'status'">
<StatusCard :status="notification.status!" />
</template>
<template v-else-if="!unsupportedEmojiReactionTypes.includes(notification.type)">
Expand Down
2 changes: 1 addition & 1 deletion components/notification/NotificationPaginator.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const virtualScroller = false // TODO: fix flickering issue with virtual scroll
const groupCapacity = Number.MAX_VALUE // No limit
const includeNotificationTypes: mastodon.v1.NotificationType[] = ['update', 'mention', 'poll', 'status']
const includeNotificationTypes: mastodon.v1.NotificationType[] = ['update', 'mention', 'status']
let id = 0
Expand Down
1 change: 0 additions & 1 deletion components/notification/NotificationPreferences.client.vue
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ onActivated(() => (busy.value = false))
<CommonCheckbox v-model="pushNotificationData.favourite" hover :label="$t('settings.notifications.push_notifications.alerts.favourite')" />
<CommonCheckbox v-model="pushNotificationData.reblog" hover :label="$t('settings.notifications.push_notifications.alerts.reblog')" />
<CommonCheckbox v-model="pushNotificationData.mention" hover :label="$t('settings.notifications.push_notifications.alerts.mention')" />
<CommonCheckbox v-model="pushNotificationData.poll" hover :label="$t('settings.notifications.push_notifications.alerts.poll')" />
</fieldset>
<fieldset flex="~ col" gap-y-1 py-1>
<legend>{{ $t('settings.notifications.push_notifications.policy.title') }}</legend>
Expand Down
141 changes: 1 addition & 140 deletions components/publish/PublishWidget.vue
Original file line number Diff line number Diff line change
Expand Up @@ -81,57 +81,6 @@ const { editor } = useTiptap({
onPaste: handlePaste,
})
function trimPollOptions() {
const indexLastNonEmpty = draft.value.params.poll!.options.findLastIndex(option => option.trim().length > 0)
const trimmedOptions = draft.value.params.poll!.options.slice(0, indexLastNonEmpty + 1)
if (currentInstance.value?.configuration
&& trimmedOptions.length >= currentInstance.value?.configuration?.polls.maxOptions) {
draft.value.params.poll!.options = trimmedOptions
}
else {
draft.value.params.poll!.options = [...trimmedOptions, '']
}
}
function editPollOptionDraft(event: Event, index: number) {
draft.value.params.poll!.options = Object.assign(draft.value.params.poll!.options.slice(), { [index]: (event.target as HTMLInputElement).value })
trimPollOptions()
}
function deletePollOption(index: number) {
const newPollOptions = draft.value.params.poll!.options.slice()
newPollOptions.splice(index, 1)
draft.value.params.poll!.options = newPollOptions
trimPollOptions()
}
const expiresInOptions = computed(() => [
{
seconds: 1 * 60 * 60,
label: t('time_ago_options.hour_future', 1),
},
{
seconds: 2 * 60 * 60,
label: t('time_ago_options.hour_future', 2),
},
{
seconds: 1 * 24 * 60 * 60,
label: t('time_ago_options.day_future', 1),
},
{
seconds: 2 * 24 * 60 * 60,
label: t('time_ago_options.day_future', 2),
},
{
seconds: 7 * 24 * 60 * 60,
label: t('time_ago_options.day_future', 7),
},
])
const expiresInDefaultOptionIndex = 2
const characterCount = computed(() => {
const text = htmlToText(editor.value?.getHTML() || '')
Expand Down Expand Up @@ -350,107 +299,19 @@ function stopQuestionMarkPropagation(e: KeyboardEvent) {
</div>

<div flex="~ col 1" max-w-full>
<form v-if="isExpanded && draft.params.poll" my-4 flex="~ 1 col" gap-3 m="s--1">
<div v-for="(option, index) in draft.params.poll.options" :key="index" flex="~ row" gap-3>
<input
:value="option" bg-base border="~ base" flex-1 h10 pe-4 rounded-2 w-full flex="~ row" items-center
relative focus-within:box-shadow-outline gap-3 px-4 py-2
:placeholder="$t('polls.option_placeholder', { current: index + 1, max: currentInstance?.configuration?.polls.maxOptions })"
class="option-input" @input="editPollOptionDraft($event, index)"
>
<CommonTooltip placement="top" :content="$t('polls.remove_option')" class="delete-button">
<button
btn-action-icon class="hover:bg-red/75"
:disabled="index === draft.params.poll!.options.length - 1 && (index + 1 !== currentInstance?.configuration?.polls.maxOptions || draft.params.poll!.options[index].length === 0)"
@click.prevent="deletePollOption(index)"
>
<div i-ri:delete-bin-line />
</button>
</CommonTooltip>
<span
v-if="currentInstance?.configuration?.polls.maxCharactersPerOption" class="char-limit-radial"
aspect-ratio-1 h-10
:style="{ background: `radial-gradient(closest-side, rgba(var(--rgb-bg-base)) 79%, transparent 80% 100%), conic-gradient(${draft.params.poll!.options[index].length / currentInstance?.configuration?.polls.maxCharactersPerOption > 1 ? 'var(--c-danger)' : 'var(--c-primary)'} ${draft.params.poll!.options[index].length / currentInstance?.configuration?.polls.maxCharactersPerOption * 100}%, var(--c-primary-fade) 0)` }"
>{{
draft.params.poll!.options[index].length }}</span>
</div>
</form>
<div v-if="shouldExpanded" flex="~ gap-1 1 wrap" m="s--1" pt-2 justify="end" max-w-full border="t base">
<PublishEmojiPicker @select="insertEmoji">
<button btn-action-icon :title="$t('tooltip.emojis')" :aria-label="$t('tooltip.add_emojis')">
<div i-ri:emotion-line />
</button>
</PublishEmojiPicker>

<CommonTooltip
v-if="draft.params.poll === undefined" placement="top" :content="$t('tooltip.add_media')"
>
<CommonTooltip placement="top" :content="$t('tooltip.add_media')">
<button btn-action-icon :aria-label="$t('tooltip.add_media')" @click="pickAttachments">
<div i-ri:image-add-line />
</button>
</CommonTooltip>

<template v-if="draft.attachments.length === 0">
<CommonTooltip v-if="!draft.params.poll" placement="top" :content="$t('polls.create')">
<button
btn-action-icon :aria-label="$t('polls.create')"
@click="draft.params.poll = { options: [''], expiresIn: expiresInOptions[expiresInDefaultOptionIndex].seconds }"
>
<div i-ri:chat-poll-line />
</button>
</CommonTooltip>
<div v-else rounded-full b-1 border-dark flex="~ row" gap-1>
<CommonTooltip placement="top" :content="$t('polls.cancel')">
<button
btn-action-icon b-r border-dark :aria-label="$t('polls.cancel')"
@click="draft.params.poll = undefined"
>
<div i-ri:close-line />
</button>
</CommonTooltip>
<CommonDropdown placement="top">
<CommonTooltip placement="top" :content="$t('polls.settings')">
<button :aria-label="$t('polls.settings')" btn-action-icon w-12>
<div i-ri:list-settings-line />
<div i-ri:arrow-down-s-line text-sm text-secondary me--1 />
</button>
</CommonTooltip>
<template #popper>
<div flex="~ col" gap-1 p-2>
<CommonCheckbox
v-model="draft.params.poll.multiple"
:label="draft.params.poll.multiple ? $t('polls.disallow_multiple') : $t('polls.allow_multiple')"
px-2 gap-3 h-9 flex justify-center hover:bg-active rounded-full
icon-checked="i-ri:checkbox-multiple-blank-line"
icon-unchecked="i-ri:checkbox-blank-circle-line"
/>
<CommonCheckbox
v-model="draft.params.poll.hideTotals"
:label="draft.params.poll.hideTotals ? $t('polls.show_votes') : $t('polls.hide_votes')" px-2 gap-3
h-9 flex justify-center hover:bg-active rounded-full icon-checked="i-ri:eye-close-line"
icon-unchecked="i-ri:eye-line"
/>
</div>
</template>
</CommonDropdown>
<CommonDropdown placement="bottom">
<CommonTooltip placement="top" :content="$t('polls.expiration')">
<button :aria-label="$t('polls.expiration')" btn-action-icon w-12>
<div i-ri:hourglass-line />
<div i-ri:arrow-down-s-line text-sm text-secondary me--1 />
</button>
</CommonTooltip>
<template #popper>
<CommonDropdownItem
v-for="expiresInOption in expiresInOptions" :key="expiresInOption.seconds"
:text="expiresInOption.label" :checked="draft.params.poll!.expiresIn === expiresInOption.seconds"
@click="draft.params.poll!.expiresIn = expiresInOption.seconds"
/>
</template>
</CommonDropdown>
</div>
</template>

<PublishEditorTools v-if="editor" :editor="editor" />

<div flex-auto />
Expand Down
1 change: 0 additions & 1 deletion components/status/StatusContent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ const allowEmbeddedMedia = computed(() => status.card?.html && embeddedMediaPref
</template>
<StatusBody v-if="!(isSensitiveNonSpoiler || hideAllMedia)" :status="status" :newer="newer" :with-action="!isDetails" :class="isDetails ? 'text-xl' : ''" />
<StatusTranslation :status="status" />
<StatusPoll v-if="status.poll" :status="status" />
<StatusMedia
v-if="status.mediaAttachments?.length"
:status="status"
Expand Down
85 changes: 0 additions & 85 deletions components/status/StatusPoll.vue

This file was deleted.

31 changes: 0 additions & 31 deletions composables/masto/publish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,24 +37,11 @@ export function usePublish(options: {
const shouldExpanded = computed(() => options.expanded.value || isExpanded.value || !isEmpty.value)
const isPublishDisabled = computed(() => {
const { params, attachments } = draftItem.value
const firstEmptyInputIndex = params.poll?.options.findIndex(option => option.trim().length === 0)
return isEmpty.value
|| options.isUploading.value
|| isSending.value
|| (attachments.length === 0 && !params.status)
|| failedMessages.value.length > 0
|| (attachments.length > 0 && params.poll !== null && params.poll !== undefined)
|| ((params.poll !== null && params.poll !== undefined)
&& (
(firstEmptyInputIndex !== -1
&& firstEmptyInputIndex !== params.poll.options.length - 1
)
|| params.poll.options.findLastIndex(option => option.trim().length > 0) + 1 < 2
|| (new Set(params.poll.options).size !== params.poll.options.length)
|| (currentInstance.value?.configuration?.polls.maxCharactersPerOption !== undefined
&& params.poll.options.find(option => option.length > currentInstance.value!.configuration!.polls.maxCharactersPerOption) !== undefined
)
))
})

watch(draftItem, () => {
Expand All @@ -70,30 +57,12 @@ export function usePublish(options: {
if (draftItem.value.mentions?.length)
content = `${draftItem.value.mentions.map(i => `@${i}`).join(' ')} ${content}`

let poll

if (draftItem.value.params.poll) {
let options = draftItem.value.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 = { ...draftItem.value.params.poll, options }
}

const payload = {
...draftItem.value.params,
spoilerText: publishSpoilerText.value,
status: content,
mediaIds: draftItem.value.attachments.map(a => a.id),
language: draftItem.value.params.language || preferredLanguage.value,
poll,
...(isGlitchEdition.value ? { 'content-type': 'text/markdown' } : {}),
} as mastodon.rest.v1.CreateStatusParams

Expand Down
14 changes: 1 addition & 13 deletions composables/masto/statusDrafts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,13 @@ export function getDefaultDraftItem(options: Partial<Mutable<mastodon.rest.v1.Cr
spoilerText,
language,
mentions,
poll,
} = options

return {
attachments,
initialText,
params: {
status: status || '',
poll,
inReplyToId,
sensitive: sensitive ?? false,
spoilerText: spoilerText || '',
Expand All @@ -54,17 +52,7 @@ export async function getDraftFromStatus(status: mastodon.v1.Status): Promise<Dr

return getDefaultDraftItem((status.mediaAttachments !== undefined && status.mediaAttachments.length > 0)
? { ...info, mediaIds: status.mediaAttachments.map(att => att.id) }
: {
...info,
poll: status.poll
? {
expiresIn: Math.abs(new Date().getTime() - new Date(status.poll.expiresAt!).getTime()) / 1000,
options: [...status.poll.options.map(({ title }) => title), ''],
multiple: status.poll.multiple,
hideTotals: status.poll.options[0].votesCount === null,
}
: undefined,
})
: { ...info })
}

function getAccountsToMention(status: mastodon.v1.Status) {
Expand Down
Loading

0 comments on commit 8dc27b1

Please sign in to comment.