1
0
Fork 1
mirror of https://github.com/elk-zone/elk.git synced 2024-11-19 23:40:07 +00:00
elk/components/publish/PublishWidgetFull.client.vue

69 lines
2.3 KiB
Vue
Raw Normal View History

2023-01-05 15:42:36 +00:00
<script setup lang="ts">
import { formatTimeAgo } from '@vueuse/core'
import type { DraftItem } from '~/types'
2023-01-05 15:42:36 +00:00
const route = useRoute()
const { formatNumber } = useHumanReadableNumber()
const timeAgoOptions = useTimeAgoOptions()
2023-01-05 15:42:36 +00:00
const draftKey = ref('home')
2023-01-05 15:42:36 +00: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 15:42:36 +00:00
.map(i => [i, currentUserDrafts.value[i]] as const),
)
watchEffect(() => {
draftKey.value = route.query.draft?.toString() || 'home'
2023-01-05 15:42:36 +00:00
})
onDeactivated(() => {
2023-01-05 15:42:36 +00:00
clearEmptyDrafts()
})
function firstDraftItemOf(drafts: DraftItem | Array<DraftItem>): DraftItem {
if (Array.isArray(drafts))
return drafts[0]
return drafts
}
2023-01-05 15:42:36 +00:00
</script>
<template>
<div flex="~ col" pb-6>
<div inline-flex justify-end h-8>
2023-01-05 15:42:36 +00:00
<VDropdown v-if="nonEmptyDrafts.length" placement="bottom-end">
<button btn-text flex="inline center">
{{ $t('compose.drafts', nonEmptyDrafts.length, { named: { v: formatNumber(nonEmptyDrafts.length) } }) }}&#160;
<div aria-hidden="true" i-ri:arrow-down-s-line />
2023-01-05 15:42:36 +00:00
</button>
<template #popper="{ hide }">
<div flex="~ col">
<NuxtLink
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 15:42:36 +00:00
>
<div>
<div flex="~ gap-1" items-center>
<i18n-t keypath="compose.draft_title">
<code>{{ key }}</code>
</i18n-t>
<span v-if="firstDraftItemOf(drafts).lastUpdated" text-secondary text-sm>
&middot; {{ formatTimeAgo(new Date(firstDraftItemOf(drafts).lastUpdated), timeAgoOptions) }}
2023-01-05 15:42:36 +00:00
</span>
</div>
<div text-secondary>
{{ htmlToText(firstDraftItemOf(drafts).params.status).slice(0, 50) }}
2023-01-05 15:42:36 +00:00
</div>
</div>
</NuxtLink>
</div>
</template>
</VDropdown>
</div>
<div>
<PublishWidgetList expanded class="min-h-100!" :draft-key="draftKey" />
2023-01-05 15:42:36 +00:00
</div>
</div>
</template>