ui: go self profile on user switcher

This commit is contained in:
三咲智子 2022-11-28 15:03:26 +08:00
parent 871076f2d9
commit 5e0119aa84
No known key found for this signature in database
GPG key ID: 69992F2250DFD93E

View file

@ -1,4 +1,6 @@
<script setup lang="ts"> <script setup lang="ts">
import type { UserLogin } from '~~/types'
const all = useUsers() const all = useUsers()
const sorted = computed(() => { const sorted = computed(() => {
@ -7,21 +9,27 @@ const sorted = computed(() => {
...all.value.filter(account => account.token !== currentUser.value?.token), ...all.value.filter(account => account.token !== currentUser.value?.token),
].filter(Boolean) ].filter(Boolean)
}) })
const router = useRouter()
const switchUser = (user: UserLogin) => {
if (user.account.id === currentUser.value?.account.id)
router.push(getAccountPath(user.account))
else loginTo(user)
}
</script> </script>
<template> <template>
<div min-w-80 mxa py2 flex="~ col"> <div min-w-80 mxa py2 flex="~ col">
<template v-for="user of sorted" :key="user.id"> <template v-for="user of sorted" :key="user.id">
<Component <button
:is="user.token !== currentUser?.token ? 'button' : 'div'"
flex rounded px4 py3 text-left flex rounded px4 py3 text-left
:class="user.token !== currentUser?.token ? 'hover:bg-active cursor-pointer transition-100' : ''" hover:bg-active cursor-pointer transition-100
@click="loginTo(user)" @click="switchUser(user)"
> >
<AccountInfo :account="user.account" /> <AccountInfo :account="user.account" />
<div flex-auto /> <div flex-auto />
<div v-if="user.token === currentUser?.token" i-ri:check-line text-primary mya text-2xl /> <div v-if="user.token === currentUser?.token" i-ri:check-line text-primary mya text-2xl />
</Component> </button>
</template> </template>
<div border="t base" pt2> <div border="t base" pt2>
<button btn-text flex="~ gap-1" items-center @click="openSigninDialog"> <button btn-text flex="~ gap-1" items-center @click="openSigninDialog">