Skip to content

Commit d69a6ba

Browse files
committed
feat: complete navigate between categories
1 parent a3dfcb5 commit d69a6ba

File tree

10 files changed

+35
-11
lines changed

10 files changed

+35
-11
lines changed

src/app/[locale]/(main)/(container)/search/components/SortRow.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { grey } from '@mui/material/colors';
77
import { MouseEventHandler } from 'react';
88
import { sortOptions } from '@/static/sortOptions';
99
import { useTranslations } from 'next-intl';
10+
import { SearchPageParamsKeys } from '@/utils/params';
1011

1112
const SortRow = () => {
1213
const { sort, navigate } = useCustomSearchParams();
@@ -15,7 +16,7 @@ const SortRow = () => {
1516

1617
const handleClickOnItem = (value: number) => {
1718
const func: MouseEventHandler<HTMLButtonElement> = (event) => {
18-
navigate('Sort', value);
19+
navigate(SearchPageParamsKeys.Sort, value);
1920
};
2021
return func;
2122
};

src/app/[locale]/(main)/(homepage)/components/Header.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { useTranslations } from 'next-intl';
88
import { useState, useTransition } from 'react';
99
import SearchDialog from './SearchDialog';
1010
import SearchSection from './SearchSection';
11+
import { SearchPageParamsKeys } from '@/utils/params';
1112

1213
const Header = () => {
1314
const [isPending, startTransition] = useTransition();
@@ -22,7 +23,7 @@ const Header = () => {
2223

2324
const onClickOnSearch = (q: string) => {
2425
startTransition(() => {
25-
navigate('Q', q);
26+
navigate(SearchPageParamsKeys.Q, q);
2627
setOpen(false);
2728
});
2829
};

src/app/[locale]/(main)/categories/components/MenuCategoryItem.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
'use client';
2+
13
import { Stack, Typography } from '@mui/material';
24
import { FC } from 'react';
35

src/app/[locale]/(main)/categories/components/SubCategories.tsx

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
'use client';
2+
13
import { Link } from '@/navigation';
24
import { ChevronRight } from '@mui/icons-material';
35
import { Stack, Typography } from '@mui/material';
@@ -15,9 +17,18 @@ const SubCategories: FC<SubCategoriesProps> = ({ name, parentId, items }) => {
1517
return null;
1618
}
1719

20+
const params = new URLSearchParams();
21+
params.set('categoryId', parentId!.toString());
22+
const parentLink = `/search?${params.toString()}`;
23+
1824
return (
1925
<Stack px={1.5} flexGrow={1}>
20-
<Stack component={Link} href="#" height={65} justifyContent="center">
26+
<Stack
27+
component={Link}
28+
href={parentLink}
29+
height={65}
30+
justifyContent="center"
31+
>
2132
<Typography
2233
variant="body2"
2334
color="primary"
@@ -42,7 +53,7 @@ const SubCategories: FC<SubCategoriesProps> = ({ name, parentId, items }) => {
4253
<SubCategoryItem
4354
src={item.image.sourceUrl}
4455
name={item.name}
45-
id={item.name}
56+
id={item.id}
4657
/>
4758
);
4859
})}

src/app/[locale]/(main)/categories/components/SubCategoryItem.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,17 @@ export interface SubCategoryItemProps {
99
src: string;
1010
}
1111
const SubCategoryItem: FC<SubCategoryItemProps> = ({ id, src, name }) => {
12+
const params = new URLSearchParams();
13+
params.set('categoryId', id!.toString());
14+
const link = `/search?${params.toString()}`;
15+
1216
return (
1317
<Stack
1418
spacing={1}
1519
width="30%"
1620
alignItems="center"
1721
component={Link}
18-
href="#"
22+
href={link}
1923
sx={{
2024
height: 'fit-content',
2125
maxHeight: 'auto',

src/app/[locale]/(main)/categories/loading.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
'use client';
2+
13
import { Skeleton, Stack } from '@mui/material';
24
import React from 'react';
35

src/components/ColumnFilters/ColumnFilters.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import { FC, useState } from 'react';
2020
import Categories from './components/Categories';
2121
import { ListItem } from './components/ListItem';
2222
import { Title } from './components/Title';
23+
import { SearchPageParamsKeys } from '@/utils/params';
2324

2425
export interface ColumnFiltersProps {}
2526

@@ -43,7 +44,7 @@ const ColumnFilters: FC<ColumnFiltersProps> = () => {
4344

4445
const { navigate, inStock } = useCustomSearchParams();
4546
const handleClickOnInStock = () => {
46-
navigate('InStock', !inStock);
47+
navigate(SearchPageParamsKeys.InStock, !inStock);
4748
};
4849

4950
return (

src/components/ColumnFilters/components/Categories.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { FC, MouseEventHandler, useMemo, useState } from 'react';
55
import { ProductCategoryOptions } from '../types';
66
import { ListItem } from './ListItem';
77
import { Title } from './Title';
8+
import { SearchPageParamsKeys } from '@/utils/params';
89

910
export interface CategoriesProps {
1011
options: ProductCategoryOptions;
@@ -55,7 +56,7 @@ const Categories: FC<CategoriesProps> = ({ options, parentId = allItemId }) => {
5556

5657
const handleClickOnItem = (id: number) => {
5758
const func: MouseEventHandler<HTMLDivElement> = (event) => {
58-
navigate('CategoryId', id);
59+
navigate(SearchPageParamsKeys.CategoryId, id);
5960
};
6061
return func;
6162
};

src/components/Header/components/TopSection.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import { useSession } from 'next-auth/react';
1717
import { useTranslations } from 'next-intl';
1818
import { DOMAttributes, FC } from 'react';
1919
import LoggedInButton from './LoggedInButton';
20+
import { SearchPageParamsKeys } from '@/utils/params';
2021

2122
const Form = styled('form')(({ theme }) => ({
2223
position: 'relative',
@@ -43,7 +44,7 @@ const TopSection: FC = () => {
4344
) => {
4445
event.preventDefault();
4546
const q = event.currentTarget.q.value;
46-
navigate('Q', q);
47+
navigate(SearchPageParamsKeys.Q, q);
4748
};
4849

4950
const cart = useAtomValue(cartAtom);

src/hooks/useCustomSearchParams.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { useSearchParams } from 'next/navigation';
1111
export interface IUseCustomSearchParams {
1212
(): {
1313
navigate: (
14-
key: keyof typeof SearchPageParamsKeys,
14+
key: SearchPageParamsKeys,
1515
value: string | number | boolean | null,
1616
) => void;
1717
} & SearchPagesParams;
@@ -27,9 +27,9 @@ const useCustomSearchParams: IUseCustomSearchParams = () => {
2727
) => {
2828
const newParams = new URLSearchParams(params);
2929
if (value === undefined || value === null || +value < 0) {
30-
newParams.delete(SearchPageParamsKeys[key]);
30+
newParams.delete(key);
3131
} else {
32-
newParams.set(SearchPageParamsKeys[key], value.toString());
32+
newParams.set(key, value.toString());
3333
}
3434
router.push(`/search?${newParams}`);
3535
};

0 commit comments

Comments
 (0)