From 2ab3d5dbe7017d3f81b4b57c1be2e9ca19910e1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=89=E5=92=B2=E6=99=BA=E5=AD=90?= Date: Thu, 24 Nov 2022 23:48:52 +0800 Subject: [PATCH] refactor: improve UI & types --- components/account/AccountFollowButton.vue | 2 +- components/publish/PublishWidget.vue | 10 ++++++---- components/status/StatusActions.vue | 2 +- components/user/UserSwitcher.vue | 2 +- composables/cache.ts | 6 +++--- composables/statusDrafts.ts | 2 +- composables/users.ts | 5 +++-- pages/@[account]/followers.vue | 2 +- types/index.ts | 2 +- 9 files changed, 18 insertions(+), 15 deletions(-) diff --git a/components/account/AccountFollowButton.vue b/components/account/AccountFollowButton.vue index b7ab1f66..7290a991 100644 --- a/components/account/AccountFollowButton.vue +++ b/components/account/AccountFollowButton.vue @@ -5,7 +5,7 @@ const { account } = defineProps<{ account: Account }>() -const isSelf = $computed(() => currentUser.value?.account?.id === account.id) +const isSelf = $computed(() => currentUser.value?.account.id === account.id) const relationship = $(useRelationship(account)) async function toggleFollow() { diff --git a/components/publish/PublishWidget.vue b/components/publish/PublishWidget.vue index 25a321bb..fadfe757 100644 --- a/components/publish/PublishWidget.vue +++ b/components/publish/PublishWidget.vue @@ -118,7 +118,7 @@ onUnmounted(() => {
- +
{
- + + +
diff --git a/components/status/StatusActions.vue b/components/status/StatusActions.vue index 531df711..b548f92f 100644 --- a/components/status/StatusActions.vue +++ b/components/status/StatusActions.vue @@ -14,7 +14,7 @@ const clipboard = useClipboard() const router = useRouter() const route = useRoute() -const isAuthor = $computed(() => status.account.id === currentUser.value?.account?.id) +const isAuthor = $computed(() => status.account.id === currentUser.value?.account.id) // Use different states to let the user press different actions right after the other const isLoading = $ref({ diff --git a/components/user/UserSwitcher.vue b/components/user/UserSwitcher.vue index 4617dd99..64e1d2b7 100644 --- a/components/user/UserSwitcher.vue +++ b/components/user/UserSwitcher.vue @@ -41,7 +41,7 @@ const sorted = computed(() => { @click="signout" >
- Sign out {{ getAccountHandle(currentUser.account!) }} + Sign out {{ getAccountHandle(currentUser.account) }}
diff --git a/composables/cache.ts b/composables/cache.ts index 38f9ff13..853ca2bd 100644 --- a/composables/cache.ts +++ b/composables/cache.ts @@ -14,7 +14,7 @@ export function setCached(key: string, value: any, override = false) { cache.set(key, value) } -export function fetchStatus(id: string) { +export function fetchStatus(id: string): Promise { const key = `status:${id}` const cached = cache.get(key) if (cached) @@ -28,7 +28,7 @@ export function fetchStatus(id: string) { return promise } -export function fetchAccount(id: string) { +export function fetchAccount(id: string): Promise { const key = `account:${id}` const cached = cache.get(key) if (cached) @@ -42,7 +42,7 @@ export function fetchAccount(id: string) { return promise } -export function fetchAccountByName(acct: string) { +export function fetchAccountByName(acct: string): Promise { const key = `account:${acct}` const cached = cache.get(key) if (cached) diff --git a/composables/statusDrafts.ts b/composables/statusDrafts.ts index c804a923..d93bfb29 100644 --- a/composables/statusDrafts.ts +++ b/composables/statusDrafts.ts @@ -14,7 +14,7 @@ export type DraftMap = Record const allDrafts = useLocalStorage>(STORAGE_KEY_DRAFTS, {}) export const currentUserDrafts = computed(() => { - if (!currentUser.value?.account?.id) + if (!currentUser.value?.account.id) return {} const id = `${currentUser.value.account.acct}@${currentUser.value.server}` if (!allDrafts.value[id]) diff --git a/composables/users.ts b/composables/users.ts index 16025f1a..12b8ac67 100644 --- a/composables/users.ts +++ b/composables/users.ts @@ -1,3 +1,4 @@ +import type { AccountCredentials } from 'masto' import { login as loginMasto } from 'masto' import type { UserLogin } from '~/types' import { DEFAULT_SERVER, STORAGE_KEY_CURRENT_USER, STORAGE_KEY_USERS } from '~/constants' @@ -20,7 +21,7 @@ export const currentServer = computed(() => currentUser.value?.server || export const useUsers = () => users -export async function loginTo(user: UserLogin) { +export async function loginTo(user: UserLogin & { account?: AccountCredentials }) { const existing = users.value.findIndex(u => u.server === user.server && u.token === user.token) if (existing !== -1) { if (currentUserId.value === users.value[existing].account?.id) @@ -48,7 +49,7 @@ export async function signout() { if (!currentUser.value) return - const index = users.value.findIndex(u => u.account?.id === currentUser.value?.account?.id) + const index = users.value.findIndex(u => u.account?.id === currentUser.value?.account.id) if (index === -1) return diff --git a/pages/@[account]/followers.vue b/pages/@[account]/followers.vue index 8840092c..d989af8c 100644 --- a/pages/@[account]/followers.vue +++ b/pages/@[account]/followers.vue @@ -3,7 +3,7 @@ const params = useRoute().params const accountName = $computed(() => params.account as string) const account = await fetchAccountByName(accountName) -const paginator = account ? masto.accounts.getFollowersIterable(account!.id!, {}) : null +const paginator = account ? masto.accounts.getFollowersIterable(account.id, {}) : null