forked from Mirrors/elk
fix: settings
This commit is contained in:
parent
bfd5c3a446
commit
f7df0e54f5
3 changed files with 12 additions and 11 deletions
|
@ -44,7 +44,7 @@ const initializeUsers = async (): Promise<Ref<UserLogin[]> | RemovableRef<UserLo
|
|||
const users = await initializeUsers()
|
||||
const instances = useLocalStorage<Record<string, Instance>>(STORAGE_KEY_SERVERS, mock ? mock.server : {}, { deep: true })
|
||||
const currentUserId = useLocalStorage<string>(STORAGE_KEY_CURRENT_USER, mock ? mock.user.account.id : '')
|
||||
const isGuestId = computed(() => currentUserId.value.startsWith(`${GUEST_ID}@`))
|
||||
const isGuestId = computed(() => !currentUserId.value || currentUserId.value.startsWith(`${GUEST_ID}@`))
|
||||
|
||||
export const currentUser = computed<UserLogin | undefined>(() => {
|
||||
if (!currentUserId.value)
|
||||
|
@ -65,8 +65,9 @@ export const currentInstance = computed<null | Instance>(() => {
|
|||
})
|
||||
export const checkUser = (val: UserLogin | undefined): val is UserLogin<true> => !!(val && !val.guest)
|
||||
export const isGuest = computed(() => !checkUser(currentUser.value))
|
||||
export const getUniqueUserId = (user: UserLogin) => user.guest ? `${GUEST_ID}@${user.server}` : user.account.id
|
||||
export const isSameUser = (a: UserLogin | undefined, b: UserLogin | undefined) =>
|
||||
a && b && a.server === b.server && a.token === b.token
|
||||
a && b && getUniqueUserId(a) === getUniqueUserId(b)
|
||||
|
||||
export const currentUserHandle = computed(() =>
|
||||
isGuestId.value ? GUEST_ID : currentUser.value!.account!.acct
|
||||
|
@ -216,11 +217,7 @@ export async function signout() {
|
|||
if (!currentUser.value)
|
||||
return
|
||||
|
||||
const masto = useMasto()
|
||||
|
||||
const _currentUserId = currentUser.value.account!.id
|
||||
|
||||
const index = users.value.findIndex(u => u.account?.id === _currentUserId)
|
||||
const index = users.value.findIndex(u => isSameUser(u, currentUser.value))
|
||||
|
||||
if (index !== -1) {
|
||||
// Clear stale data
|
||||
|
@ -244,6 +241,7 @@ export async function signout() {
|
|||
if (!currentUserId.value)
|
||||
await useRouter().push('/')
|
||||
|
||||
const masto = useMasto()
|
||||
await masto.loginTo(currentUser.value)
|
||||
}
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ const isRootPath = computedEager(() => route.name === 'settings')
|
|||
</template>
|
||||
<div xl:w-97 lg:w-78 w-full>
|
||||
<SettingsItem
|
||||
v-if="isHydrated && currentUser "
|
||||
v-if="isHydrated && !isGuest"
|
||||
command
|
||||
icon="i-ri:user-line"
|
||||
:text="$t('settings.profile.label')"
|
||||
|
|
|
@ -40,7 +40,7 @@ async function importTokens() {
|
|||
const users = data.users as UserLogin[]
|
||||
const newUsers: UserLogin[] = []
|
||||
for (const user of users) {
|
||||
if (loggedInUsers.value.some(u => u.server === user.server && u.account.id === user.account.id))
|
||||
if (loggedInUsers.value.some(u => isSameUser(u, user)))
|
||||
continue
|
||||
newUsers.push(user)
|
||||
}
|
||||
|
@ -69,8 +69,11 @@ async function importTokens() {
|
|||
<div p6>
|
||||
<template v-if="loggedInUsers.length">
|
||||
<div flex="~ col gap2">
|
||||
<div v-for="user of loggedInUsers" :key="user.account.id">
|
||||
<AccountInfo :account="user.account" :hover-card="false" />
|
||||
<div v-for="user of loggedInUsers" :key="getUniqueUserId(user)">
|
||||
<AccountInfo v-if="!user.guest" :account="user.account" :hover-card="false" />
|
||||
<div v-else>
|
||||
TODO: Guest @ settings/users/index.vue
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div my4 border="t base" />
|
||||
|
|
Loading…
Reference in a new issue