Clean up MainNavigationBar

This commit is contained in:
Ramon Wenger 2023-04-06 15:44:12 +02:00
parent 5922678363
commit 812d70b1c8
3 changed files with 67 additions and 53 deletions

View File

@ -0,0 +1,26 @@
<template>
<AccountMenuContent
:course-sessions="courseSessionsStore.currentCourseSessions"
:selected-course-session="courseSessionsStore.currentCourseSession?.id"
:user="userStore"
@logout="logout"
@select-course-session="selectCourseSession"
/>
</template>
<script setup lang="ts">
import AccountMenuContent from "@/components/header/AccountMenuContent.vue";
import { useCourseSessionsStore } from "@/stores/courseSessions";
import { useUserStore } from "@/stores/user";
import type { CourseSession } from "@/types";
const logout = () => {
userStore.handleLogout();
};
const selectCourseSession = (courseSession: CourseSession) => {
courseSessionsStore.switchCourseSession(courseSession);
};
const courseSessionsStore = useCourseSessionsStore();
const userStore = useUserStore();
</script>

View File

@ -1,7 +1,7 @@
<script setup lang="ts"> <script setup lang="ts">
import log from "loglevel"; import log from "loglevel";
import AccountMenuContent from "@/components/header/AccountMenuContent.vue"; import AccountMenu from "@/components/header/AccountMenu.vue";
import MobileMenu from "@/components/header/MobileMenu.vue"; import MobileMenu from "@/components/header/MobileMenu.vue";
import NotificationPopover from "@/components/notifications/NotificationPopover.vue"; import NotificationPopover from "@/components/notifications/NotificationPopover.vue";
import NotificationPopoverContent from "@/components/notifications/NotificationPopoverContent.vue"; import NotificationPopoverContent from "@/components/notifications/NotificationPopoverContent.vue";
@ -9,20 +9,19 @@ import ItFullScreenModal from "@/components/ui/ItFullScreenModal.vue";
import { useCourseSessionsStore } from "@/stores/courseSessions"; import { useCourseSessionsStore } from "@/stores/courseSessions";
import { useNotificationsStore } from "@/stores/notifications"; import { useNotificationsStore } from "@/stores/notifications";
import { useUserStore } from "@/stores/user"; import { useUserStore } from "@/stores/user";
import type { CourseSession } from "@/types"; import { useRouteLookups } from "@/utils/route";
import { Popover, PopoverButton, PopoverPanel } from "@headlessui/vue"; import { Popover, PopoverButton, PopoverPanel } from "@headlessui/vue";
import { breakpointsTailwind, useBreakpoints } from "@vueuse/core"; import { breakpointsTailwind, useBreakpoints } from "@vueuse/core";
import { computed, onMounted, reactive } from "vue"; import { computed, onMounted, reactive } from "vue";
import { useI18n } from "vue-i18n"; import { useI18n } from "vue-i18n";
import { useRoute } from "vue-router";
log.debug("MainNavigationBar created"); log.debug("MainNavigationBar created");
const route = useRoute();
const breakpoints = useBreakpoints(breakpointsTailwind); const breakpoints = useBreakpoints(breakpointsTailwind);
const userStore = useUserStore(); const userStore = useUserStore();
const courseSessionsStore = useCourseSessionsStore(); const courseSessionsStore = useCourseSessionsStore();
const notificationsStore = useNotificationsStore(); const notificationsStore = useNotificationsStore();
const { inCockpit, inCompetenceProfile, inCourse, inLearningPath } = useRouteLookups();
const { t } = useI18n(); const { t } = useI18n();
const state = reactive({ const state = reactive({
@ -30,37 +29,6 @@ const state = reactive({
showMobileProfileMenu: false, showMobileProfileMenu: false,
}); });
function inCourse() {
return route.path.startsWith("/course/");
}
function inCockpit() {
const regex = new RegExp("/course/[^/]+/cockpit");
return regex.test(route.path);
}
function inLearningPath() {
const regex = new RegExp("/course/[^/]+/learn");
return regex.test(route.path);
}
function inCompetenceProfile() {
const regex = new RegExp("/course/[^/]+/competence");
return regex.test(route.path);
}
function inMediaLibrary() {
return route.path.startsWith("/media/");
}
function logout() {
userStore.handleLogout();
}
function selectCourseSession(courseSession: CourseSession) {
courseSessionsStore.switchCourseSession(courseSession);
}
function popoverClick(event: Event) { function popoverClick(event: Event) {
if (breakpoints.smaller("lg").value) { if (breakpoints.smaller("lg").value) {
event.preventDefault(); event.preventDefault();
@ -96,11 +64,7 @@ onMounted(() => {
:show="state.showMobileProfileMenu" :show="state.showMobileProfileMenu"
@closemodal="state.showMobileProfileMenu = false" @closemodal="state.showMobileProfileMenu = false"
> >
<AccountMenuContent <AccountMent />
:course-sessions="courseSessionsStore.currentCourseSessions"
:user="userStore"
@logout="logout"
/>
</ItFullScreenModal> </ItFullScreenModal>
</Teleport> </Teleport>
<Transition name="nav"> <Transition name="nav">
@ -129,13 +93,14 @@ onMounted(() => {
<div <div
class="ml-1 border-l border-white pl-3 pr-10 text-2xl text-white" class="ml-1 border-l border-white pl-3 pr-10 text-2xl text-white"
> >
{{ $t("general.title") }} {{ t("general.title") }}
</div> </div>
</router-link> </router-link>
</div> </div>
</div> </div>
<div class="hidden space-x-8 lg:flex"> <div class="hidden space-x-8 lg:flex">
<!-- Navigation Links Desktop -->
<router-link <router-link
v-if=" v-if="
inCourse() && inCourse() &&
@ -146,7 +111,7 @@ onMounted(() => {
class="nav-item" class="nav-item"
:class="{ 'nav-item--active': inCockpit() }" :class="{ 'nav-item--active': inCockpit() }"
> >
{{ $t("cockpit.title") }} {{ t("cockpit.title") }}
</router-link> </router-link>
<router-link <router-link
@ -155,7 +120,7 @@ onMounted(() => {
class="nav-item" class="nav-item"
:class="{ 'nav-item--active': inLearningPath() }" :class="{ 'nav-item--active': inLearningPath() }"
> >
{{ $t("general.learningPath") }} {{ t("general.learningPath") }}
</router-link> </router-link>
<router-link <router-link
@ -164,12 +129,13 @@ onMounted(() => {
class="nav-item" class="nav-item"
:class="{ 'nav-item--active': inCompetenceProfile() }" :class="{ 'nav-item--active': inCompetenceProfile() }"
> >
{{ $t("competences.title") }} {{ t("competences.title") }}
</router-link> </router-link>
</div> </div>
</div> </div>
<div class="flex items-stretch justify-start space-x-8"> <div class="flex items-stretch justify-start space-x-8">
<!-- Notification Bell & Menu -->
<div v-if="userStore.loggedIn" class="nav-item"> <div v-if="userStore.loggedIn" class="nav-item">
<NotificationPopover> <NotificationPopover>
<template #toggleButtonContent> <template #toggleButtonContent>
@ -217,15 +183,7 @@ onMounted(() => {
class="absolute -right-2 top-8 z-50 w-[500px] bg-white shadow-lg" class="absolute -right-2 top-8 z-50 w-[500px] bg-white shadow-lg"
> >
<div class="p-4"> <div class="p-4">
<AccountMenuContent <AccountMenu />
:course-sessions="courseSessionsStore.currentCourseSessions"
:selected-course-session="
courseSessionsStore.currentCourseSession.id
"
:user="userStore"
@logout="logout"
@select-course-session="selectCourseSession"
/>
</div> </div>
</PopoverPanel> </PopoverPanel>
</Popover> </Popover>

30
client/src/utils/route.ts Normal file
View File

@ -0,0 +1,30 @@
import { useRoute } from "vue-router";
export function useRouteLookups() {
const route = useRoute();
function inCourse() {
return route.path.startsWith("/course/");
}
function inCockpit() {
const regex = new RegExp("/course/[^/]+/cockpit");
return regex.test(route.path);
}
function inLearningPath() {
const regex = new RegExp("/course/[^/]+/learn");
return regex.test(route.path);
}
function inCompetenceProfile() {
const regex = new RegExp("/course/[^/]+/competence");
return regex.test(route.path);
}
function inMediaLibrary() {
return route.path.startsWith("/media/");
}
return { inMediaLibrary, inCockpit, inLearningPath, inCompetenceProfile, inCourse };
}