Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: character count should includes spoiler text #1535

Merged
merged 2 commits into from
Feb 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions components/publish/PublishWidget.vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const {
dropZoneRef,
} = $(useUploadMediaAttachment($$(draft)))

let { shouldExpanded, isExpanded, isSending, isPublishDisabled, publishDraft, failedMessages, preferredLanguage } = $(usePublish(
let { shouldExpanded, isExpanded, isSending, isPublishDisabled, publishDraft, failedMessages, preferredLanguage, publishSpoilerText } = $(usePublish(
{
draftState,
...$$({ expanded, isUploading, initialDraft: initial }),
Expand Down Expand Up @@ -74,6 +74,8 @@ const characterCount = $computed(() => {
}).join(' ').length + 1
}

length += stringLength(publishSpoilerText)

return length
})

Expand Down Expand Up @@ -156,7 +158,7 @@ defineExpose({

<div v-if="draft.params.sensitive">
<input
v-model="draft.params.spoilerText"
v-model="publishSpoilerText"
type="text"
:placeholder="$t('placeholder.content_warning')"
p2 border-rounded w-full bg-transparent
Expand Down
13 changes: 13 additions & 0 deletions composables/masto/publish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,17 @@ export function usePublish(options: {
const isExpanded = $ref(false)
const failedMessages = $ref<string[]>([])

const publishSpoilerText = $computed({
get() {
return draft.params.sensitive ? draft.params.spoilerText : ''
},
set(val) {
if (!draft.params.sensitive)
return
Comment on lines +29 to +30
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this?

Suggested change
if (!draft.params.sensitive)
return

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, just to make the logic more rigorous, is it recommended to delete it?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't really think when this would be called, so I think it probably doesn't matter either way.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@danielroe Got it, Normal operation here would never call. I wish I could remove this if you prefer cleaner code.

draft.params.spoilerText = val
},
})

const shouldExpanded = $computed(() => expanded || isExpanded || !isEmpty)
const isPublishDisabled = $computed(() => {
return isEmpty || isUploading || isSending || (draft.attachments.length === 0 && !draft.params.status) || failedMessages.length > 0
Expand All @@ -41,6 +52,7 @@ export function usePublish(options: {

const payload = {
...draft.params,
spoilerText: publishSpoilerText,
status: content,
mediaIds: draft.attachments.map(a => a.id),
language: draft.params.language || preferredLanguage,
Expand Down Expand Up @@ -91,6 +103,7 @@ export function usePublish(options: {
isPublishDisabled,
failedMessages,
preferredLanguage,
publishSpoilerText,
publishDraft,
})
}
Expand Down
1 change: 0 additions & 1 deletion composables/masto/statusDrafts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ export const isEmptyDraft = (draft: Draft | null | undefined) => {

return (text.length === 0)
&& attachments.length === 0
&& (params.spoilerText || '').length === 0
}

export interface UseDraft {
Expand Down