From 259e11c09719cff6239992f889b7b41a3468fc48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=89=E5=92=B2=E6=99=BA=E5=AD=90?= Date: Tue, 29 Nov 2022 01:46:00 +0800 Subject: [PATCH] feat: warn danger actions for dev --- components/status/StatusActions.vue | 6 ++++++ composables/dialog.ts | 19 +++++++++++++++---- composables/statusDrafts.ts | 4 +++- 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/components/status/StatusActions.vue b/components/status/StatusActions.vue index dab93916..8e44833d 100644 --- a/components/status/StatusActions.vue +++ b/components/status/StatusActions.vue @@ -97,6 +97,12 @@ const deleteStatus = async () => { const deleteAndRedraft = async () => { // TODO confirm to delete + if (process.dev) { + // eslint-disable-next-line no-alert + const result = confirm('[DEV] Are you sure you want to delete and re-draft this post?') + if (!result) + return + } const { text } = await useMasto().statuses.remove(status.id) openPublishDialog('dialog', getDraftFromStatus(status, text), true) diff --git a/composables/dialog.ts b/composables/dialog.ts index c3562f54..4b212b6a 100644 --- a/composables/dialog.ts +++ b/composables/dialog.ts @@ -21,11 +21,22 @@ export function openSigninDialog() { export function openPublishDialog(draftKey = 'dialog', draft?: Draft, overwrite = false): void { dialogDraftKey.value = draftKey - if (overwrite) { - // TODO overwrite warning + + if (draft) { + if (overwrite && !isEmptyDraft(currentUserDrafts.value[draftKey])) { + // TODO overwrite warning + // TODO don't overwrite, have a draft list + if (process.dev) { + // eslint-disable-next-line no-alert + const result = confirm('[DEV] Are you sure you overwrite draft content?') + if (!result) + return + } + } + + if (overwrite || !currentUserDrafts.value[draftKey]) + currentUserDrafts.value[draftKey] = draft } - if (draft && (overwrite || !currentUserDrafts.value[draftKey])) - currentUserDrafts.value[draftKey] = draft isPublishDialogOpen.value = true } diff --git a/composables/statusDrafts.ts b/composables/statusDrafts.ts index da4c2348..d0470eb3 100644 --- a/composables/statusDrafts.ts +++ b/composables/statusDrafts.ts @@ -61,7 +61,9 @@ export function getReplyDraft(status: Status) { } } -export const isEmptyDraft = (draft: Draft) => { +export const isEmptyDraft = (draft: Draft | null | undefined) => { + if (!draft) + return true const { params, attachments } = draft const status = params.status || '' return (status.length === 0 || status === '

')