Skip to content

Commit 88cf288

Browse files
committed
chore: some of the props and update funtions
Signed-off-by: Amit Amrutiya <amitamrutiya2210@gmail.com>
1 parent 166bc6e commit 88cf288

5 files changed

Lines changed: 89 additions & 65 deletions

File tree

src/custom/CatalogDetail/ChallengesSection.tsx

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { useEffect, useState } from 'react';
2-
import { ListItemIcon } from '../../base';
2+
import { Link, ListItemIcon } from '../../base';
33
import { ChallengesIcon } from '../../icons';
44
import { useTheme } from '../../theme';
55
import CollapsibleSection from './CollapsibleSection';
@@ -27,21 +27,24 @@ const ChallengesSection: React.FC<ChallengesSectionProps> = ({ filteredAcademyDa
2727
setAutoUpdate(false);
2828
};
2929

30-
const navigateToChallenge = (item: string) => {
31-
window.location.href = `/academy/challenges/${slugify('' + item)}`;
32-
};
33-
3430
const renderChallengeItem = (item: string, index: number) => (
35-
<LabelDiv key={index} clickable={true} onClick={() => navigateToChallenge(item)}>
36-
<ListItemIcon sx={{ minWidth: '1.5rem', marginRight: 1 }}>
37-
<ChallengesIcon
38-
primaryFill={theme.palette.icon.default}
39-
secondaryFill={theme.palette.icon.secondary}
40-
brandFill={theme.palette.icon.secondary}
41-
/>
42-
</ListItemIcon>
43-
{item}
44-
</LabelDiv>
31+
<Link
32+
href={`https://meshery.layer5.io/academy/challenges/${slugify('' + item)}`}
33+
target="_blank"
34+
rel="noopener noreferrer"
35+
style={{ textDecoration: 'none', color: 'inherit' }}
36+
>
37+
<LabelDiv key={index} clickable={true}>
38+
<ListItemIcon sx={{ minWidth: '1.5rem', marginRight: 1 }}>
39+
<ChallengesIcon
40+
primaryFill={theme.palette.icon.default}
41+
secondaryFill={theme.palette.icon.secondary}
42+
brandFill={theme.palette.icon.secondary}
43+
/>
44+
</ListItemIcon>
45+
{item}
46+
</LabelDiv>
47+
</Link>
4548
);
4649

4750
return (

src/custom/CatalogDetail/LearningSection.tsx

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React, { useEffect, useState } from 'react';
2-
import { ListItemIcon } from '../../base';
2+
import { Link, ListItemIcon } from '../../base';
33
import { LearningIcon } from '../../icons';
44
import { useTheme } from '../../theme';
55
import CollapsibleSection from './CollapsibleSection';
@@ -27,20 +27,23 @@ const LearningSection: React.FC<LearningSectionProps> = ({ filteredAcademyData }
2727
setAutoUpdate(false);
2828
};
2929

30-
const navigateToLearningPath = (item: string): void => {
31-
window.location.href = `/academy/learning-paths/${slugify('' + item)}`;
32-
};
33-
3430
const renderLearningItem = (item: string, index: number) => (
35-
<LabelDiv key={index} clickable={true} onClick={() => navigateToLearningPath(item)}>
36-
<ListItemIcon sx={{ minWidth: '1.5rem', marginRight: 1 }}>
37-
<LearningIcon
38-
primaryFill={theme.palette.icon.default}
39-
secondaryFill={theme.palette.icon.secondary}
40-
/>
41-
</ListItemIcon>
42-
{item}
43-
</LabelDiv>
31+
<Link
32+
href={`https://meshery.layer5.io/academy/learning-paths/${slugify('' + item)}`}
33+
target="_blank"
34+
rel="noopener noreferrer"
35+
style={{ textDecoration: 'none', color: 'inherit' }}
36+
>
37+
<LabelDiv key={index} clickable={true}>
38+
<ListItemIcon sx={{ minWidth: '1.5rem', marginRight: 1 }}>
39+
<LearningIcon
40+
primaryFill={theme.palette.icon.default}
41+
secondaryFill={theme.palette.icon.secondary}
42+
/>
43+
</ListItemIcon>
44+
{item}
45+
</LabelDiv>
46+
</Link>
4447
);
4548

4649
return (

src/custom/CatalogDetail/OverviewSection.tsx

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,34 +13,31 @@ interface OverviewSectionProps {
1313
details: Pattern;
1414
type: string;
1515
cardId: string;
16-
handleClick: (event: React.MouseEvent) => void;
1716
title: string;
18-
id: string;
19-
anchorEl: HTMLElement | null;
20-
handleClose: () => void;
2117
getUrl: (type: string, id: string) => string;
2218
showContentDetails: boolean;
2319
ViewsComponent?: React.ReactNode;
2420
showVersion: boolean;
2521
classes: Class[];
2622
handleCopyUrl: (type: string, name: string, id: string) => void;
23+
fontFamily?: string;
24+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
25+
userProfile?: any;
2726
}
2827

2928
const OverviewSection: React.FC<OverviewSectionProps> = ({
3029
details,
3130
type,
3231
cardId,
33-
handleClick,
3432
title,
35-
id,
36-
anchorEl,
37-
handleClose,
3833
getUrl,
3934
showContentDetails,
4035
ViewsComponent,
4136
showVersion,
4237
classes,
43-
handleCopyUrl
38+
handleCopyUrl,
39+
fontFamily,
40+
userProfile
4441
}) => {
4542
return (
4643
<OverviewContainer>
@@ -49,27 +46,24 @@ const OverviewSection: React.FC<OverviewSectionProps> = ({
4946
display: 'flex',
5047
flexDirection: 'row',
5148
width: '100%',
52-
flexWrap: 'wrap'
49+
flexWrap: 'wrap',
50+
fontFamily: fontFamily || 'inherit'
5351
}}
5452
>
5553
<DesignHeading>{details?.name}</DesignHeading>
5654
<SocialSharePopper
5755
details={details}
5856
type={type}
5957
cardId={cardId}
60-
handleClick={handleClick}
6158
title={title}
62-
id={id}
63-
anchorEl={anchorEl}
64-
handleClose={handleClose}
6559
getUrl={getUrl}
6660
handleCopyUrl={handleCopyUrl}
6761
/>
6862
</div>
6963
<Grid container spacing={2}>
7064
<Grid item lg={4} md={4} sm={12} xs={12}>
7165
<Grid container>
72-
<Grid item lg={12} md={12} sm={6} xs={6}>
66+
<Grid item lg={12} md={12} sm={6} xs={6} style={{ fontFamily: fontFamily }}>
7367
{details?.catalog_data?.content_class && (
7468
<ContentRow>
7569
<ContentClassInfo
@@ -78,7 +72,7 @@ const OverviewSection: React.FC<OverviewSectionProps> = ({
7872
/>
7973
</ContentRow>
8074
)}
81-
<UserInfo details={details} showVersion={showVersion} />
75+
<UserInfo details={details} showVersion={showVersion} userProfile={userProfile} />
8276
</Grid>
8377
</Grid>
8478
</Grid>

src/custom/CatalogDetail/RelatedDesigns.tsx

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { CatalogCardDesignLogo } from '../CustomCatalog';
22
import CustomCatalogCard, { Pattern } from '../CustomCatalog/CustomCard';
33
import { formatToTitleCase } from './helper';
44
import { AdditionalContainer, ContentHeading, DesignCardContainer } from './style';
5+
import { UserProfile } from './types';
56

67
export interface PatternsPerUser {
78
patterns: Pattern[];
@@ -11,9 +12,17 @@ interface RelatedDesignsProps {
1112
details: Pattern;
1213
type: string;
1314
patternsPerUser: PatternsPerUser;
15+
onSuggestedPatternClick: (pattern: Pattern) => void;
16+
userProfile?: UserProfile;
1417
}
1518

16-
const RelatedDesigns: React.FC<RelatedDesignsProps> = ({ details, type, patternsPerUser }) => {
19+
const RelatedDesigns: React.FC<RelatedDesignsProps> = ({
20+
details,
21+
type,
22+
patternsPerUser,
23+
onSuggestedPatternClick,
24+
userProfile
25+
}) => {
1726
const filteredPatternsPerUser = patternsPerUser?.patterns?.filter(
1827
(pattern) => pattern.id !== details.id
1928
);
@@ -24,15 +33,26 @@ const RelatedDesigns: React.FC<RelatedDesignsProps> = ({ details, type, patterns
2433
<AdditionalContainer>
2534
<ContentHeading>
2635
<h2 style={{ margin: '0', textTransform: 'uppercase' }}>
27-
Other published design by {formatToTitleCase(details.user.first_name)}
36+
Other published design by
37+
{formatToTitleCase(userProfile?.first_name ?? '')}
2838
</h2>
2939
</ContentHeading>
3040
<DesignCardContainer>
3141
{filteredPatternsPerUser.map((pattern, index) => (
32-
<CustomCatalogCard key={`design-${index}`} pattern={pattern} patternType={type}>
42+
<CustomCatalogCard
43+
key={`design-${index}`}
44+
pattern={pattern}
45+
patternType={type}
46+
onCardClick={() => onSuggestedPatternClick(pattern)}
47+
UserName={`${userProfile?.first_name ?? ''} ${userProfile?.last_name ?? ''}`}
48+
avatarUrl={userProfile?.avatar_url}
49+
basePath="/static/img/meshmodels"
50+
subBasePath="color"
51+
cardTechnologies={true}
52+
>
3353
<CatalogCardDesignLogo
3454
imgURL={pattern?.catalog_data?.imageURL}
35-
height={'100%'}
55+
height={'7.5rem'}
3656
width={'100%'}
3757
zoomEffect={false}
3858
type={{ type: type }}

src/custom/CatalogDetail/RightPanel.tsx

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,64 +8,68 @@ import { Class } from './types';
88
interface RightPanelProps {
99
details: Pattern;
1010
type: string;
11-
cardId: string;
12-
handleClick: (event: React.MouseEvent) => void;
11+
cardId?: string;
1312
title: string;
14-
id?: string;
15-
anchorEl: HTMLElement | null;
16-
handleClose: () => void;
1713
getUrl: (type: string, id: string) => string;
1814
showContentDetails: boolean;
1915
ViewsComponent?: React.ReactNode;
2016
showVersion: boolean;
2117
showCaveats: boolean;
2218
classes: Class[];
2319
patternsPerUser: PatternsPerUser;
20+
onSuggestedPatternClick: (pattern: Pattern) => void;
2421
handleCopyUrl: (type: string, name: string, id: string) => void;
2522
fontFamily?: string;
23+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
24+
useGetUserProfileByIdQuery: any;
2625
}
2726

2827
const RightPanel: React.FC<RightPanelProps> = ({
2928
details,
3029
type,
31-
cardId,
32-
handleClick,
30+
cardId = details.id,
3331
title,
34-
id = '',
35-
anchorEl,
36-
handleClose,
3732
getUrl,
3833
showContentDetails,
3934
ViewsComponent,
4035
showVersion,
4136
showCaveats,
4237
classes,
4338
patternsPerUser,
39+
onSuggestedPatternClick,
4440
handleCopyUrl,
45-
fontFamily
41+
fontFamily,
42+
useGetUserProfileByIdQuery
4643
}) => {
4744
const cleanedType = type.replace('my-', '').replace(/s$/, '');
45+
const { data: userProfile } = useGetUserProfileByIdQuery({
46+
id: details.user_id
47+
});
4848

4949
return (
5050
<div style={{ fontFamily }}>
5151
<OverviewSection
5252
details={details}
5353
type={cleanedType}
5454
cardId={cardId}
55-
handleClick={handleClick}
5655
title={title}
57-
id={id}
58-
anchorEl={anchorEl}
59-
handleClose={handleClose}
6056
getUrl={getUrl}
6157
showContentDetails={showContentDetails}
6258
ViewsComponent={ViewsComponent}
6359
showVersion={showVersion}
6460
classes={classes}
6561
handleCopyUrl={handleCopyUrl}
62+
fontFamily={fontFamily}
63+
userProfile={userProfile}
6664
/>
6765
{showCaveats && <CaveatsSection details={details} />}
68-
<RelatedDesigns details={details} type={type} patternsPerUser={patternsPerUser} />
66+
<RelatedDesigns
67+
details={details}
68+
type={type}
69+
patternsPerUser={patternsPerUser}
70+
onSuggestedPatternClick={onSuggestedPatternClick}
71+
userProfile={userProfile}
72+
/>
6973
</div>
7074
);
7175
};

0 commit comments

Comments
 (0)