refactor(status): remove null fields
This commit is contained in:
parent
b0d6f310a8
commit
9677f742c8
@ -3,7 +3,7 @@ import ISO6391 from 'iso-639-1'
|
||||
import Fuse from 'fuse.js'
|
||||
|
||||
let { modelValue } = $defineModel<{
|
||||
modelValue: string | null | undefined
|
||||
modelValue: string
|
||||
}>()
|
||||
|
||||
const { t } = useI18n()
|
||||
@ -11,17 +11,14 @@ const { t } = useI18n()
|
||||
const languageKeyword = $ref('')
|
||||
|
||||
const languageList: {
|
||||
code: string | null
|
||||
code: string
|
||||
nativeName: string
|
||||
name?: string
|
||||
}[] = [{
|
||||
code: null,
|
||||
nativeName: t('language.none'),
|
||||
}, ...ISO6391.getAllCodes().map(code => ({
|
||||
name: string
|
||||
}[] = ISO6391.getAllCodes().map(code => ({
|
||||
code,
|
||||
nativeName: ISO6391.getNativeName(code),
|
||||
name: ISO6391.getName(code),
|
||||
}))]
|
||||
}))
|
||||
|
||||
const fuse = new Fuse(languageList, {
|
||||
keys: ['code', 'nativeName', 'name'],
|
||||
@ -32,15 +29,11 @@ const languages = $computed(() =>
|
||||
languageKeyword.trim()
|
||||
? fuse.search(languageKeyword).map(r => r.item)
|
||||
: [...languageList].sort(({ code: a }, { code: b }) => {
|
||||
return a === modelValue
|
||||
? -1
|
||||
: b === modelValue
|
||||
? 1
|
||||
: (a === null ? -1 : b === null ? 1 : a.localeCompare(b))
|
||||
return a === modelValue ? -1 : b === modelValue ? 1 : a.localeCompare(b)
|
||||
}),
|
||||
)
|
||||
|
||||
function chooseLanguage(language: string | null) {
|
||||
function chooseLanguage(language: string) {
|
||||
modelValue = language
|
||||
}
|
||||
</script>
|
||||
@ -57,16 +50,11 @@ function chooseLanguage(language: string | null) {
|
||||
<CommonDropdownItem
|
||||
v-for="{ code, nativeName, name } in languages"
|
||||
:key="code"
|
||||
:checked="code === (modelValue || null)"
|
||||
:text="nativeName"
|
||||
:description="name"
|
||||
:checked="code === modelValue"
|
||||
@click="chooseLanguage(code)"
|
||||
>
|
||||
{{ nativeName }}
|
||||
<template #description>
|
||||
<template v-if="name">
|
||||
{{ name }}
|
||||
</template>
|
||||
</template>
|
||||
</CommonDropdownItem>
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
@ -333,9 +333,7 @@ defineExpose({
|
||||
</button>
|
||||
|
||||
<template #popper>
|
||||
<div min-w-80 p3>
|
||||
<PublishLanguagePicker v-model="draft.params.language" />
|
||||
</div>
|
||||
<PublishLanguagePicker v-model="draft.params.language" min-w-80 p3 />
|
||||
</template>
|
||||
</CommonDropdown>
|
||||
</CommonTooltip>
|
||||
|
@ -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',
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
@ -1,6 +1,6 @@
|
||||
import type { Account, AccountCredentials, Attachment, CreateStatusParams, Emoji, Instance, MastoClient, Notification, PushSubscription, Status } from 'masto'
|
||||
import type { Ref } from 'vue'
|
||||
import type { Mutable } from './utils'
|
||||
import type { MarkNonNullable, Mutable } from './utils'
|
||||
|
||||
export interface AppInfo {
|
||||
id: string
|
||||
@ -59,9 +59,7 @@ export type TranslateFn = ReturnType<typeof useI18n>['t']
|
||||
export interface Draft {
|
||||
editingStatus?: Status
|
||||
initialText?: string
|
||||
params: Omit<Mutable<CreateStatusParams>, 'status'> & {
|
||||
status?: Exclude<CreateStatusParams['status'], null>
|
||||
}
|
||||
params: MarkNonNullable<Mutable<CreateStatusParams>, 'status' | 'language' | 'sensitive' | 'spoilerText' | 'visibility'>
|
||||
attachments: Attachment[]
|
||||
}
|
||||
export type DraftMap = Record<string, Draft>
|
||||
|
@ -1,3 +1,8 @@
|
||||
export type Mutable<T> = {
|
||||
-readonly[P in keyof T]: T[P]
|
||||
}
|
||||
|
||||
export type Overwrite<T, O> = Omit<T, keyof O> & O
|
||||
export type MarkNonNullable<T, K extends keyof T> = Overwrite<T, {
|
||||
[P in K]-?: NonNullable<T[P]>
|
||||
}>
|
||||
|
Loading…
Reference in New Issue
Block a user