1
0
Fork 0
activist/src/components/Sidebar.vue

105 lines
2.4 KiB
Vue
Raw Normal View History

<script lang="ts" setup>
2024-11-24 20:50:39 -05:00
import {ref} from "vue";
import {useRouter} from "vue-router";
2024-11-24 20:50:39 -05:00
import Avatar from 'primevue/avatar';
import Menu from "primevue/menu";
2024-12-02 19:35:53 -05:00
import { type UserAction, userActions } from "@/stores/userActionsStore";
import { useSessionStore } from "@/stores/sessionStore";
2024-11-22 19:38:29 -05:00
import Navigation from "@/components/Navigation.vue";
2024-11-24 20:50:39 -05:00
const sessionStore = useSessionStore();
const router = useRouter();
2024-11-24 20:50:39 -05:00
const logout = () => {
sessionStore.logout();
2024-11-24 20:50:39 -05:00
};
const profile = () => {
router.push({name: "profile"});
};
2024-11-24 20:50:39 -05:00
// Attach handlers.
2024-12-02 19:35:53 -05:00
userActions.map((item: UserAction) => {
switch (item.cmd) {
case "logout":
item.command = logout;
break;
case "profile":
item.command = profile;
break;
2024-11-24 20:50:39 -05:00
}
});
const items = ref(userActions);
const menu = ref();
2024-12-02 19:35:53 -05:00
const toggle = (event: Event) => { menu.value.toggle(event); };
2024-11-22 19:38:29 -05:00
</script>
<template>
<aside>
<Navigation></Navigation>
2024-11-24 20:50:39 -05:00
<div class="mt-auto act-avatar">
<!-- TODO -->
2024-11-24 20:50:39 -05:00
<a class="nav-item" @click="toggle">
<div v-if="sessionStore.isAnonymous">
2024-11-24 20:50:39 -05:00
<Avatar icon="pi pi-user" size="large" shape="circle" />
</div>
<div v-else>
<Avatar v-bind:label="sessionStore.initials" size="large" shape="circle" />
2024-11-24 20:50:39 -05:00
</div>
2024-12-04 09:01:43 -05:00
<span>{{ sessionStore.user.name }}</span>
</a>
2024-11-24 20:50:39 -05:00
<Menu ref="menu" id="overlay_menu" :model="items" :popup="true">
<template #item="{ item, props }">
<a
class="flex items-center"
v-bind:class="{ 'act-useraction': item.needsAuth }"
v-bind="props.action"
v-if="!item.needsAuth || !sessionStore.isAnonymous">
2024-11-24 20:50:39 -05:00
<span v-bind:class="item.icon" />
<span>{{ item.label }}</span>
</a>
</template>
</Menu>
2024-11-22 19:38:29 -05:00
</div>
</aside>
</template>
2024-11-22 19:38:29 -05:00
<style scoped>
@reference "tailwindcss";
@reference "tailwindcss-primeui";
aside {
background-color: #333;
display: flex;
flex-direction: row;
height: 100%;
2024-11-24 20:50:39 -05:00
.act-avatar {
display: none;
}
}
/* Duplicated in Navigation.vue. */
.nav-item {
align-items: center;
display: flex;
flex-direction: column;
padding: 16px;
@apply hover:bg-surface-800 rounded-border text-surface-300 hover:text-white;
span {
@apply text-base;
text-align: center;
}
}
@media (min-width: 640px) {
aside {
flex-direction: column;
2024-11-24 20:50:39 -05:00
.act-avatar {
display: block;
}
}
}
2024-11-22 19:38:29 -05:00
</style>