Skip to content

Commit

Permalink
adminbutton fix
Browse files Browse the repository at this point in the history
  • Loading branch information
masinnae committed May 13, 2024
1 parent c073444 commit 366156f
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions frontend/src/composables/useNavigations.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { computed } from "vue";
import { ref, watch } from "vue";
import useIsAdmin from "@/composables/useIsAdmin";
import { useAuthStore } from "@/stores/auth-store";
import { storeToRefs } from "pinia";
Expand Down Expand Up @@ -28,15 +28,19 @@ const admin_navigations: NavigationData[] = [
export default function useNavigations() {
const { isLoggedIn } = storeToRefs(useAuthStore());
const { isAdmin } = useIsAdmin();
const navigations = computed(() => {
const navigations = ref([]);

const updateNavigations = async () => {
if (!isLoggedIn.value) {
return noLoginNavigations;
}
const navs = main_navigations;
if (isAdmin.value) {
navs.push(...admin_navigations);
navigations.value = noLoginNavigations;
} else {
const navs = [...main_navigations];
if (isAdmin.value) {
navs.push(...admin_navigations);
}
navigations.value = navs;
}
return navs;
});
};
watch([isLoggedIn, isAdmin], updateNavigations, { immediate: true });
return { navigations };
}

0 comments on commit 366156f

Please sign in to comment.