Skip to content

Commit

Permalink
refactor: use mobile and desktop components
Browse files Browse the repository at this point in the history
  • Loading branch information
pooriaset committed May 4, 2024
1 parent 9abe5ad commit 3858458
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 37 deletions.
18 changes: 10 additions & 8 deletions src/components/Footer/Footer.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
'use client';

import { DesktopFooter, MobileFooter } from './components';
import { IPageListItem } from '@/app/[locale]/(main)/layout';
import { Box } from '@mui/material';
import { useAppContext } from '@/hooks/useAppContext';
import { FC } from 'react';
import { IPageListItem } from '@/app/[locale]/(main)/layout';
import DesktopView from '../App/DesktopView';
import MobileView from '../App/MobileView';
import { DesktopFooter, MobileFooter } from './components';

export interface FooterProps {
pages: IPageListItem[];
}
const Footer: FC<FooterProps> = ({ pages }) => {
const { isMobile } = useAppContext();

return (
<Box mt={2}>
{isMobile ? <MobileFooter /> : <DesktopFooter pages={pages} />}
<MobileView>
<MobileFooter />
</MobileView>
<DesktopView>
<DesktopFooter pages={pages} />
</DesktopView>
</Box>
);
};
Expand Down
2 changes: 2 additions & 0 deletions src/components/Footer/components/DesktopFooter.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use client';

import { IPageListItem } from '@/app/[locale]/(main)/layout';
import { Box, Container, Link, Typography } from '@mui/material';
import { useTranslations } from 'next-intl';
Expand Down
15 changes: 8 additions & 7 deletions src/components/Header/Header.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
'use client';

import { AppBar, Container } from '@mui/material';
import { DesktopView, MobileView } from './components';
import { Suspense } from 'react';
import { useAppContext } from '@/hooks/useAppContext';
import DesktopView from '../App/DesktopView';
import MobileView from '../App/MobileView';
import { DesktopHeader } from './components';

const Header = () => {
const { isMobile } = useAppContext();
return (
<AppBar
elevation={0}
Expand All @@ -21,13 +21,14 @@ const Header = () => {
}}
>
<Container maxWidth="xl">
{isMobile ? (
<DesktopView>
<DesktopHeader />
</DesktopView>
<MobileView>
<Suspense>
<MobileView />
</Suspense>
) : (
<DesktopView />
)}
</MobileView>
</Container>
</AppBar>
);
Expand Down
16 changes: 16 additions & 0 deletions src/components/Header/components/DesktopHeader.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
'use client';

import { Suspense } from 'react';
import BottomSection from './BottomSection';
import TopSection from './TopSection';

const DesktopHeader = () => {
return (
<Suspense>
<TopSection />
<BottomSection />
</Suspense>
);
};

export default DesktopHeader;
16 changes: 0 additions & 16 deletions src/components/Header/components/DesktopView.tsx

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import SearchDialog from './SearchDialog';
import SearchSection from './SearchSection';
import { useTranslations } from 'next-intl';

const MobileView = () => {
const MobileHeader = () => {
const { navigate, q } = useCustomSearchParams();

const [open, setOpen] = useState(false);
Expand Down Expand Up @@ -64,4 +64,4 @@ const MobileView = () => {
);
};

export default MobileView;
export default MobileHeader;
8 changes: 4 additions & 4 deletions src/components/Header/components/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export { default as TopSection } from "./TopSection";
export { default as BottomSection } from "./BottomSection";
export { default as DesktopView } from "./DesktopView";
export { default as MobileView } from "./MobileView";
export { default as TopSection } from './TopSection';
export { default as BottomSection } from './BottomSection';
export { default as DesktopHeader } from './DesktopHeader';
export { default as MobileHeader } from './MobileHeader';

0 comments on commit 3858458

Please sign in to comment.