feat: support showing publish failed messages (#1209)

This commit is contained in:
Alex 2023-01-17 20:56:51 +08:00 committed by GitHub
parent 0b2b9a713b
commit 85e163a0ad
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 93 additions and 17 deletions

View file

@ -16,12 +16,18 @@ export const usePublish = (options: {
let isSending = $ref(false)
const isExpanded = $ref(false)
const failedMessages = $ref<string[]>([])
const shouldExpanded = $computed(() => expanded || isExpanded || !isEmpty)
const isPublishDisabled = $computed(() => {
return isEmpty || isUploading || isSending || (draft.attachments.length === 0 && !draft.params.status)
return isEmpty || isUploading || isSending || (draft.attachments.length === 0 && !draft.params.status) || failedMessages.length > 0
})
watch(() => draft, () => {
if (failedMessages.length > 0)
failedMessages.length = 0
}, { deep: true })
async function publishDraft() {
let content = htmlToText(draft.params.status || '')
if (draft.mentions?.length)
@ -63,6 +69,7 @@ export const usePublish = (options: {
}
catch (err) {
console.error(err)
failedMessages.push((err as Error).message)
}
finally {
isSending = false
@ -74,6 +81,7 @@ export const usePublish = (options: {
isExpanded,
shouldExpanded,
isPublishDisabled,
failedMessages,
publishDraft,
})