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

268-feat: Rework mobile menu #454

Merged
merged 6 commits into from
Aug 24, 2024
Merged
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
11 changes: 5 additions & 6 deletions src/app/layouts/base-layout/components/footer/footer.test.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { type Mock, describe, expect, it } from 'vitest';
import { Footer } from './footer';
import { renderWithRouter } from '@/shared/__tests__/utils';

Check warning on line 3 in src/app/layouts/base-layout/components/footer/footer.test.tsx

View workflow job for this annotation

GitHub Actions / CI

"app" is not allowed to import "gm_shared" | See rules: https://feature-sliced.design/docs/reference/layers/overview
import { useWindowSize } from '@/shared/hooks/use-window-size';

Check warning on line 4 in src/app/layouts/base-layout/components/footer/footer.test.tsx

View workflow job for this annotation

GitHub Actions / CI

Reaching to "@/shared/hooks/use-window-size" is not allowed

vi.mock('@/shared/hooks/use-window-size', () => ({ useWindowSize: vi.fn().mockImplementation(() => ({ width: 1200 })) }));
vi.mock('@/shared/hooks/use-data-by-name', () => ({ useDataByName: vi.fn().mockImplementation(() => ({ data: [] })) }));
Expand Down Expand Up @@ -36,23 +36,22 @@
expect(desktopView).toBeInTheDocument();
});

it('should render mobile view and have correct class - mobile-view', () => {
it('should render mobile view', () => {
(useWindowSize as Mock).mockReturnValueOnce({ width: 800 });

const { getByTestId } = renderWithRouter(<Footer />);
const mobileView = getByTestId('mobile-view');

expect(mobileView).toBeInTheDocument();
expect(mobileView).toHaveClass('mobile-view');
});

it('should render "About Community" link and correct href in mobile view', () => {
it('should render "Community" link and correct href in mobile view', () => {
(useWindowSize as Mock).mockReturnValueOnce({ width: 800 });

const { getByText } = renderWithRouter(<Footer />);
const aboutLink = getByText('About Community');
const communityLink = getByText('Community');

expect(aboutLink).toBeInTheDocument();
expect(aboutLink).toHaveAttribute('href', '/community/#about');
expect(communityLink).toBeInTheDocument();
expect(communityLink).toHaveAttribute('href', '/community');
});
});
29 changes: 29 additions & 0 deletions src/widgets/mobile-view/ui/mobile-view.module.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
.mobile-view {
display: flex;
flex-direction: column;
flex-grow: 1;
gap: 16px;
align-items: baseline;
justify-content: flex-start;

width: 100%;
}

.category-link {
font-size: 24px;
font-weight: $font-weight-bold;
}

.divider {
width: 100%;
border: none;
border-bottom: 1px solid currentcolor;
}

.dark {
color: $color-gray-600;
}

.light {
color: $color-gray-100;
}
47 changes: 0 additions & 47 deletions src/widgets/mobile-view/ui/mobile-view.scss

This file was deleted.

57 changes: 28 additions & 29 deletions src/widgets/mobile-view/ui/mobile-view.tsx
Original file line number Diff line number Diff line change
@@ -1,59 +1,58 @@
import classNames from 'classnames/bind';
import { Link } from 'react-router-dom';
import { ROUTES } from '@/app/const';
import { Logo } from '@/shared/ui/logo';
import { SchoolMenu } from '@/widgets/school-menu';

import './mobile-view.scss';
import styles from './mobile-view.module.scss';

interface MobileViewProps {
type: 'header' | 'footer';
}
const cx = classNames.bind(styles);

type DividerProps = {
color: 'light' | 'dark';
};

const Divider = ({ type }: MobileViewProps) => (
<div className={`divider ${type === 'header' ? 'dark' : 'light'}`} />
const Divider = ({ color }: DividerProps) => (
<hr className={cx('divider', color)} />
);

type MobileViewProps = {
type: 'header' | 'footer';
};

export const MobileView = ({ type }: MobileViewProps) => {
const color = type === 'header' ? 'dark' : 'light';
const logoView = type === 'header' ? null : 'with-border';

return (
<div className="mobile-view" data-testid="mobile-view">
<nav className={cx('mobile-view')} data-testid="mobile-view">
<Link to={ROUTES.HOME}>
<Logo type={logoView} />
</Link>

<Link to={`/${ROUTES.COMMUNITY}/#about`} className={`main-link ${color}`}>
About Community
</Link>

<Divider type={type} />

<SchoolMenu heading="rs school" color={color} />
<Divider color={color} />

<Divider type={type} />
<Link to={ROUTES.HOME} className={cx('category-link', color)}>
RS School
</Link>

<SchoolMenu heading="all courses" color={color} />
<SchoolMenu heading="rs school" hasTitle={false} color={color} />

<Divider type={type} />
<Divider color={color} />

<Link to={`/${ROUTES.COMMUNITY}/#community`} className={`main-link mt ${color}`}>
Community
<Link to={ROUTES.COURSES} className={cx('category-link', color)}>
Courses
</Link>

<Divider type={type} />
<SchoolMenu heading="all courses" hasTitle={false} color={color} />

<Link to={`/${ROUTES.COMMUNITY}/#events`} className={`main-link ${color}`}>
Events
</Link>

<Divider type={type} />
<Divider color={color} />

<Link to={`/${ROUTES.COMMUNITY}/#merch`} className={`main-link ${color}`}>
Merch
<Link to={ROUTES.COMMUNITY} className={cx('category-link', color)}>
Community
</Link>

<Divider type={type} />
</div>
<SchoolMenu heading="community" hasTitle={false} color={color} />
</nav>
);
};
Loading