From d17775377555001466fbd54170804d0808976c60 Mon Sep 17 00:00:00 2001 From: Anthony Fu Date: Sat, 26 Nov 2022 00:17:15 +0800 Subject: [PATCH] fix: publish content --- components/publish/PublishWidget.vue | 31 +++++++++++++++++----------- components/status/StatusCard.vue | 2 +- composables/content.ts | 19 +++++++++++------ 3 files changed, 33 insertions(+), 19 deletions(-) diff --git a/components/publish/PublishWidget.vue b/components/publish/PublishWidget.vue index db702924..4b4ecc27 100644 --- a/components/publish/PublishWidget.vue +++ b/components/publish/PublishWidget.vue @@ -29,15 +29,8 @@ const { editor } = useTiptap({ onPaste: handlePaste, }) -const status = $computed(() => { - return { - ...draft.params, - mediaIds: draft.attachments.map(a => a.id), - } as CreateStatusParams -}) - const currentVisibility = $computed(() => { - return STATUS_VISIBILITIES.find(v => v.value === status.visibility) || STATUS_VISIBILITIES[0] + return STATUS_VISIBILITIES.find(v => v.value === draft.params.visibility) || STATUS_VISIBILITIES[0] }) let isUploading = $ref(false) @@ -97,16 +90,30 @@ function chooseVisibility(visibility: StatusVisibility) { } async function publish() { + const payload = { + ...draft.params, + status: htmlToText(draft.params.status || ''), + mediaIds: draft.attachments.map(a => a.id), + } as CreateStatusParams + if (process.dev) { - alert(JSON.stringify(draft.params, null, 2)) - return + // eslint-disable-next-line no-console + console.info({ + raw: draft.params.status, + ...payload, + }) + const result = confirm('[DEV] Payload logged to console, do you want to publish it?') + if (!result) + return } + try { isSending = true + if (!draft.editingStatus) - await masto.statuses.create(status) + await masto.statuses.create(payload) else - await masto.statuses.update(draft.editingStatus.id, status) + await masto.statuses.update(draft.editingStatus.id, payload) draft = getDefaultDraft({ inReplyToId }) isPublishDialogOpen.value = false diff --git a/components/status/StatusCard.vue b/components/status/StatusCard.vue index eef2ecc8..0c24a180 100644 --- a/components/status/StatusCard.vue +++ b/components/status/StatusCard.vue @@ -68,7 +68,7 @@ const timeago = useTimeAgo(() => status.createdAt, {