fix: character count should includes spoiler text (#1535)

* fix: character count should includes spoiler text

* fix: draft empty conditions exclude spoiler text
zio/stable
Alex Liu 2023-02-06 01:36:33 +08:00 committed by GitHub
parent 04c4ff5225
commit 2bd8dc2dd5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 3 deletions

View File

@ -35,7 +35,7 @@ const {
dropZoneRef, dropZoneRef,
} = $(useUploadMediaAttachment($$(draft))) } = $(useUploadMediaAttachment($$(draft)))
let { shouldExpanded, isExpanded, isSending, isPublishDisabled, publishDraft, failedMessages, preferredLanguage } = $(usePublish( let { shouldExpanded, isExpanded, isSending, isPublishDisabled, publishDraft, failedMessages, preferredLanguage, publishSpoilerText } = $(usePublish(
{ {
draftState, draftState,
...$$({ expanded, isUploading, initialDraft: initial }), ...$$({ expanded, isUploading, initialDraft: initial }),
@ -74,6 +74,8 @@ const characterCount = $computed(() => {
}).join(' ').length + 1 }).join(' ').length + 1
} }
length += stringLength(publishSpoilerText)
return length return length
}) })
@ -162,7 +164,7 @@ defineExpose({
<div v-if="draft.params.sensitive"> <div v-if="draft.params.sensitive">
<input <input
v-model="draft.params.spoilerText" v-model="publishSpoilerText"
type="text" type="text"
:placeholder="$t('placeholder.content_warning')" :placeholder="$t('placeholder.content_warning')"
p2 border-rounded w-full bg-transparent p2 border-rounded w-full bg-transparent

View File

@ -21,6 +21,17 @@ export function usePublish(options: {
const isExpanded = $ref(false) const isExpanded = $ref(false)
const failedMessages = $ref<string[]>([]) const failedMessages = $ref<string[]>([])
const publishSpoilerText = $computed({
get() {
return draft.params.sensitive ? draft.params.spoilerText : ''
},
set(val) {
if (!draft.params.sensitive)
return
draft.params.spoilerText = val
},
})
const shouldExpanded = $computed(() => expanded || isExpanded || !isEmpty) const shouldExpanded = $computed(() => expanded || isExpanded || !isEmpty)
const isPublishDisabled = $computed(() => { const isPublishDisabled = $computed(() => {
return isEmpty || isUploading || isSending || (draft.attachments.length === 0 && !draft.params.status) || failedMessages.length > 0 return isEmpty || isUploading || isSending || (draft.attachments.length === 0 && !draft.params.status) || failedMessages.length > 0
@ -41,6 +52,7 @@ export function usePublish(options: {
const payload = { const payload = {
...draft.params, ...draft.params,
spoilerText: publishSpoilerText,
status: content, status: content,
mediaIds: draft.attachments.map(a => a.id), mediaIds: draft.attachments.map(a => a.id),
language: draft.params.language || preferredLanguage, language: draft.params.language || preferredLanguage,
@ -91,6 +103,7 @@ export function usePublish(options: {
isPublishDisabled, isPublishDisabled,
failedMessages, failedMessages,
preferredLanguage, preferredLanguage,
publishSpoilerText,
publishDraft, publishDraft,
}) })
} }

View File

@ -89,7 +89,6 @@ export const isEmptyDraft = (draft: Draft | null | undefined) => {
return (text.length === 0) return (text.length === 0)
&& attachments.length === 0 && attachments.length === 0
&& (params.spoilerText || '').length === 0
} }
export interface UseDraft { export interface UseDraft {