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 users = await initializeUsers()
|
||||||
const instances = useLocalStorage<Record<string, Instance>>(STORAGE_KEY_SERVERS, mock ? mock.server : {}, { deep: true })
|
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 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>(() => {
|
export const currentUser = computed<UserLogin | undefined>(() => {
|
||||||
if (!currentUserId.value)
|
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 checkUser = (val: UserLogin | undefined): val is UserLogin<true> => !!(val && !val.guest)
|
||||||
export const isGuest = computed(() => !checkUser(currentUser.value))
|
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) =>
|
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(() =>
|
export const currentUserHandle = computed(() =>
|
||||||
isGuestId.value ? GUEST_ID : currentUser.value!.account!.acct
|
isGuestId.value ? GUEST_ID : currentUser.value!.account!.acct
|
||||||
|
|
@ -216,11 +217,7 @@ export async function signout() {
|
||||||
if (!currentUser.value)
|
if (!currentUser.value)
|
||||||
return
|
return
|
||||||
|
|
||||||
const masto = useMasto()
|
const index = users.value.findIndex(u => isSameUser(u, currentUser.value))
|
||||||
|
|
||||||
const _currentUserId = currentUser.value.account!.id
|
|
||||||
|
|
||||||
const index = users.value.findIndex(u => u.account?.id === _currentUserId)
|
|
||||||
|
|
||||||
if (index !== -1) {
|
if (index !== -1) {
|
||||||
// Clear stale data
|
// Clear stale data
|
||||||
|
|
@ -244,6 +241,7 @@ export async function signout() {
|
||||||
if (!currentUserId.value)
|
if (!currentUserId.value)
|
||||||
await useRouter().push('/')
|
await useRouter().push('/')
|
||||||
|
|
||||||
|
const masto = useMasto()
|
||||||
await masto.loginTo(currentUser.value)
|
await masto.loginTo(currentUser.value)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@ const isRootPath = computedEager(() => route.name === 'settings')
|
||||||
</template>
|
</template>
|
||||||
<div xl:w-97 lg:w-78 w-full>
|
<div xl:w-97 lg:w-78 w-full>
|
||||||
<SettingsItem
|
<SettingsItem
|
||||||
v-if="isHydrated && currentUser "
|
v-if="isHydrated && !isGuest"
|
||||||
command
|
command
|
||||||
icon="i-ri:user-line"
|
icon="i-ri:user-line"
|
||||||
:text="$t('settings.profile.label')"
|
:text="$t('settings.profile.label')"
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,7 @@ async function importTokens() {
|
||||||
const users = data.users as UserLogin[]
|
const users = data.users as UserLogin[]
|
||||||
const newUsers: UserLogin[] = []
|
const newUsers: UserLogin[] = []
|
||||||
for (const user of users) {
|
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
|
continue
|
||||||
newUsers.push(user)
|
newUsers.push(user)
|
||||||
}
|
}
|
||||||
|
|
@ -69,8 +69,11 @@ async function importTokens() {
|
||||||
<div p6>
|
<div p6>
|
||||||
<template v-if="loggedInUsers.length">
|
<template v-if="loggedInUsers.length">
|
||||||
<div flex="~ col gap2">
|
<div flex="~ col gap2">
|
||||||
<div v-for="user of loggedInUsers" :key="user.account.id">
|
<div v-for="user of loggedInUsers" :key="getUniqueUserId(user)">
|
||||||
<AccountInfo :account="user.account" :hover-card="false" />
|
<AccountInfo v-if="!user.guest" :account="user.account" :hover-card="false" />
|
||||||
|
<div v-else>
|
||||||
|
TODO: Guest @ settings/users/index.vue
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div my4 border="t base" />
|
<div my4 border="t base" />
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue