fix: default reply to visibility (urgent) (#194)

zio/stable
patak 2022-11-28 10:57:42 +01:00 committed by GitHub
parent 0843878a42
commit 8076e5f069
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 6 deletions

View File

@ -8,16 +8,18 @@ const {
draftKey, draftKey,
placeholder = 'What is on your mind?', placeholder = 'What is on your mind?',
inReplyToId, inReplyToId,
inReplyToVisibility = 'public',
expanded: _expanded = false, expanded: _expanded = false,
} = defineProps<{ } = defineProps<{
draftKey: string draftKey: string
placeholder?: string placeholder?: string
inReplyToId?: string inReplyToId?: string
inReplyToVisibility?: StatusVisibility
expanded?: boolean expanded?: boolean
}>() }>()
let isSending = $ref(false) let isSending = $ref(false)
let { draft } = $(useDraft(draftKey, inReplyToId)) let { draft } = $(useDraft(draftKey, inReplyToId, inReplyToVisibility))
const isExistDraft = $computed(() => !!draft.params.status && draft.params.status !== '<p></p>') const isExistDraft = $computed(() => !!draft.params.status && draft.params.status !== '<p></p>')
let isExpanded = $ref(isExistDraft || _expanded) let isExpanded = $ref(isExistDraft || _expanded)
@ -119,7 +121,7 @@ async function publish() {
else else
await useMasto().statuses.update(draft.editingStatus.id, payload) await useMasto().statuses.update(draft.editingStatus.id, payload)
draft = getDefaultDraft({ inReplyToId }) draft = getDefaultDraft({ inReplyToId, visibility: inReplyToVisibility })
isPublishDialogOpen.value = false isPublishDialogOpen.value = false
} }
finally { finally {

View File

@ -1,4 +1,4 @@
import type { Account, Attachment, CreateStatusParams, Status } from 'masto' import type { Account, Attachment, CreateStatusParams, Status, StatusVisibility } from 'masto'
import { STORAGE_KEY_DRAFTS } from '~/constants' import { STORAGE_KEY_DRAFTS } from '~/constants'
import type { Mutable } from '~/types/utils' import type { Mutable } from '~/types/utils'
@ -45,12 +45,11 @@ export function getParamsFromStatus(status: Status): Draft['params'] {
} }
} }
export function useDraft(draftKey: string, inReplyToId?: string) { export function useDraft(draftKey: string, inReplyToId?: string, inReplyToVisibility?: StatusVisibility) {
const draft = computed({ const draft = computed({
get() { get() {
if (!currentUserDrafts.value[draftKey]) if (!currentUserDrafts.value[draftKey])
currentUserDrafts.value[draftKey] = getDefaultDraft({ inReplyToId }) currentUserDrafts.value[draftKey] = getDefaultDraft({ inReplyToId, visibility: inReplyToVisibility })
return currentUserDrafts.value[draftKey] return currentUserDrafts.value[draftKey]
}, },
set(val) { set(val) {

View File

@ -57,6 +57,7 @@ onReactivated(() => {
:draft-key="`reply-${id}`" :draft-key="`reply-${id}`"
:placeholder="`Reply to ${status?.account ? getDisplayName(status.account) : 'this thread'}`" :placeholder="`Reply to ${status?.account ? getDisplayName(status.account) : 'this thread'}`"
:in-reply-to-id="id" :in-reply-to-id="id"
:in-reply-to-visibility="status.visibility"
/> />
<template v-if="context"> <template v-if="context">