refactor: improve UI & types

This commit is contained in:
三咲智子 2022-11-24 23:48:52 +08:00
parent 86c29776a1
commit 2ab3d5dbe7
No known key found for this signature in database
GPG key ID: 69992F2250DFD93E
9 changed files with 18 additions and 15 deletions

View file

@ -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<Status> {
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<Account> {
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<Account> {
const key = `account:${acct}`
const cached = cache.get(key)
if (cached)

View file

@ -14,7 +14,7 @@ export type DraftMap = Record<string, Draft>
const allDrafts = useLocalStorage<Record<string, DraftMap>>(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])

View file

@ -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<string>(() => 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