mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-25 15:55:48 +00:00
chore(FE-40): set correct page title
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import { useState } from 'react';
|
import { useCallback, useState } from 'react';
|
||||||
import { usePathname } from 'next/navigation';
|
import { usePathname } from 'next/navigation';
|
||||||
|
|
||||||
import Image from 'next/image';
|
import Image from 'next/image';
|
||||||
@@ -29,15 +29,11 @@ const isPathActive = (pathname: string, link?: string) => {
|
|||||||
const splittedPathname = pathname.split('/');
|
const splittedPathname = pathname.split('/');
|
||||||
const splittedLink = link.split('/');
|
const splittedLink = link.split('/');
|
||||||
|
|
||||||
return splittedPathname.every((pathnameChunk, idx) => {
|
const isActiveLinkValid = splittedLink.every((linkChunk, idx) => {
|
||||||
return pathnameChunk === splittedLink[idx];
|
return linkChunk === splittedPathname[idx];
|
||||||
});
|
});
|
||||||
};
|
|
||||||
|
|
||||||
const isCollapseActive = (pathname: string, link?: string) => {
|
return pathname.startsWith(link) && isActiveLinkValid;
|
||||||
if (!link) return false;
|
|
||||||
|
|
||||||
return pathname === link || pathname.startsWith(link);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const CollapseMenu = ({
|
const CollapseMenu = ({
|
||||||
@@ -48,7 +44,7 @@ const CollapseMenu = ({
|
|||||||
depth = 0,
|
depth = 0,
|
||||||
}: CollapseMenuProps) => {
|
}: CollapseMenuProps) => {
|
||||||
const pathname = usePathname();
|
const pathname = usePathname();
|
||||||
const isActive = isCollapseActive(pathname, link);
|
const isActive = isPathActive(pathname, link);
|
||||||
const [open, setOpen] = useState(isActive);
|
const [open, setOpen] = useState(isActive);
|
||||||
|
|
||||||
const menuCollapseTitle = (
|
const menuCollapseTitle = (
|
||||||
@@ -184,9 +180,37 @@ const MainDrawer = ({
|
|||||||
const { mainDrawerOpen, setMainDrawerOpen } = useUiStore();
|
const { mainDrawerOpen, setMainDrawerOpen } = useUiStore();
|
||||||
const pathname = usePathname();
|
const pathname = usePathname();
|
||||||
|
|
||||||
const pageTitle = MAIN_DRAWER_LINKS.find((item) =>
|
const getPageTitle = useCallback(() => {
|
||||||
pathname.startsWith(item.link)
|
let title = '';
|
||||||
)?.title;
|
|
||||||
|
const activeMenu = MAIN_DRAWER_LINKS.find((item) =>
|
||||||
|
isPathActive(pathname, item.link)
|
||||||
|
);
|
||||||
|
|
||||||
|
const traverseMenuTitle = (menu: typeof activeMenu) => {
|
||||||
|
const hasSubmenu = menu?.submenu && menu?.submenu.length > 0;
|
||||||
|
|
||||||
|
if (!title) {
|
||||||
|
title += menu?.title;
|
||||||
|
} else {
|
||||||
|
title += ' - ' + menu?.title;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!hasSubmenu) return;
|
||||||
|
|
||||||
|
const activeSubmenu = menu.submenu.find((item) =>
|
||||||
|
isPathActive(pathname, item.link)
|
||||||
|
);
|
||||||
|
|
||||||
|
traverseMenuTitle(activeSubmenu);
|
||||||
|
};
|
||||||
|
|
||||||
|
traverseMenuTitle(activeMenu);
|
||||||
|
|
||||||
|
return title;
|
||||||
|
}, [pathname]);
|
||||||
|
|
||||||
|
const pageTitle = getPageTitle();
|
||||||
|
|
||||||
const toggleSidebar = () => {
|
const toggleSidebar = () => {
|
||||||
setMainDrawerOpen(!mainDrawerOpen);
|
setMainDrawerOpen(!mainDrawerOpen);
|
||||||
|
|||||||
Reference in New Issue
Block a user