From d546390f5c060bb99b1a3bc34b12a284eed53ec7 Mon Sep 17 00:00:00 2001 From: Anthony Fu Date: Tue, 13 Dec 2022 14:49:22 +0100 Subject: [PATCH] fix: reference conflicts --- composables/statusDrafts.ts | 8 ++++---- composables/users.ts | 35 +++++++++++++++++------------------ 2 files changed, 21 insertions(+), 22 deletions(-) diff --git a/composables/statusDrafts.ts b/composables/statusDrafts.ts index e6848236..d41cd310 100644 --- a/composables/statusDrafts.ts +++ b/composables/statusDrafts.ts @@ -48,16 +48,16 @@ function mentionHTML(acct: string) { } export function getReplyDraft(status: Status) { - const acountsToMention: string[] = [] + const accountsToMention: string[] = [] const userId = currentUser.value?.account.id if (status.account.id !== userId) - acountsToMention.push(status.account.acct) - acountsToMention.push(...(status.mentions.filter(mention => mention.id !== userId).map(mention => mention.acct))) + accountsToMention.push(status.account.acct) + accountsToMention.push(...(status.mentions.filter(mention => mention.id !== userId).map(mention => mention.acct))) return { key: `reply-${status.id}`, draft: () => { return getDefaultDraft({ - initialText: acountsToMention.map(acct => mentionHTML(acct)).join(' '), + initialText: accountsToMention.map(acct => mentionHTML(acct)).join(' '), inReplyToId: status!.id, visibility: status.visibility, }) diff --git a/composables/users.ts b/composables/users.ts index cf3b8b51..bd93e5f5 100644 --- a/composables/users.ts +++ b/composables/users.ts @@ -20,6 +20,11 @@ export const currentUser = computed(() => { return users.value[0] }) +export const currentUserHandle = computed(() => currentUser.value?.account.id + ? `${currentUser.value.account.acct}@${currentUser.value.server}` + : '[anonymous]', +) + export const publicServer = ref(DEFAULT_SERVER) const publicInstance = ref(null) export const currentServer = computed(() => currentUser.value?.server || publicServer.value) @@ -153,30 +158,24 @@ export function checkLogin() { return true } -const userLocalStorages = new Map>>() - /** * Create reactive storage for the current user */ export function useUserLocalStorage(key: string, initial: () => T) { - if (!userLocalStorages.has(key)) - userLocalStorages.set(key, useLocalStorage(key, {}, { deep: true })) + // @ts-expect-error bind value to the function + const storages = useUserLocalStorage._ = useUserLocalStorage._ || new Map>>() - const all = userLocalStorages.get(key) as Ref> - const id = currentUser.value?.account.id - ? `${currentUser.value.account.acct}@${currentUser.value.server}` - : '[anonymous]' + if (!storages.has(key)) + storages.set(key, useLocalStorage(key, {}, { deep: true })) + const all = storages.get(key) as Ref> - all.value[id] = Object.assign(initial(), all.value[id] || {}) - return extendRef( - computed(() => all.value[id]), - { - remove: { - value: () => { - delete all.value[id] - }, - }, - }) + return computed(() => { + const id = currentUser.value?.account.id + ? `${currentUser.value.account.acct}@${currentUser.value.server}` + : '[anonymous]' + all.value[id] = Object.assign(initial(), all.value[id] || {}) + return all.value[id] + }) } /**