mirror of
https://github.com/elk-zone/elk
synced 2024-11-24 15:16:09 +09:00
51 lines
1.4 KiB
Vue
51 lines
1.4 KiB
Vue
<script setup lang="ts">
|
|
import type { UserLogin } from '~/types'
|
|
|
|
const all = useUsers()
|
|
|
|
const sorted = computed(() => {
|
|
return [
|
|
currentUser.value!,
|
|
...all.value.filter(account => account.token !== currentUser.value?.token),
|
|
].filter(Boolean)
|
|
})
|
|
|
|
const router = useRouter()
|
|
const switchUser = (user: UserLogin) => {
|
|
if (user.account.id === currentUser.value?.account.id)
|
|
router.push(getAccountRoute(user.account))
|
|
else
|
|
loginTo(user)
|
|
}
|
|
</script>
|
|
|
|
<template>
|
|
<div sm:min-w-80 max-w-100vw mxa py2 flex="~ col">
|
|
<template v-for="user of sorted" :key="user.id">
|
|
<button
|
|
flex rounded px4 py3 text-left
|
|
hover:bg-active cursor-pointer transition-100
|
|
aria-label="Switch user"
|
|
@click="switchUser(user)"
|
|
>
|
|
<AccountInfo :account="user.account" :hover-card="false" />
|
|
<div flex-auto />
|
|
<div v-if="user.token === currentUser?.token" i-ri:check-line text-primary mya text-2xl />
|
|
</button>
|
|
</template>
|
|
<div border="t base" pt2>
|
|
<CommonDropdownItem
|
|
:text="$t('user.add_existing')"
|
|
icon="i-ri:user-add-line"
|
|
@click="openSigninDialog"
|
|
/>
|
|
<CommonDropdownItem
|
|
v-if="currentUser"
|
|
:text="$t('user.sign_out_account', [getFullHandle(currentUser.account)])"
|
|
icon="i-ri:logout-box-line"
|
|
@click="signout"
|
|
/>
|
|
</div>
|
|
</div>
|
|
</template>
|