refactor(status): remove null fields

This commit is contained in:
三咲智子 2023-01-04 18:21:18 +08:00
parent b0d6f310a8
commit 9677f742c8
No known key found for this signature in database
GPG key ID: 69992F2250DFD93E
6 changed files with 38 additions and 46 deletions

View file

@ -1,32 +1,35 @@
import type { Account, Status } from 'masto'
import type { Account, CreateStatusParams, Status } from 'masto'
import { STORAGE_KEY_DRAFTS } from '~/constants'
import type { Draft, DraftMap } from '~/types'
import type { Mutable } from '~/types/utils'
export const currentUserDrafts = process.server ? computed<DraftMap>(() => ({})) : useUserLocalStorage<DraftMap>(STORAGE_KEY_DRAFTS, () => ({}))
export function getDefaultDraft(options: Partial<Draft['params'] & Omit<Draft, 'params'>> = {}): Draft {
export function getDefaultDraft(options: Partial<Mutable<CreateStatusParams> & Omit<Draft, 'params'>> = {}): Draft {
const {
status = '',
inReplyToId,
visibility = 'public',
attachments = [],
initialText = '',
sensitive = false,
spoilerText = '',
status,
inReplyToId,
visibility,
sensitive,
spoilerText,
language,
} = options
return {
params: {
status,
inReplyToId,
visibility,
sensitive,
spoilerText,
language,
},
attachments,
initialText,
params: {
status: status || '',
inReplyToId,
visibility: visibility || 'public',
sensitive: sensitive ?? false,
spoilerText: spoilerText || '',
language: language || 'en',
},
}
}

View file

@ -18,7 +18,7 @@ import { CustomEmoji } from './tiptap/custom-emoji'
import { Emoji } from './tiptap/emoji'
export interface UseTiptapOptions {
content: Ref<string | undefined>
content: Ref<string>
placeholder: Ref<string | undefined>
onSubmit: () => void
onFocus: () => void