fix: login menu now works on all browsers and devices

This commit is contained in:
Jannat Patel
2025-05-26 10:58:17 +05:30
parent 589337116a
commit 80ceb49358

View File

@@ -1,60 +1,55 @@
<template> <template>
<div class="flex h-full flex-col"> <div class="flex h-full flex-col relative">
<div class="h-full pb-10" id="scrollContainer"> <div class="h-full pb-10" id="scrollContainer">
<slot /> <slot />
</div> </div>
<div
v-if="sidebarSettings.data" <div class="relative z-20">
class="fixed flex items-center justify-around border-t border-outline-gray-2 bottom-0 z-10 w-full bg-surface-white standalone:pb-4" <!-- Dropdown menu -->
:style="{ <div
gridTemplateColumns: `repeat(${ class="fixed bottom-16 right-2 w-[80%] rounded-md bg-surface-white text-base p-5 space-y-4 shadow-md"
sidebarLinks.length + 1 v-if="showMenu"
}, minmax(0, 1fr))`, ref="menu"
}"
>
<button
v-for="tab in sidebarLinks"
:key="tab.label"
:class="isVisible(tab) ? 'block' : 'hidden'"
class="flex flex-col items-center justify-center py-3 transition active:scale-95"
@click="handleClick(tab)"
> >
<component <div
:is="icons[tab.icon]" v-for="link in otherLinks"
class="h-6 w-6 stroke-1.5" :key="link.label"
:class="[isActive(tab) ? 'text-ink-gray-9' : 'text-ink-gray-5']" class="flex items-center space-x-2 cursor-pointer"
/> @click="handleClick(link)"
</button> >
<Popover <component
trigger="hover" :is="icons[link.icon]"
popoverClass="bottom-28 mx-2" class="h-4 w-4 stroke-1.5 text-ink-gray-5"
placement="top-start" />
<div>{{ link.label }}</div>
</div>
</div>
<!-- Fixed menu -->
<div
v-if="sidebarSettings.data"
class="fixed bottom-0 left-0 w-full flex items-center justify-around border-t border-outline-gray-2 bg-surface-white standalone:pb-4 z-10"
> >
<template #target> <button
v-for="tab in sidebarLinks"
:key="tab.label"
:class="isVisible(tab) ? 'block' : 'hidden'"
class="flex flex-col items-center justify-center py-3 transition active:scale-95"
@click="handleClick(tab)"
>
<component
:is="icons[tab.icon]"
class="h-6 w-6 stroke-1.5"
:class="[isActive(tab) ? 'text-ink-gray-9' : 'text-ink-gray-5']"
/>
</button>
<button @click="toggleMenu">
<component <component
:is="icons['List']" :is="icons['List']"
class="h-6 w-6 stroke-1.5 text-ink-gray-5" class="h-6 w-6 stroke-1.5 text-ink-gray-5"
/> />
</template> </button>
<template #body-main> </div>
<div class="text-base p-5 space-y-4">
<div
v-for="link in otherLinks"
:key="link.label"
class="flex items-center space-x-2"
@click="handleClick(link)"
>
<component
:is="icons[link.icon]"
class="h-4 w-4 stroke-1.5 text-ink-gray-5"
/>
<div>
{{ link.label }}
</div>
</div>
</div>
</template>
</Popover>
</div> </div>
</div> </div>
</template> </template>
@@ -64,7 +59,6 @@ import { useRouter } from 'vue-router'
import { watch, ref, onMounted } from 'vue' import { watch, ref, onMounted } from 'vue'
import { sessionStore } from '@/stores/session' import { sessionStore } from '@/stores/session'
import { usersStore } from '@/stores/user' import { usersStore } from '@/stores/user'
import { Popover } from 'frappe-ui'
import * as icons from 'lucide-vue-next' import * as icons from 'lucide-vue-next'
const { logout, user, sidebarSettings } = sessionStore() const { logout, user, sidebarSettings } = sessionStore()
@@ -73,26 +67,47 @@ const router = useRouter()
let { userResource } = usersStore() let { userResource } = usersStore()
const sidebarLinks = ref(getSidebarLinks()) const sidebarLinks = ref(getSidebarLinks())
const otherLinks = ref([]) const otherLinks = ref([])
const showMenu = ref(false)
const menu = ref(null)
onMounted(() => { onMounted(() => {
sidebarSettings.reload( sidebarSettings.reload(
{}, {},
{ {
onSuccess(data) { onSuccess(data) {
Object.keys(data).forEach((key) => { filterLinksToShow(data)
if (!parseInt(data[key])) {
sidebarLinks.value = sidebarLinks.value.filter(
(link) => link.label.toLowerCase().split(' ').join('_') !== key
)
}
})
addOtherLinks() 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 = () => { const addOtherLinks = () => {
if (user) { if (user) {
otherLinks.value.push({ otherLinks.value.push({
@@ -122,6 +137,7 @@ watch(userResource, () => {
(userResource.data.is_moderator || userResource.data.is_instructor) (userResource.data.is_moderator || userResource.data.is_instructor)
) { ) {
addQuizzes() addQuizzes()
addAssignments()
} }
}) })
@@ -133,6 +149,14 @@ const addQuizzes = () => {
}) })
} }
const addAssignments = () => {
otherLinks.value.push({
label: 'Assignments',
icon: 'Pencil',
to: 'Assignments',
})
}
let isActive = (tab) => { let isActive = (tab) => {
return tab.activeFor?.includes(router.currentRoute.value.name) return tab.activeFor?.includes(router.currentRoute.value.name)
} }
@@ -158,4 +182,8 @@ const isVisible = (tab) => {
else if (tab.label == 'Log out') return isLoggedIn else if (tab.label == 'Log out') return isLoggedIn
else return true else return true
} }
const toggleMenu = () => {
showMenu.value = !showMenu.value
}
</script> </script>