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

[FE] 카테고리 페이지에 따라 제목 변경 UI 구현 #271

Merged
merged 1 commit into from
Jul 28, 2022
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
14 changes: 7 additions & 7 deletions frontend/src/components/common/CategoryNav/CategoryNav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ type Props = {
triggerAnimation: boolean;
};

const CATEGORY = {
KEYBOARD: { key: 'keyboard', name: '키보드' },
MOUSE: { key: 'mouse', name: '마우스' },
MONITOR: { key: 'monitor', name: '모니터' },
STAND: { key: 'stand', name: '거치대' },
SOFTWARE: { key: 'software', name: '소프트웨어' },
export const CATEGORY = {
keyboard: '키보드',
mouse: '마우스',
monitor: '모니터',
stand: '거치대',
software: '소프트웨어',
} as const;

function CategoryNav({ handleTransitionEnd, triggerAnimation }: Props) {
const CategoryLinks = Object.values(CATEGORY).map(({ key, name }) => (
const CategoryLinks = Object.entries(CATEGORY).map(([key, name]) => (
<Link key={key} to={`${ROUTES.PRODUCTS}?category=${key}`}>
{name}
</Link>
Expand Down
14 changes: 12 additions & 2 deletions frontend/src/pages/Products/Products.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import ProductListSection from '@/components/ProductListSection/ProductListSecti
import Select from '@/components/common/Select/Select';
import useProducts from '@/hooks/useProducts';
import { useLocation, useSearchParams } from 'react-router-dom';
import { CATEGORY } from '@/components/common/CategoryNav/CategoryNav';

type Option = { value: string; text: string };

Expand All @@ -25,7 +26,9 @@ const DefaultSort = options[1];

function Products() {
const location = useLocation();
const [sort, setSort] = useState<Sort>(DefaultSort.value);
const [sort, setSort] = useState<Sort>(
location.hash === '#popular' ? PopularSort.value : DefaultSort.value
);
const [searchParams] = useSearchParams();
const category = searchParams.get('category');
const [products, getNextPage] = useProducts({
Expand All @@ -34,6 +37,13 @@ function Products() {
category,
});

const categoryTitle = CATEGORY[category as keyof typeof CATEGORY] || '상품';

const title =
location.hash === '#popular'
? '인기 상품 목록'
: `모든 ${categoryTitle} 목록`;

useEffect(() => {
setSort(
location.hash === '#popular' ? PopularSort.value : DefaultSort.value
Expand All @@ -42,7 +52,7 @@ function Products() {

return (
<ProductListSection
title={location.hash === '#popular' ? '인기 상품 목록' : '모든 상품 목록'}
title={title}
data={!!products && products}
getNextPage={getNextPage}
addOn={<Select value={sort} setValue={setSort} options={options} />}
Expand Down