|
| 1 | +import { Carousel } from '../Carousel'; |
1 | 2 | import { CatalogCardDesignLogo } from '../CustomCatalog'; |
2 | 3 | import CustomCatalogCard, { Pattern } from '../CustomCatalog/CustomCard'; |
3 | 4 | import { getHeadingText } from './helper'; |
4 | | -import { AdditionalContainer, ContentHeading, DesignCardContainer } from './style'; |
| 5 | +import { AdditionalContainer, ContentHeading } from './style'; |
5 | 6 | import { UserProfile } from './types'; |
6 | | - |
7 | 7 | export interface PatternsPerUser { |
8 | 8 | patterns: Pattern[]; |
9 | 9 | } |
10 | | - |
| 10 | +export interface DetailsByType { |
| 11 | + patterns: Pattern[]; |
| 12 | +} |
11 | 13 | interface RelatedDesignsProps { |
12 | 14 | details: Pattern; |
13 | 15 | type: string; |
14 | 16 | patternsPerUser: PatternsPerUser; |
| 17 | + detailsByType?: DetailsByType; |
15 | 18 | onSuggestedPatternClick: (pattern: Pattern) => void; |
16 | 19 | userProfile?: UserProfile; |
17 | 20 | technologySVGPath: string; |
18 | 21 | technologySVGSubpath: string; |
19 | 22 | orgName: string; |
20 | 23 | fetchingOrgError: boolean; |
| 24 | + filterByType?: boolean; |
21 | 25 | } |
22 | 26 |
|
23 | 27 | const RelatedDesigns: React.FC<RelatedDesignsProps> = ({ |
24 | 28 | details, |
25 | 29 | type, |
26 | 30 | patternsPerUser, |
| 31 | + detailsByType, |
27 | 32 | onSuggestedPatternClick, |
28 | 33 | userProfile, |
29 | 34 | technologySVGPath, |
30 | 35 | technologySVGSubpath, |
31 | 36 | orgName, |
32 | | - fetchingOrgError |
| 37 | + fetchingOrgError, |
| 38 | + filterByType |
33 | 39 | }) => { |
34 | | - const filteredPatternsPerUser = patternsPerUser?.patterns?.filter( |
35 | | - (pattern) => pattern.id !== details.id |
36 | | - ); |
| 40 | + const filteredPatterns = filterByType |
| 41 | + ? detailsByType?.patterns?.filter((pattern) => pattern.id !== details.id) || [] |
| 42 | + : patternsPerUser?.patterns?.filter((pattern) => pattern.id !== details.id) || []; |
| 43 | + |
| 44 | + if (!filteredPatterns.length) return null; |
| 45 | + const organizationName = filterByType |
| 46 | + ? 'Similar Designs by Type' |
| 47 | + : fetchingOrgError || !orgName |
| 48 | + ? 'Unknown Organization' |
| 49 | + : orgName; |
37 | 50 |
|
38 | | - if (!filteredPatternsPerUser?.length) return null; |
39 | | - const organizationName = fetchingOrgError || !orgName ? 'Unknown Organization' : orgName; |
| 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 | + )); |
40 | 71 | return ( |
41 | 72 | <AdditionalContainer> |
42 | 73 | <ContentHeading> |
43 | 74 | <h2 style={{ margin: '0', textTransform: 'uppercase' }}> |
44 | | - {getHeadingText({ type, userProfile, organizationName, fetchingOrgError })} |
| 75 | + {filterByType |
| 76 | + ? organizationName |
| 77 | + : getHeadingText({ type, userProfile, organizationName, fetchingOrgError })} |
45 | 78 | </h2> |
46 | 79 | </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> |
| 80 | + <Carousel items={carouselItems} scrollAmount={300} /> |
70 | 81 | </AdditionalContainer> |
71 | 82 | ); |
72 | 83 | }; |
|
0 commit comments