mirror of
https://github.com/versia-pub/frontend.git
synced 2025-12-06 08:28:20 +01:00
feat: ✨ Allow account switcher to switch accounts
This commit is contained in:
parent
a19339bd33
commit
3d9d75c45e
|
|
@ -17,7 +17,7 @@
|
||||||
<DropdownMenuContent class="w-[--radix-dropdown-menu-trigger-width] min-w-56 rounded-lg" side="bottom"
|
<DropdownMenuContent class="w-[--radix-dropdown-menu-trigger-width] min-w-56 rounded-lg" side="bottom"
|
||||||
align="end" :side-offset="4">
|
align="end" :side-offset="4">
|
||||||
<DropdownMenuLabel class="p-0 font-normal">
|
<DropdownMenuLabel class="p-0 font-normal">
|
||||||
<div v-for="identity of identities" class="flex items-center gap-2 px-1 py-1.5 text-left text-sm">
|
<Button @click="switchAccount(identity.account.id)" variant="ghost" size="lg" :href="`/@${identity.account.username}`" v-for="identity of identities" class="flex w-full items-center gap-2 px-1 text-left text-sm">
|
||||||
<Avatar class="size-8" :src="identity.account.avatar" :name="identity.account.display_name" />
|
<Avatar class="size-8" :src="identity.account.avatar" :name="identity.account.display_name" />
|
||||||
<div class="grid flex-1 text-left text-sm leading-tight">
|
<div class="grid flex-1 text-left text-sm leading-tight">
|
||||||
<span class="truncate font-semibold" v-render-emojis="identity.account.emojis">{{
|
<span class="truncate font-semibold" v-render-emojis="identity.account.emojis">{{
|
||||||
|
|
@ -27,7 +27,7 @@
|
||||||
identity.account.acct
|
identity.account.acct
|
||||||
}}</span>
|
}}</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</Button>
|
||||||
<DropdownMenuItem @click="signIn()">
|
<DropdownMenuItem @click="signIn()">
|
||||||
<UserPlus />
|
<UserPlus />
|
||||||
Add account
|
Add account
|
||||||
|
|
@ -64,6 +64,7 @@ import {
|
||||||
import { toast } from "vue-sonner";
|
import { toast } from "vue-sonner";
|
||||||
import { NuxtLink } from "#components";
|
import { NuxtLink } from "#components";
|
||||||
import Avatar from "../profiles/avatar.vue";
|
import Avatar from "../profiles/avatar.vue";
|
||||||
|
import { Button } from "../ui/button";
|
||||||
import {
|
import {
|
||||||
DropdownMenu,
|
DropdownMenu,
|
||||||
DropdownMenuContent,
|
DropdownMenuContent,
|
||||||
|
|
@ -152,4 +153,28 @@ const signOut = async (userId?: string) => {
|
||||||
toast.dismiss(id);
|
toast.dismiss(id);
|
||||||
toast.success("Signed out");
|
toast.success("Signed out");
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const switchAccount = async (userId: string) => {
|
||||||
|
if (userId === identity.value?.account.id) {
|
||||||
|
return await navigateTo(`/@${identity.value.account.username}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
const id = toast.loading("Switching account...");
|
||||||
|
|
||||||
|
const identityToSwitch = identities.value.find(
|
||||||
|
(i) => i.account.id === userId,
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!identityToSwitch) {
|
||||||
|
toast.dismiss(id);
|
||||||
|
toast.error("No identity to switch to");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
identity.value = identityToSwitch;
|
||||||
|
toast.dismiss(id);
|
||||||
|
toast.success("Switched account");
|
||||||
|
|
||||||
|
window.location.href = "/";
|
||||||
|
};
|
||||||
</script>
|
</script>
|
||||||
Loading…
Reference in a new issue