diff --git a/components/nav/NavSide.vue b/components/nav/NavSide.vue index ec75afdf..1baa870f 100644 --- a/components/nav/NavSide.vue +++ b/components/nav/NavSide.vue @@ -21,11 +21,11 @@ const { notifications } = useNotifications() + - diff --git a/components/publish/PublishWidget.vue b/components/publish/PublishWidget.vue index 31a40c9d..6d814b71 100644 --- a/components/publish/PublishWidget.vue +++ b/components/publish/PublishWidget.vue @@ -14,7 +14,7 @@ const { placeholder, dialogLabelledBy, } = defineProps<{ - draftKey: string + draftKey?: string initial?: () => Draft placeholder?: string inReplyToId?: string @@ -38,7 +38,10 @@ const shouldExpanded = $computed(() => _expanded || isExpanded || !isEmpty) const { editor } = useTiptap({ content: computed({ get: () => draft.params.status, - set: newVal => draft.params.status = newVal, + set: (newVal) => { + draft.params.status = newVal + draft.lastUpdated = Date.now() + }, }), placeholder: computed(() => placeholder ?? draft.params.inReplyToId ? t('placeholder.replying') : t('placeholder.default_1')), autofocus: shouldExpanded, diff --git a/components/publish/PublishWidgetFull.client.vue b/components/publish/PublishWidgetFull.client.vue new file mode 100644 index 00000000..7ec5bfe9 --- /dev/null +++ b/components/publish/PublishWidgetFull.client.vue @@ -0,0 +1,60 @@ + + + diff --git a/composables/statusDrafts.ts b/composables/statusDrafts.ts index 6c0e040f..618b926b 100644 --- a/composables/statusDrafts.ts +++ b/composables/statusDrafts.ts @@ -5,6 +5,11 @@ import type { Mutable } from '~/types/utils' export const currentUserDrafts = process.server ? computed(() => ({})) : useUserLocalStorage(STORAGE_KEY_DRAFTS, () => ({})) +export const builtinDraftKeys = [ + 'dialog', + 'home', +] + export function getDefaultDraft(options: Partial & Omit> = {}): Draft { const { attachments = [], @@ -21,7 +26,6 @@ export function getDefaultDraft(options: Partial & O return { attachments, initialText, - params: { status: status || '', inReplyToId, @@ -30,6 +34,7 @@ export function getDefaultDraft(options: Partial & O spoilerText: spoilerText || '', language: language || 'en', }, + lastUpdated: Date.now(), } } @@ -78,25 +83,27 @@ export const isEmptyDraft = (draft: Draft | null | undefined) => { } export function useDraft( - draftKey: string, + draftKey?: string, initial: () => Draft = () => getDefaultDraft({}), ) { - const draft = computed({ - get() { - if (!currentUserDrafts.value[draftKey]) - currentUserDrafts.value[draftKey] = initial() - return currentUserDrafts.value[draftKey] - }, - set(val) { - currentUserDrafts.value[draftKey] = val - }, - }) + const draft = draftKey + ? computed({ + get() { + if (!currentUserDrafts.value[draftKey]) + currentUserDrafts.value[draftKey] = initial() + return currentUserDrafts.value[draftKey] + }, + set(val) { + currentUserDrafts.value[draftKey] = val + }, + }) + : ref(initial()) const isEmpty = computed(() => isEmptyDraft(draft.value)) onUnmounted(async () => { // Remove draft if it's empty - if (isEmpty.value) { + if (isEmpty.value && draftKey) { await nextTick() delete currentUserDrafts.value[draftKey] } @@ -117,3 +124,12 @@ export function directMessageUser(account: Account) { visibility: 'direct', }), true) } + +export function clearEmptyDrafts() { + for (const key in currentUserDrafts.value) { + if (builtinDraftKeys.includes(key)) + continue + if (!currentUserDrafts.value[key].params || isEmptyDraft(currentUserDrafts.value[key])) + delete currentUserDrafts.value[key] + } +} diff --git a/layouts/default.vue b/layouts/default.vue index 5f4d1ee4..f3c664cc 100644 --- a/layouts/default.vue +++ b/layouts/default.vue @@ -14,7 +14,7 @@ const wideLayout = computed(() => route.meta.wideLayout ?? false)
- +