|
| 1 | +import { ChevronLeft, ChevronRight } from '@mui/icons-material'; |
| 2 | +import { useRef } from 'react'; |
1 | 3 | import { CatalogCardDesignLogo } from '../CustomCatalog'; |
2 | 4 | import CustomCatalogCard, { Pattern } from '../CustomCatalog/CustomCard'; |
3 | 5 | import { getHeadingText } from './helper'; |
4 | | -import { AdditionalContainer, ContentHeading, DesignCardContainer } from './style'; |
| 6 | +import { |
| 7 | + AdditionalContainer, |
| 8 | + CarouselButton, |
| 9 | + CarouselContainer, |
| 10 | + CarouselWrapper, |
| 11 | + ContentHeading |
| 12 | +} from './style'; |
5 | 13 | import { UserProfile } from './types'; |
6 | 14 |
|
7 | 15 | export interface PatternsPerUser { |
@@ -31,42 +39,62 @@ const RelatedDesigns: React.FC<RelatedDesignsProps> = ({ |
31 | 39 | orgName, |
32 | 40 | fetchingOrgError |
33 | 41 | }) => { |
| 42 | + const carouselRef = useRef<HTMLDivElement>(null); |
34 | 43 | const filteredPatternsPerUser = patternsPerUser?.patterns?.filter( |
35 | 44 | (pattern) => pattern.id !== details.id |
36 | 45 | ); |
37 | 46 |
|
38 | 47 | if (!filteredPatternsPerUser?.length) return null; |
39 | 48 | const organizationName = fetchingOrgError || !orgName ? 'Unknown Organization' : orgName; |
| 49 | + |
| 50 | + const scroll = (direction: 'left' | 'right') => { |
| 51 | + if (carouselRef.current) { |
| 52 | + const scrollAmount = 300; // Adjust scroll distance per click |
| 53 | + carouselRef.current.scrollBy({ |
| 54 | + left: direction === 'left' ? -scrollAmount : scrollAmount, |
| 55 | + behavior: 'smooth' |
| 56 | + }); |
| 57 | + } |
| 58 | + }; |
40 | 59 | return ( |
41 | 60 | <AdditionalContainer> |
42 | 61 | <ContentHeading> |
43 | 62 | <h2 style={{ margin: '0', textTransform: 'uppercase' }}> |
44 | 63 | {getHeadingText({ type, userProfile, organizationName, fetchingOrgError })} |
45 | 64 | </h2> |
46 | 65 | </ContentHeading> |
47 | | - <DesignCardContainer> |
48 | | - {filteredPatternsPerUser.map((pattern, index) => ( |
49 | | - <CustomCatalogCard |
50 | | - key={`design-${index}`} |
51 | | - pattern={pattern} |
52 | | - patternType={type} |
53 | | - onCardClick={() => onSuggestedPatternClick(pattern)} |
54 | | - UserName={`${userProfile?.first_name ?? ''} ${userProfile?.last_name ?? ''}`} |
55 | | - avatarUrl={userProfile?.avatar_url} |
56 | | - basePath={technologySVGPath} |
57 | | - subBasePath={technologySVGSubpath} |
58 | | - cardTechnologies={true} |
59 | | - > |
60 | | - <CatalogCardDesignLogo |
61 | | - imgURL={pattern?.catalog_data?.imageURL} |
62 | | - height={'7.5rem'} |
63 | | - width={'100%'} |
64 | | - zoomEffect={false} |
65 | | - type={{ type: type }} |
66 | | - /> |
67 | | - </CustomCatalogCard> |
68 | | - ))} |
69 | | - </DesignCardContainer> |
| 66 | + <CarouselWrapper> |
| 67 | + <CarouselButton onClick={() => scroll('left')}> |
| 68 | + <ChevronLeft /> |
| 69 | + </CarouselButton> |
| 70 | + <CarouselContainer ref={carouselRef}> |
| 71 | + {filteredPatternsPerUser.map((pattern, index) => ( |
| 72 | + <div key={`design-${index}`} className="carousel-item"> |
| 73 | + <CustomCatalogCard |
| 74 | + pattern={pattern} |
| 75 | + patternType={type} |
| 76 | + onCardClick={() => onSuggestedPatternClick(pattern)} |
| 77 | + UserName={`${userProfile?.first_name ?? ''} ${userProfile?.last_name ?? ''}`} |
| 78 | + avatarUrl={userProfile?.avatar_url} |
| 79 | + basePath={technologySVGPath} |
| 80 | + subBasePath={technologySVGSubpath} |
| 81 | + cardTechnologies={true} |
| 82 | + > |
| 83 | + <CatalogCardDesignLogo |
| 84 | + imgURL={pattern?.catalog_data?.imageURL} |
| 85 | + height={'5.5rem'} |
| 86 | + width={'100%'} |
| 87 | + zoomEffect={false} |
| 88 | + type={{ type: type }} |
| 89 | + /> |
| 90 | + </CustomCatalogCard> |
| 91 | + </div> |
| 92 | + ))} |
| 93 | + </CarouselContainer> |
| 94 | + <CarouselButton onClick={() => scroll('right')}> |
| 95 | + <ChevronRight /> |
| 96 | + </CarouselButton> |
| 97 | + </CarouselWrapper> |
70 | 98 | </AdditionalContainer> |
71 | 99 | ); |
72 | 100 | }; |
|
0 commit comments