Skip to content

Commit

Permalink
Merge pull request #1386 from ita-social-projects/feature/issue-838
Browse files Browse the repository at this point in the history
Menu slider fixed when unknown path
  • Loading branch information
mythter authored Sep 30, 2024
2 parents cf8eb9b + 8670013 commit 85a5a55
Showing 1 changed file with 19 additions and 14 deletions.
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

0 comments on commit 85a5a55

Please sign in to comment.