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

630-fix: Hydration error on prod (DO NOT MERGE) #631

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
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
22 changes: 3 additions & 19 deletions src/core/base-layout/components/header/header.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,9 @@
height: 64px;
padding: 0 40px;

border-radius: 0;

transition: background-color 0.2s;

&.gray {
background-color: $color-yellow-500;
}

&.none {
display: none;
}

&.white {
opacity: 1;
background-color: rgb(255 255 255);
border-bottom-right-radius: 0;
border-bottom-left-radius: 0;
box-shadow: rgb(0 0 0 / 8.2%) 0 1.026px 8.0694px 0;
}
background-color: rgb(255 255 255 / 10%);
backdrop-filter: blur(24px) saturate(1);
box-shadow: rgb(0 0 0 / 8.2%) 0 1.026px 8.0694px 0;

@include media-tablet {
height: 48px;
Expand Down
6 changes: 0 additions & 6 deletions src/core/base-layout/components/header/header.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,6 @@ describe('Header', () => {
expect(headerElement).toBeInTheDocument();
});

it('set color as gray when scrollbar is at the top', () => {
const headerElement = screen.getByTestId('navigation');

expect(headerElement).toHaveClass(cxHeader('gray'));
});

it('renders all the header links', () => {
const headerElement = screen.getAllByText(/.*/, { selector: `span.${cxNavItem('label')}` });

Expand Down
42 changes: 2 additions & 40 deletions src/core/base-layout/components/header/header.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
'use client';

import { useEffect, useState } from 'react';
import { useState } from 'react';
import classNames from 'classnames/bind';
import { usePathname } from 'next/navigation';
import { BurgerMenu } from './burger/burger';
import { NavItem } from './nav-item/nav-item';
import { ROUTES } from '@/core/const';
Expand Down Expand Up @@ -34,50 +33,13 @@ const navLinks = [

export const Header = () => {
const [isMenuOpen, setMenuOpen] = useState(false);
const [color, setColor] = useState('gray');
const [hash, setHash] = useState('');
const [key, setKey] = useState('');
const pathname = usePathname();

const toggleMenu = () => {
setMenuOpen((prev) => !prev);
};

useEffect(() => {
const listenScrollEvent = () => {
const scrollY = window.scrollY;

// setting the class depending on the scrolled height
// class changes the background color of the header
if (scrollY < 500) {
setColor('gray');
} else {
setColor('white');
}
};

window.addEventListener('scroll', listenScrollEvent);

return () => {
window.removeEventListener('scroll', listenScrollEvent);
};
}, []);

useEffect(() => {
if (typeof window !== 'undefined') {
setHash(window.location.hash);
setKey(window.location.href);
}
}, [pathname]);

useEffect(() => {
if (location.pathname) {
setMenuOpen(false);
}
}, [key, hash, pathname]);

return (
<nav className={cx('navbar', color)} data-testid="navigation">
<nav className={cx('navbar')} data-testid="navigation">
<section className={cx('navbar-content')}>
<Logo />

Expand Down
4 changes: 2 additions & 2 deletions src/widgets/breadcrumbs/ui/breadcrumbs.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ vi.mock('next/navigation', () => ({
},
}));

describe('Breadcrumbs', () => {
describe.skip('Breadcrumbs', () => {
it('renders "Home"', () => {
mockUsePathname.mockImplementation(() => ROUTES.HOME);

Expand Down Expand Up @@ -44,7 +44,7 @@ describe('Breadcrumbs', () => {
expect(unmappedBreadcrumb).toBeInTheDocument();
});

it('renders Breadcrumbs for nested route', () => {
it.skip('renders Breadcrumbs for nested route', () => {
mockUsePathname.mockImplementation(() => nodejsCourseRoute);

renderWithRouter(<Breadcrumbs />, { route: nodejsCourseRoute });
Expand Down
40 changes: 10 additions & 30 deletions src/widgets/breadcrumbs/ui/breadcrumbs.tsx
Original file line number Diff line number Diff line change
@@ -1,36 +1,16 @@
'use client';

import classNames from 'classnames/bind';
import { usePathname } from 'next/navigation';
import { BreadcrumbItem } from './breadcrumb-item';
import { breadcrumbNameMap } from '../constants';
import { ROUTES } from '@/core/const';
import { RouteValues } from '@/core/types/route.types';

import styles from './breadcrumbs.module.scss';

const cx = classNames.bind(styles);
// const cx = classNames.bind(styles);

export const Breadcrumbs = () => {
const pathname = usePathname();
const crumbs = pathname.split('/').filter(Boolean) as RouteValues[];

const transformedCrumbs = crumbs.map((crumb, i) => ({
text: breadcrumbNameMap[crumb] || crumb,
linkTo: `/${crumbs.slice(0, i + 1).join('/')}/`,
isLastLink: i === crumbs.length - 1,
}));
// const pathname = usePathname();
// const crumbs = pathname.split('/').filter(Boolean) as RouteValues[];
//
// const transformedCrumbs = crumbs.map((crumb, i) => ({
// text: breadcrumbNameMap[crumb] || crumb,
// linkTo: `/${crumbs.slice(0, i + 1).join('/')}/`,
// isLastLink: i === crumbs.length - 1,
// }));

return (
<nav className={cx('container')}>
<div className={cx('content', 'breadcrumbs-content')}>
<ul>
<BreadcrumbItem linkTo={ROUTES.HOME} text="Home" />
{transformedCrumbs.map((crumb, i) => (
<BreadcrumbItem key={`${crumb.text}${i}`} {...crumb} />
))}
</ul>
</div>
</nav>
);
return <div>test</div>;
};
Loading