feat(status): edit & redraft
This commit is contained in:
parent
a8bc64a0c7
commit
823f4c960a
4 changed files with 159 additions and 83 deletions
|
@ -1,9 +1,10 @@
|
|||
import type { Attachment, CreateStatusParamsWithStatus } from 'masto'
|
||||
import type { Attachment, CreateStatusParams, CreateStatusParamsWithStatus, Status } from 'masto'
|
||||
import { STORAGE_KEY_DRAFTS } from '~/constants'
|
||||
import type { Mutable } from '~/types/utils'
|
||||
|
||||
export type DraftMap = Record<string, {
|
||||
params: Mutable<CreateStatusParamsWithStatus>
|
||||
editingStatus?: Status
|
||||
params: Omit<Mutable<CreateStatusParams>, 'status'> & { status?: Exclude<CreateStatusParams['status'], null> }
|
||||
attachments: Attachment[]
|
||||
}>
|
||||
|
||||
|
@ -17,3 +18,45 @@ export const currentUserDrafts = computed(() => {
|
|||
allDrafts.value[id] = {}
|
||||
return allDrafts.value[id]
|
||||
})
|
||||
|
||||
export function getDefaultStatus(inReplyToId?: string): CreateStatusParamsWithStatus {
|
||||
return {
|
||||
status: '',
|
||||
inReplyToId,
|
||||
visibility: 'public',
|
||||
}
|
||||
}
|
||||
|
||||
export function getParamsFromStatus(status: Status) {
|
||||
return {
|
||||
status: status.content,
|
||||
mediaIds: status.mediaAttachments.map(att => att.id),
|
||||
visibility: status.visibility,
|
||||
}
|
||||
}
|
||||
|
||||
export function useDraft(draftKey: string, inReplyToId?: string) {
|
||||
const draft = computed({
|
||||
get() {
|
||||
if (!currentUserDrafts.value[draftKey]) {
|
||||
currentUserDrafts.value[draftKey] = {
|
||||
params: getDefaultStatus(inReplyToId),
|
||||
attachments: [],
|
||||
}
|
||||
}
|
||||
return currentUserDrafts.value[draftKey]
|
||||
},
|
||||
set(val) {
|
||||
currentUserDrafts.value[draftKey] = val
|
||||
},
|
||||
})
|
||||
|
||||
const isEmpty = computed(() => {
|
||||
return (draft.value.params.status ?? '').trim().length === 0
|
||||
&& draft.value.attachments.length === 0
|
||||
})
|
||||
|
||||
return { draft, isEmpty }
|
||||
}
|
||||
|
||||
export const dialogDraft = useDraft('dialog')
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue