2023-01-05 18:42:36 +03:00
|
|
|
<script setup lang="ts">
|
|
|
|
import { formatTimeAgo } from '@vueuse/core'
|
2024-04-08 12:53:26 +03:00
|
|
|
import type { DraftItem } from '~/types'
|
2023-01-05 18:42:36 +03:00
|
|
|
|
|
|
|
const route = useRoute()
|
2023-01-08 15:54:05 +03:00
|
|
|
const { formatNumber } = useHumanReadableNumber()
|
|
|
|
const timeAgoOptions = useTimeAgoOptions()
|
2023-01-05 18:42:36 +03:00
|
|
|
|
2024-02-21 18:20:08 +03:00
|
|
|
const draftKey = ref('home')
|
2023-01-05 18:42:36 +03:00
|
|
|
|
2024-02-21 18:20:08 +03:00
|
|
|
const draftKeys = computed(() => Object.keys(currentUserDrafts.value))
|
|
|
|
const nonEmptyDrafts = computed(() => draftKeys.value
|
|
|
|
.filter(i => i !== draftKey.value && !isEmptyDraft(currentUserDrafts.value[i]))
|
2023-01-05 18:42:36 +03:00
|
|
|
.map(i => [i, currentUserDrafts.value[i]] as const),
|
|
|
|
)
|
|
|
|
|
|
|
|
watchEffect(() => {
|
2024-02-21 18:20:08 +03:00
|
|
|
draftKey.value = route.query.draft?.toString() || 'home'
|
2023-01-05 18:42:36 +03:00
|
|
|
})
|
|
|
|
|
2023-04-27 23:41:10 +03:00
|
|
|
onDeactivated(() => {
|
2023-01-05 18:42:36 +03:00
|
|
|
clearEmptyDrafts()
|
|
|
|
})
|
2024-04-08 12:53:26 +03:00
|
|
|
|
|
|
|
function firstDraftItemOf(drafts: DraftItem | Array<DraftItem>): DraftItem {
|
|
|
|
if (Array.isArray(drafts))
|
|
|
|
return drafts[0]
|
|
|
|
return drafts
|
|
|
|
}
|
2023-01-05 18:42:36 +03:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
2024-04-08 12:53:26 +03:00
|
|
|
<div flex="~ col" pb-6>
|
2023-01-18 16:54:36 +03:00
|
|
|
<div inline-flex justify-end h-8>
|
2023-01-05 18:42:36 +03:00
|
|
|
<VDropdown v-if="nonEmptyDrafts.length" placement="bottom-end">
|
|
|
|
<button btn-text flex="inline center">
|
2024-04-08 12:53:26 +03:00
|
|
|
{{ $t('compose.drafts', nonEmptyDrafts.length, { named: { v: formatNumber(nonEmptyDrafts.length) } }) }} 
|
|
|
|
<div aria-hidden="true" i-ri:arrow-down-s-line />
|
2023-01-05 18:42:36 +03:00
|
|
|
</button>
|
|
|
|
<template #popper="{ hide }">
|
|
|
|
<div flex="~ col">
|
|
|
|
<NuxtLink
|
2024-04-08 12:53:26 +03:00
|
|
|
v-for="[key, drafts] of nonEmptyDrafts" :key="key" border="b base" text-left py2 px4
|
|
|
|
hover:bg-active :replace="true" :to="`/compose?draft=${encodeURIComponent(key)}`" @click="hide()"
|
2023-01-05 18:42:36 +03:00
|
|
|
>
|
|
|
|
<div>
|
|
|
|
<div flex="~ gap-1" items-center>
|
2023-01-08 15:54:05 +03:00
|
|
|
<i18n-t keypath="compose.draft_title">
|
|
|
|
<code>{{ key }}</code>
|
|
|
|
</i18n-t>
|
2024-04-08 12:53:26 +03:00
|
|
|
<span v-if="firstDraftItemOf(drafts).lastUpdated" text-secondary text-sm>
|
|
|
|
· {{ formatTimeAgo(new Date(firstDraftItemOf(drafts).lastUpdated), timeAgoOptions) }}
|
2023-01-05 18:42:36 +03:00
|
|
|
</span>
|
|
|
|
</div>
|
|
|
|
<div text-secondary>
|
2024-04-08 12:53:26 +03:00
|
|
|
{{ htmlToText(firstDraftItemOf(drafts).params.status).slice(0, 50) }}
|
2023-01-05 18:42:36 +03:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</NuxtLink>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
</VDropdown>
|
|
|
|
</div>
|
|
|
|
<div>
|
2024-04-08 12:53:26 +03:00
|
|
|
<PublishWidgetList expanded class="min-h-100!" :draft-key="draftKey" />
|
2023-01-05 18:42:36 +03:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|