Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Menu slider fixed when unknown path #1386

Merged
merged 2 commits into from
Sep 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 19 additions & 14 deletions src/app/layout/header/HeaderDrawer/HeaderDrawer.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,25 +64,30 @@ const HeaderDrawer = () => {
query: '(max-width: 1024px)',
});

const setCatalogForStreetcodePage = (currentPath: string) => {
let optionId = menuOptions.indexOf(currentPath);

const isExcluded = currentPath !== FRONTEND_ROUTES.BASE
&& menuOptions
.filter((option, index) => index !== 0)
.some((option) => currentPath.startsWith(option));

if (currentPath && !isExcluded) {
if (currentPath !== FRONTEND_ROUTES.BASE) {
optionId = 1;
}
const getMenuOptionIdByCurrentPath = (currentPath: string) => {
const optionId = menuOptions.indexOf(currentPath);

// on the desktop there is no Privacy Policy menu item
const isDesktopAndPrivacyPath = !isSmall && currentPath === FRONTEND_ROUTES.OTHER_PAGES.PRIVACY_POLICY;

if (optionId >= 0 && !isDesktopAndPrivacyPath) {
return optionId;
}
return optionId;

// if the current path does not match any menu item
// and is not streetcode page, stay at the beginning
if (currentPath.startsWith('/news')
|| isDesktopAndPrivacyPath) {
return 0;
}

// otherwise return Streetcodes menu option ID
return 1;
};

useEffect(() => {
const currentPath = location.pathname;
const optionId = setCatalogForStreetcodePage(currentPath);
const optionId = getMenuOptionIdByCurrentPath(currentPath);

if (isSmall) {
setScalingCooficient(scaleMobile);
Expand Down