Skip to content

Commit

Permalink
fix: 뒤로가기 버튼 동작 수정 (#115)
Browse files Browse the repository at this point in the history
* refactor: 뒤로가기 버튼 동작 수정

* refactor: 상품 페이지 헤더 topbar로 수정
  • Loading branch information
Leejin-Yang authored Apr 23, 2024
1 parent 92f0dae commit 4def882
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 7 deletions.
19 changes: 16 additions & 3 deletions src/components/Common/TopBar/TopBar.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { ComponentPropsWithoutRef } from 'react';
import { Link } from 'react-router-dom';
import type { ComponentPropsWithoutRef, MouseEventHandler } from 'react';
import { Link, useNavigate } from 'react-router-dom';

import { LeftNavigationWrapper, container, headerTitle, leftTitle, register } from './topBar.css';
import SvgIcon from '../Svg/SvgIcon';
Expand Down Expand Up @@ -31,8 +31,21 @@ const Logo = () => {
};

const BackLink = ({ state }: TopBarProps) => {
const navigate = useNavigate();

const handleBack: MouseEventHandler<HTMLAnchorElement> = (event) => {
event.preventDefault();

if (state) {
navigate('..', { state, relative: 'path' });
return;
}

navigate(-1);
};

return (
<Link to=".." relative="path" state={state}>
<Link to="#" onClick={handleBack}>
<SvgIcon variant="arrowLeft" stroke={vars.colors.gray5} width={20} height={20} />
</Link>
);
Expand Down
9 changes: 7 additions & 2 deletions src/pages/ProductDetailPage/ProductDetailPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ import NotFoundPage from '../NotFoundPage';

import {
SortButton,
PageHeader,
SectionHeader,
ErrorBoundary,
ErrorComponent,
Loading,
SelectOptionList,
TopBar,
} from '@/components/Common';
import { ProductDetailItem, ProductRecipeList } from '@/components/Product';
import { ReviewList } from '@/components/Review';
Expand Down Expand Up @@ -55,7 +55,12 @@ export const ProductDetailPage = () => {

return (
<>
<PageHeader title="상세" hasBackLink />
<TopBar>
<TopBar.BackLink />
<TopBar.Title title="상세" />
<TopBar.Spacer />
</TopBar>

<main className={main}>
<ProductDetailItem productDetail={productDetail} />

Expand Down
8 changes: 6 additions & 2 deletions src/pages/ProductListPage/ProductListPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { useLocation, useParams } from 'react-router-dom';
import { categoryButton, listSection, main, selectButton, selectSection, sortButton } from './productListPage.css';
import NotFoundPage from '../NotFoundPage';

import { ErrorBoundary, ErrorComponent, Loading, PageHeader, SelectOptionList, SvgIcon } from '@/components/Common';
import { ErrorBoundary, ErrorComponent, Loading, SelectOptionList, SvgIcon, TopBar } from '@/components/Common';
import { ProductList } from '@/components/Product';
import { CATEGORY_TYPE, PAGE_TITLE, PRODUCT_SORT_OPTIONS } from '@/constants';
import { useSelect } from '@/hooks/common';
Expand Down Expand Up @@ -46,7 +46,11 @@ export const ProductListPage = () => {

return (
<>
<PageHeader title={pageTitle} hasBackLink hasSearchLink state={category} />
<TopBar>
<TopBar.BackLink state={category} />
<TopBar.Title title={pageTitle} />
<TopBar.SearchLink />
</TopBar>

<main className={main}>
<section className={selectSection}>
Expand Down

0 comments on commit 4def882

Please sign in to comment.