drop/desktop/main/components/HeaderUserWidget.vue

114 lines
3.5 KiB
Vue
Raw Permalink Normal View History

2024-10-08 00:39:42 +11:00
<template>
<Menu v-if="state?.user" as="div" class="relative inline-block">
2024-10-08 00:39:42 +11:00
<MenuButton>
<HeaderWidget>
<div class="inline-flex items-center text-zinc-300 hover:text-white">
<img :src="profilePictureUrl" class="w-5 h-5 rounded-sm" />
<span class="ml-2 text-sm font-bold">{{
state.user.displayName
}}</span>
2024-10-08 00:39:42 +11:00
<ChevronDownIcon class="ml-3 h-4" />
</div>
</HeaderWidget>
</MenuButton>
<transition
enter-active-class="transition ease-out duration-100"
enter-from-class="transform opacity-0 scale-95"
enter-to-class="transform opacity-100 scale-100"
leave-active-class="transition ease-in duration-75"
leave-from-class="transform opacity-100 scale-100"
leave-to-class="transform opacity-0 scale-95"
>
<MenuItems
class="absolute bg-zinc-900 right-0 top-10 z-50 w-56 origin-top-right focus:outline-none shadow-md"
2024-10-08 00:39:42 +11:00
>
<div class="flex-col gap-y-2">
2024-10-08 00:39:42 +11:00
<NuxtLink
to="/id/me"
class="transition inline-flex items-center w-full py-3 px-4 hover:bg-zinc-800"
>
<div class="inline-flex items-center text-zinc-300">
<img :src="profilePictureUrl" class="w-5 h-5 rounded-sm" />
<span class="ml-2 text-sm font-bold">{{
state.user.displayName
}}</span>
2024-10-08 00:39:42 +11:00
</div>
</NuxtLink>
<div class="h-0.5 rounded-full w-full bg-zinc-800" />
<div class="flex flex-col mb-1">
<MenuItem v-if="state.user.admin" v-slot="{ active }">
2024-10-09 17:55:19 +11:00
<a
:href="adminUrl"
target="_blank"
:class="[
active ? 'bg-zinc-800 text-zinc-100' : 'text-zinc-400',
'transition block px-4 py-2 text-sm',
]"
>
Admin Dashboard
2024-10-09 17:55:19 +11:00
</a>
</MenuItem>
2025-03-15 15:05:35 +11:00
<MenuItem
v-for="(nav, navIdx) in navigation"
v-slot="{ active, close }"
>
<button
2025-03-15 15:05:35 +11:00
@click="() => navigate(close, nav)"
2024-10-08 00:39:42 +11:00
:href="nav.route"
:class="[
active ? 'bg-zinc-800 text-zinc-100' : 'text-zinc-400',
'transition text-left block px-4 py-2 text-sm',
2024-10-08 00:39:42 +11:00
]"
>
2025-03-15 15:05:35 +11:00
{{ nav.label }}
</button>
2024-10-08 00:39:42 +11:00
</MenuItem>
</div>
</div>
2024-10-08 00:39:42 +11:00
</MenuItems>
</transition>
</Menu>
</template>
<script setup lang="ts">
import { Menu, MenuButton, MenuItem, MenuItems } from "@headlessui/vue";
import { ChevronDownIcon } from "@heroicons/vue/16/solid";
2024-10-15 20:05:13 +11:00
import type { NavigationItem } from "../types";
2024-10-08 00:39:42 +11:00
import HeaderWidget from "./HeaderWidget.vue";
import { useAppState } from "~/composables/app-state";
import { invoke } from "@tauri-apps/api/core";
const open = ref(false);
const router = useRouter();
router.afterEach(() => {
open.value = false;
2025-03-15 15:05:35 +11:00
});
const state = useAppState();
2025-03-15 15:05:35 +11:00
const profilePictureUrl: string = await useObject(
state.value?.user?.profilePictureObjectId ?? ""
2025-03-15 15:05:35 +11:00
);
const adminUrl: string = await invoke("gen_drop_url", {
path: "/admin",
});
2024-10-08 00:39:42 +11:00
2025-03-15 15:05:35 +11:00
function navigate(close: () => any, to: NavigationItem) {
close();
router.push(to.route);
}
2024-10-08 00:39:42 +11:00
const navigation: NavigationItem[] = [
{
label: "App settings",
route: "/settings",
prefix: "",
},
2024-10-08 00:39:42 +11:00
{
2024-12-23 20:56:11 +11:00
label: "Quit Drop",
route: "/quit",
2024-10-08 00:39:42 +11:00
prefix: "",
2025-03-15 15:05:35 +11:00
},
];
2024-10-08 00:39:42 +11:00
</script>