refactor: separate dialog and edit drafts

zio/stable
三咲智子 2022-11-28 15:55:57 +08:00
parent 7f7eccdd07
commit b8cadca717
No known key found for this signature in database
GPG Key ID: 69992F2250DFD93E
5 changed files with 12 additions and 13 deletions

View File

@ -16,7 +16,7 @@ import {
<HelpPreview @close="closePreviewHelp()" /> <HelpPreview @close="closePreviewHelp()" />
</ModalDialog> </ModalDialog>
<ModalDialog v-model="isPublishDialogOpen"> <ModalDialog v-model="isPublishDialogOpen">
<PublishWidget draft-key="dialog" expanded min-w-180 /> <PublishWidget :draft-key="dialogDraftKey" expanded min-w-180 />
</ModalDialog> </ModalDialog>
<ModalDialog v-model="isImagePreviewDialogOpen"> <ModalDialog v-model="isImagePreviewDialogOpen">
<img :src="imagePreview.src" :alt="imagePreview.alt" max-w-95vw max-h-95vh> <img :src="imagePreview.src" :alt="imagePreview.alt" max-w-95vw max-h-95vh>

View File

@ -1,8 +1,6 @@
<script setup lang="ts"> <script setup lang="ts">
function openDialog() { function openDialog() {
if (dialogDraft.draft.value.editingStatus) openPublishDialog()
openPublishDialog(getDefaultDraft())
else openPublishDialog()
} }
</script> </script>

View File

@ -102,17 +102,14 @@ const deleteAndRedraft = async () => {
// TODO confirm to overwrite // TODO confirm to overwrite
} }
openPublishDialog({ openPublishDialog('dialog', {
params: { ...getParamsFromStatus(status), status: text! }, params: { ...getParamsFromStatus(status), status: text! },
attachments: [], attachments: [],
}) })
} }
function editStatus() { function editStatus() {
if (!dialogDraft.isEmpty) { openPublishDialog(`edit-${status.id}`, {
// TODO confirm to overwrite
}
openPublishDialog({
editingStatus: status, editingStatus: status,
params: getParamsFromStatus(status), params: getParamsFromStatus(status),
attachments: [], attachments: [],

View File

@ -4,6 +4,7 @@ import { STORAGE_KEY_FIRST_VISIT, STORAGE_KEY_ZEN_MODE } from '~/constants'
export const imagePreview = ref({ src: '', alt: '' }) export const imagePreview = ref({ src: '', alt: '' })
export const statusEdit = ref<StatusEdit>() export const statusEdit = ref<StatusEdit>()
export const dialogDraftKey = ref<string>()
export const isFirstVisit = useLocalStorage(STORAGE_KEY_FIRST_VISIT, true) export const isFirstVisit = useLocalStorage(STORAGE_KEY_FIRST_VISIT, true)
export const isZenMode = useLocalStorage(STORAGE_KEY_ZEN_MODE, false) export const isZenMode = useLocalStorage(STORAGE_KEY_ZEN_MODE, false)
export const toggleZenMode = useToggle(isZenMode) export const toggleZenMode = useToggle(isZenMode)
@ -18,9 +19,10 @@ export function openSigninDialog() {
isSigninDialogOpen.value = true isSigninDialogOpen.value = true
} }
export function openPublishDialog(draft?: Draft) { export function openPublishDialog(draftKey = 'dialog', draft?: Draft) {
dialogDraftKey.value = draftKey
if (draft) if (draft)
dialogDraft.draft.value = draft currentUserDrafts.value[draftKey] = draft
isPublishDialogOpen.value = true isPublishDialogOpen.value = true
} }

View File

@ -69,11 +69,13 @@ export function useDraft(draftKey: string, inReplyToId?: string) {
export const dialogDraft = useDraft('dialog') export const dialogDraft = useDraft('dialog')
export function mentionUser(account: Account) { export function mentionUser(account: Account) {
openPublishDialog(getDefaultDraft({ status: `@${account.acct} ` })) openPublishDialog('dialog', getDefaultDraft({
status: `@${account.acct} `,
}))
} }
export function directMessageUser(account: Account) { export function directMessageUser(account: Account) {
openPublishDialog(getDefaultDraft({ openPublishDialog('dialog', getDefaultDraft({
status: `@${account.acct} `, status: `@${account.acct} `,
visibility: 'direct', visibility: 'direct',
})) }))