fix: store info for all servers
parent
aac689a2f5
commit
4f133aabc0
|
@ -1,9 +1,10 @@
|
|||
import { login as loginMasto } from 'masto'
|
||||
import type { AccountCredentials, Instance } from 'masto'
|
||||
import type { UserLogin } from '~/types'
|
||||
import { DEFAULT_POST_CHARS_LIMIT, DEFAULT_SERVER, STORAGE_KEY_CURRENT_USER, STORAGE_KEY_SERVER, STORAGE_KEY_USERS } from '~/constants'
|
||||
import { DEFAULT_POST_CHARS_LIMIT, DEFAULT_SERVER, STORAGE_KEY_CURRENT_USER, STORAGE_KEY_SERVERS, STORAGE_KEY_USERS } from '~/constants'
|
||||
|
||||
const users = useLocalStorage<UserLogin[]>(STORAGE_KEY_USERS, [], { deep: true })
|
||||
const servers = useLocalStorage<Record<string, Instance>>(STORAGE_KEY_SERVERS, {}, { deep: true })
|
||||
const currentUserId = useLocalStorage<string>(STORAGE_KEY_CURRENT_USER, '')
|
||||
|
||||
export const currentUser = computed<UserLogin | undefined>(() => {
|
||||
|
@ -21,9 +22,9 @@ export const currentServer = computed<string>(() => currentUser.value?.server ||
|
|||
|
||||
export const useUsers = () => users
|
||||
|
||||
export const currentInstance = useLocalStorage<Partial<Instance>>(STORAGE_KEY_SERVER, {}, { deep: true })
|
||||
export const currentInstance = computed<null | Instance>(() => currentUserId.value ? servers.value[currentUserId.value] ?? null : null)
|
||||
|
||||
export const characterLimit = computed(() => currentInstance.value.configuration?.statuses.maxCharacters ?? DEFAULT_POST_CHARS_LIMIT)
|
||||
export const characterLimit = computed(() => currentInstance.value?.configuration.statuses.maxCharacters ?? DEFAULT_POST_CHARS_LIMIT)
|
||||
|
||||
export async function loginTo(user: UserLogin & { account?: AccountCredentials }) {
|
||||
const existing = users.value.findIndex(u => u.server === user.server && u.token === user.token)
|
||||
|
@ -41,10 +42,10 @@ export async function loginTo(user: UserLogin & { account?: AccountCredentials }
|
|||
})
|
||||
const me = await masto.accounts.verifyCredentials()
|
||||
user.account = me
|
||||
currentInstance.value = await masto.instances.fetch()
|
||||
|
||||
users.value.push(user)
|
||||
currentUserId.value = me.id
|
||||
servers.value[me.id] = await masto.instances.fetch()
|
||||
await reloadPage()
|
||||
return true
|
||||
}
|
||||
|
|
|
@ -7,9 +7,9 @@ export const HOST_DOMAIN = process.dev
|
|||
export const DEFAULT_POST_CHARS_LIMIT = 500
|
||||
export const DEFAULT_SERVER = 'mas.to'
|
||||
|
||||
export const STORAGE_KEY_SERVER = 'elk-current-server'
|
||||
export const STORAGE_KEY_DRAFTS = 'elk-drafts'
|
||||
export const STORAGE_KEY_USERS = 'elk-users'
|
||||
export const STORAGE_KEY_SERVERS = 'elk-servers'
|
||||
export const STORAGE_KEY_CURRENT_USER = 'elk-current-user'
|
||||
export const STORAGE_KEY_NOTIFY_TAB = 'elk-notify-tab'
|
||||
export const STORAGE_KEY_FIRST_VISIT = 'elk-first-visit'
|
||||
|
|
Loading…
Reference in New Issue