diff --git a/frontend/src/components/MobileLayout.vue b/frontend/src/components/MobileLayout.vue index e7846452..2bf061c4 100644 --- a/frontend/src/components/MobileLayout.vue +++ b/frontend/src/components/MobileLayout.vue @@ -1,60 +1,55 @@ @@ -64,7 +59,6 @@ import { useRouter } from 'vue-router' import { watch, ref, onMounted } from 'vue' import { sessionStore } from '@/stores/session' import { usersStore } from '@/stores/user' -import { Popover } from 'frappe-ui' import * as icons from 'lucide-vue-next' const { logout, user, sidebarSettings } = sessionStore() @@ -73,26 +67,47 @@ const router = useRouter() let { userResource } = usersStore() const sidebarLinks = ref(getSidebarLinks()) const otherLinks = ref([]) +const showMenu = ref(false) +const menu = ref(null) onMounted(() => { sidebarSettings.reload( {}, { onSuccess(data) { - Object.keys(data).forEach((key) => { - if (!parseInt(data[key])) { - sidebarLinks.value = sidebarLinks.value.filter( - (link) => link.label.toLowerCase().split(' ').join('_') !== key - ) - } - }) - + filterLinksToShow(data) addOtherLinks() }, } ) }) +const handleOutsideClick = (e) => { + if (menu.value && !menu.value.contains(e.target)) { + showMenu.value = false + } +} + +watch(showMenu, (val) => { + if (val) { + setTimeout(() => { + document.addEventListener('click', handleOutsideClick) + }, 0) + } else { + document.removeEventListener('click', handleOutsideClick) + } +}) + +const filterLinksToShow = (data) => { + Object.keys(data).forEach((key) => { + if (!parseInt(data[key])) { + sidebarLinks.value = sidebarLinks.value.filter( + (link) => link.label.toLowerCase().split(' ').join('_') !== key + ) + } + }) +} + const addOtherLinks = () => { if (user) { otherLinks.value.push({ @@ -122,6 +137,7 @@ watch(userResource, () => { (userResource.data.is_moderator || userResource.data.is_instructor) ) { addQuizzes() + addAssignments() } }) @@ -133,6 +149,14 @@ const addQuizzes = () => { }) } +const addAssignments = () => { + otherLinks.value.push({ + label: 'Assignments', + icon: 'Pencil', + to: 'Assignments', + }) +} + let isActive = (tab) => { return tab.activeFor?.includes(router.currentRoute.value.name) } @@ -158,4 +182,8 @@ const isVisible = (tab) => { else if (tab.label == 'Log out') return isLoggedIn else return true } + +const toggleMenu = () => { + showMenu.value = !showMenu.value +}