2022-11-24 06:54:54 +00:00
|
|
|
import type { Attachment, CreateStatusParamsWithStatus } from 'masto'
|
|
|
|
import { STORAGE_KEY_DRAFTS } from '~/constants'
|
2022-11-24 09:15:58 +00:00
|
|
|
import type { Mutable } from '~/types/utils'
|
2022-11-24 06:54:54 +00:00
|
|
|
|
|
|
|
export type DraftMap = Record<string, {
|
2022-11-24 09:15:58 +00:00
|
|
|
params: Mutable<CreateStatusParamsWithStatus>
|
2022-11-24 06:54:54 +00:00
|
|
|
attachments: Attachment[]
|
|
|
|
}>
|
|
|
|
|
|
|
|
const allDrafts = useLocalStorage<Record<string, DraftMap>>(STORAGE_KEY_DRAFTS, {})
|
|
|
|
|
|
|
|
export const currentUserDrafts = computed(() => {
|
|
|
|
if (!currentUser.value?.account?.id)
|
|
|
|
return {}
|
|
|
|
const id = `${currentUser.value.account.acct}@${currentUser.value.server}`
|
|
|
|
if (!allDrafts.value[id])
|
|
|
|
allDrafts.value[id] = {}
|
|
|
|
return allDrafts.value[id]
|
|
|
|
})
|