File tree Expand file tree Collapse file tree 7 files changed +210
-198
lines changed Expand file tree Collapse file tree 7 files changed +210
-198
lines changed Original file line number Diff line number Diff line change 1+ import { Stack , Typography } from '@mui/material' ;
2+ import { FC } from 'react' ;
3+
4+ export interface MenuCategoryItemProps {
5+ name : string | null ;
6+ selected : boolean ;
7+ onClick : VoidFunction ;
8+ }
9+ const MenuCategoryItem : FC < MenuCategoryItemProps > = ( {
10+ name,
11+ selected,
12+ onClick,
13+ } ) => {
14+ return (
15+ < Stack
16+ onClick = { onClick }
17+ alignItems = "center"
18+ justifyContent = "center"
19+ sx = { {
20+ height : 65 ,
21+ backgroundColor : ( theme ) =>
22+ selected ? theme . palette . background . default : theme . palette . grey [ 200 ] ,
23+ } }
24+ >
25+ < Typography variant = "body2" > { name } </ Typography >
26+ </ Stack >
27+ ) ;
28+ } ;
29+
30+ export default MenuCategoryItem ;
Original file line number Diff line number Diff line change 1+ import { Link } from '@/navigation' ;
2+ import { ChevronRight } from '@mui/icons-material' ;
3+ import { Stack , Typography } from '@mui/material' ;
4+ import { FC } from 'react' ;
5+ import SubCategoryItem from './SubCategoryItem' ;
6+
7+ export interface SubCategoriesProps {
8+ parentId : string | null ;
9+ name : string ;
10+ items : any [ ] ;
11+ }
12+
13+ const SubCategories : FC < SubCategoriesProps > = ( { name, parentId, items } ) => {
14+ if ( ! parentId ) {
15+ return null ;
16+ }
17+
18+ return (
19+ < Stack px = { 1.5 } flexGrow = { 1 } >
20+ < Stack component = { Link } href = "#" height = { 65 } justifyContent = "center" >
21+ < Typography
22+ variant = "body2"
23+ color = "primary"
24+ sx = { {
25+ display : 'flex' ,
26+ alignItems : 'center' ,
27+ } }
28+ >
29+ مشاهده همه کالاهای { name } { ' ' }
30+ < ChevronRight
31+ fontSize = "small"
32+ sx = { {
33+ transform : ( theme ) =>
34+ theme . direction === 'rtl' ? 'rotate(180deg)' : null ,
35+ } }
36+ />
37+ </ Typography >
38+ </ Stack >
39+ < Stack direction = "row" px = { 1.5 } flexWrap = "wrap" gap = { 1 } >
40+ { items . map ( ( item ) => {
41+ return (
42+ < SubCategoryItem
43+ src = { item . image . sourceUrl }
44+ name = { item . name }
45+ id = { item . name }
46+ />
47+ ) ;
48+ } ) }
49+
50+ < SubCategoryItem
51+ src = { '/assets/images/all-product.webp' }
52+ name = { 'همه کالاها' }
53+ id = { parentId }
54+ />
55+ </ Stack >
56+ </ Stack >
57+ ) ;
58+ } ;
59+
60+ export default SubCategories ;
Original file line number Diff line number Diff line change 1+ import Image from '@/components/common/Image' ;
2+ import { Link } from '@/navigation' ;
3+ import { Stack , Typography } from '@mui/material' ;
4+ import { FC } from 'react' ;
5+
6+ export interface SubCategoryItemProps {
7+ id : string ;
8+ name : string ;
9+ src : string ;
10+ }
11+ const SubCategoryItem : FC < SubCategoryItemProps > = ( { id, src, name } ) => {
12+ return (
13+ < Stack
14+ spacing = { 1 }
15+ width = "30%"
16+ alignItems = "center"
17+ component = { Link }
18+ href = "#"
19+ sx = { {
20+ height : 'fit-content' ,
21+ maxHeight : 'auto' ,
22+ } }
23+ >
24+ < Stack
25+ alignItems = "center"
26+ justifyContent = "center"
27+ sx = { {
28+ bgcolor : ( theme ) => theme . palette . grey [ 200 ] ,
29+ borderRadius : 1.5 ,
30+ height : 'fit-content' ,
31+ } }
32+ >
33+ < Image width = { 82 } height = { 82 } src = { src } alt = { name } />
34+ </ Stack >
35+ < Typography
36+ color = "text.primary"
37+ variant = "body2"
38+ sx = { {
39+ // whiteSpace: 'nowrap',
40+ textOverflow : 'ellipsis' ,
41+ overflow : 'hidden' ,
42+ display : '-webkit-box' ,
43+ '-webkit-line-clamp' : '2' ,
44+ '-webkit-box-orient' : 'vertical' ,
45+ } }
46+ >
47+ { name }
48+ </ Typography >
49+ </ Stack >
50+ ) ;
51+ } ;
52+
53+ export default SubCategoryItem ;
Original file line number Diff line number Diff line change 1+ 'use client' ;
2+
3+ import { GET_ALL_CATEGORIES_QUERY } from '@/graphql/queries/categories' ;
4+ import { CategoriesQuery } from '@/graphql/types/graphql' ;
5+ import { useQuery } from '@apollo/client' ;
6+ import { Stack } from '@mui/material' ;
7+ import { useEffect , useState } from 'react' ;
8+ import MenuCategoryItem from './components/MenuCategoryItem' ;
9+ import SubCategories from './components/SubCategories' ;
10+
11+ const page = ( ) => {
12+ const { data, loading } = useQuery < CategoriesQuery > (
13+ GET_ALL_CATEGORIES_QUERY ,
14+ {
15+ variables : {
16+ first : 10000 ,
17+ } ,
18+ } ,
19+ ) ;
20+
21+ const categories = data ?. productCategories ?. nodes || [ ] ;
22+
23+ const [ selected , setSelected ] = useState < any > ( null ) ;
24+
25+ useEffect ( ( ) => {
26+ if ( ! loading ) {
27+ setSelected ( categories [ 0 ] ) ;
28+ }
29+ } , [ loading ] ) ;
30+
31+ if ( loading || ! selected ) {
32+ return < > Loading</ > ;
33+ }
34+
35+ return (
36+ < Stack overflow = "auto" direction = "row" >
37+ < Stack
38+ overflow = "auto"
39+ sx = { {
40+ minWidth : 110 ,
41+ } }
42+ >
43+ { categories
44+ . filter ( ( category ) => ! category . parentId )
45+ . map ( ( category ) => {
46+ return (
47+ < MenuCategoryItem
48+ selected = { category . id === selected . id }
49+ { ...category }
50+ key = { category . id }
51+ onClick = { ( ) => setSelected ( category ) }
52+ />
53+ ) ;
54+ } ) }
55+ </ Stack >
56+ < SubCategories
57+ name = { selected . name }
58+ parentId = { selected . id }
59+ items = { categories . filter (
60+ ( category ) => category . parentId === selected . id ,
61+ ) }
62+ />
63+ </ Stack >
64+ ) ;
65+ } ;
66+
67+ export default page ;
You can’t perform that action at this time.
0 commit comments