refactor(publish): extract to composables

This commit is contained in:
三咲智子 Kevin Deng 2023-01-10 21:22:39 +08:00
parent df37e7c4de
commit 0ef99f2c8e
No known key found for this signature in database
GPG key ID: 69992F2250DFD93E
5 changed files with 190 additions and 122 deletions

View file

@ -1,4 +1,5 @@
import type { mastodon } from 'masto'
import type { ComputedRef, Ref } from 'vue'
import { STORAGE_KEY_DRAFTS } from '~/constants'
import type { Draft, DraftMap } from '~/types'
import type { Mutable } from '~/types/utils'
@ -89,10 +90,15 @@ export const isEmptyDraft = (draft: Draft | null | undefined) => {
&& (params.spoilerText || '').length === 0
}
export interface UseDraft {
draft: Ref<Draft>
isEmpty: ComputedRef<boolean>
}
export function useDraft(
draftKey?: string,
initial: () => Draft = () => getDefaultDraft({}),
) {
): UseDraft {
const draft = draftKey
? computed({
get() {