1- import { ChevronLeft , ChevronRight } from '@mui/icons-material' ;
2- import { useRef } from 'react' ;
31import { CatalogCardDesignLogo } from '../CustomCatalog' ;
42import CustomCatalogCard , { Pattern } from '../CustomCatalog/CustomCard' ;
3+ import Carousel from './Carousel' ;
54import { getHeadingText } from './helper' ;
6- import {
7- AdditionalContainer ,
8- CarouselButton ,
9- CarouselContainer ,
10- CarouselWrapper ,
11- ContentHeading
12- } from './style' ;
5+ import { AdditionalContainer , ContentHeading } from './style' ;
136import { UserProfile } from './types' ;
14-
157export interface PatternsPerUser {
168 patterns : Pattern [ ] ;
179}
@@ -45,7 +37,6 @@ const RelatedDesigns: React.FC<RelatedDesignsProps> = ({
4537 fetchingOrgError,
4638 filterByType
4739} ) => {
48- const carouselRef = useRef < HTMLDivElement > ( null ) ;
4940 const filteredPatterns = filterByType
5041 ? detailsByType ?. patterns ?. filter ( ( pattern ) => pattern . id !== details . id ) || [ ]
5142 : patternsPerUser ?. patterns ?. filter ( ( pattern ) => pattern . id !== details . id ) || [ ] ;
@@ -57,15 +48,26 @@ const RelatedDesigns: React.FC<RelatedDesignsProps> = ({
5748 ? 'Unknown Organization'
5849 : orgName ;
5950
60- const scroll = ( direction : 'left' | 'right' ) => {
61- if ( carouselRef . current ) {
62- const scrollAmount = 300 ; // Adjust scroll distance per click
63- carouselRef . current . scrollBy ( {
64- left : direction === 'left' ? - scrollAmount : scrollAmount ,
65- behavior : 'smooth'
66- } ) ;
67- }
68- } ;
51+ const carouselItems = filteredPatterns . map ( ( pattern ) => (
52+ < CustomCatalogCard
53+ pattern = { pattern }
54+ patternType = { type }
55+ onCardClick = { ( ) => onSuggestedPatternClick ( pattern ) }
56+ UserName = { `${ userProfile ?. first_name ?? '' } ${ userProfile ?. last_name ?? '' } ` }
57+ avatarUrl = { userProfile ?. avatar_url }
58+ basePath = { technologySVGPath }
59+ subBasePath = { technologySVGSubpath }
60+ cardTechnologies = { true }
61+ >
62+ < CatalogCardDesignLogo
63+ imgURL = { pattern ?. catalog_data ?. imageURL }
64+ height = { '5.5rem' }
65+ width = { '100%' }
66+ zoomEffect = { false }
67+ type = { { type : type } }
68+ />
69+ </ CustomCatalogCard >
70+ ) ) ;
6971 return (
7072 < AdditionalContainer >
7173 < ContentHeading >
@@ -75,38 +77,7 @@ const RelatedDesigns: React.FC<RelatedDesignsProps> = ({
7577 : getHeadingText ( { type, userProfile, organizationName, fetchingOrgError } ) }
7678 </ h2 >
7779 </ ContentHeading >
78- < CarouselWrapper >
79- < CarouselButton onClick = { ( ) => scroll ( 'left' ) } >
80- < ChevronLeft />
81- </ CarouselButton >
82- < CarouselContainer ref = { carouselRef } >
83- { filteredPatterns . map ( ( pattern , index ) => (
84- < div key = { `design-${ index } ` } className = "carousel-item" >
85- < CustomCatalogCard
86- pattern = { pattern }
87- patternType = { type }
88- onCardClick = { ( ) => onSuggestedPatternClick ( pattern ) }
89- UserName = { `${ userProfile ?. first_name ?? '' } ${ userProfile ?. last_name ?? '' } ` }
90- avatarUrl = { userProfile ?. avatar_url }
91- basePath = { technologySVGPath }
92- subBasePath = { technologySVGSubpath }
93- cardTechnologies = { true }
94- >
95- < CatalogCardDesignLogo
96- imgURL = { pattern ?. catalog_data ?. imageURL }
97- height = { '5.5rem' }
98- width = { '100%' }
99- zoomEffect = { false }
100- type = { { type : type } }
101- />
102- </ CustomCatalogCard >
103- </ div >
104- ) ) }
105- </ CarouselContainer >
106- < CarouselButton onClick = { ( ) => scroll ( 'right' ) } >
107- < ChevronRight />
108- </ CarouselButton >
109- </ CarouselWrapper >
80+ < Carousel items = { carouselItems } scrollAmount = { 300 } />
11081 </ AdditionalContainer >
11182 ) ;
11283} ;
0 commit comments