Skip to content

Commit 0cb0130

Browse files
committed
feat: add open leader board button
Signed-off-by: Amit Amrutiya <[email protected]>
1 parent e5feb80 commit 0cb0130

File tree

2 files changed

+37
-51
lines changed

2 files changed

+37
-51
lines changed

src/custom/PerformersSection/PerformersSection.tsx

Lines changed: 27 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* eslint-disable @typescript-eslint/no-explicit-any */
22
import { memo, useMemo } from 'react';
3-
import { Box } from '../../base';
3+
import { Box, Button } from '../../base';
44
import { iconXSmall } from '../../constants/iconsSizes';
55
import { LeaderBoardIcon, TropyIcon } from '../../icons';
66
import { useTheme } from '../../theme';
@@ -20,6 +20,7 @@ import {
2020
StatsValue,
2121
StyledCard,
2222
Title,
23+
TitleBox,
2324
UserNameText
2425
} from './styles';
2526

@@ -46,21 +47,18 @@ interface StatCardProps {
4647
patternName: string;
4748
pattern: Pattern;
4849
userName: string;
49-
userid: string;
5050
status: string;
5151
id: string;
5252
onCardClick: (pattern: Pattern) => void;
5353
onIconClick: (sortOrder: string) => void;
54-
onAuthorClick: (userId: string) => void;
55-
onStatusClick: (status: string) => void;
54+
onOpenLeaderboard?: () => void;
5655
}
5756

5857
interface PerformersSectionProps {
5958
useGetCatalogFilters: (params: any) => any;
6059
onCardClick: (pattern: Pattern) => void;
6160
onIconClick: (sortOrder: string) => void;
62-
onAuthorClick: (userId: string) => void;
63-
onStatusClick: (status: string) => void;
61+
onOpenLeaderboard?: () => void;
6462
}
6563

6664
type MetricType = 'view' | 'clone' | 'download' | 'deployment' | 'share';
@@ -114,12 +112,10 @@ const StatCardComponent: React.FC<StatCardProps> = ({
114112
patternName,
115113
pattern,
116114
userName,
117-
userid,
118115
status,
119116
id,
120117
onCardClick,
121-
onIconClick,
122-
onAuthorClick
118+
onIconClick
123119
}) => {
124120
const handleCardClick = () => {
125121
onCardClick(pattern);
@@ -130,11 +126,8 @@ const StatCardComponent: React.FC<StatCardProps> = ({
130126
onIconClick(sortOrder);
131127
};
132128

133-
const handleAuthorClick = (e: React.MouseEvent) => {
134-
e.stopPropagation();
135-
onAuthorClick(userid);
136-
};
137129
const theme = useTheme();
130+
138131
return (
139132
<StyledCard elevation={0} status={status} onClick={handleCardClick}>
140133
<ContentWrapper cardId={id}>
@@ -149,7 +142,7 @@ const StatCardComponent: React.FC<StatCardProps> = ({
149142

150143
<Box>
151144
<RepoTitle>{patternName}</RepoTitle>
152-
<UserNameText onClick={handleAuthorClick}>by {userName}</UserNameText>
145+
<UserNameText>by {userName}</UserNameText>
153146
</Box>
154147
</ContentWrapper>
155148
</StyledCard>
@@ -222,7 +215,6 @@ const processQueryData = (
222215
patternName: pattern.name || 'Unknown',
223216
pattern: pattern,
224217
userName: pattern.user?.first_name || 'Unknown',
225-
userid: pattern.user?.id,
226218
id: config.id,
227219
status: pattern?.catalog_data?.content_class
228220
};
@@ -232,8 +224,7 @@ const PerformersSection: React.FC<PerformersSectionProps> = ({
232224
useGetCatalogFilters,
233225
onCardClick,
234226
onIconClick,
235-
onAuthorClick,
236-
onStatusClick
227+
onOpenLeaderboard
237228
}) => {
238229
const theme = useTheme();
239230
const { queries, isLoading, hasError } = useMetricQueries(useGetCatalogFilters);
@@ -242,13 +233,8 @@ const PerformersSection: React.FC<PerformersSectionProps> = ({
242233
() =>
243234
(Object.keys(METRICS) as MetricType[])
244235
.map((metric) => processQueryData(queries, metric))
245-
.filter(
246-
(
247-
stat
248-
): stat is Omit<
249-
StatCardProps,
250-
'onCardClick' | 'onIconClick' | 'onAuthorClick' | 'onStatusClick'
251-
> => Boolean(stat)
236+
.filter((stat): stat is Omit<StatCardProps, 'onCardClick' | 'onIconClick'> =>
237+
Boolean(stat)
252238
),
253239
[queries]
254240
);
@@ -266,24 +252,29 @@ const PerformersSection: React.FC<PerformersSectionProps> = ({
266252
{...stat}
267253
onCardClick={onCardClick}
268254
onIconClick={onIconClick}
269-
onAuthorClick={onAuthorClick}
270-
onStatusClick={onStatusClick}
271255
/>
272256
));
273257

274258
return (
275259
<ErrorBoundary>
276260
<MainContainer>
277-
<Title>
278-
Top Performers
279-
<TropyIcon
280-
style={{
281-
height: '2rem',
282-
width: '2rem',
283-
color: theme.palette.icon.secondary
284-
}}
285-
/>
286-
</Title>
261+
<TitleBox>
262+
<Box display={'flex'} alignItems="center" gap={1}>
263+
<Title>Top Performers</Title>
264+
<TropyIcon
265+
style={{
266+
height: '2rem',
267+
width: '2rem',
268+
color: theme.palette.icon.secondary
269+
}}
270+
/>
271+
</Box>
272+
{onOpenLeaderboard && (
273+
<Button variant="contained" onClick={() => onOpenLeaderboard()}>
274+
Open Leaderboard
275+
</Button>
276+
)}
277+
</TitleBox>
287278
<CardsContainer>
288279
{isLoading && <StateCardSekeleton />}
289280
<Carousel items={statComponents} />

src/custom/PerformersSection/styles.tsx

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,19 @@ export const MainContainer = styled(Box)(({ theme }) => ({
7474
flexDirection: 'column'
7575
}));
7676

77+
export const TitleBox = styled(Box)(({ theme }) => ({
78+
paddingInline: theme.spacing(2),
79+
display: 'flex',
80+
alignItems: 'center',
81+
placeSelf: 'flex-start',
82+
justifyContent: 'space-between',
83+
width: '100%'
84+
}));
85+
7786
export const Title = styled(Typography)(({ theme }) => ({
7887
fontSize: '1.5rem',
7988
fontWeight: 600,
80-
color: theme.palette.text.default,
81-
paddingLeft: theme.spacing(2),
82-
display: 'flex',
83-
alignItems: 'center',
84-
gap: '0.5rem',
85-
placeSelf: 'flex-start'
89+
color: theme.palette.text.default
8690
}));
8791

8892
export const StyledCard = styled(Card)<StyledCardProps>(({ theme }) => ({
@@ -203,16 +207,7 @@ export const RepoTitle = styled(Typography)(({ theme }) => ({
203207

204208
export const UserNameText = styled(Typography)({
205209
fontSize: '0.75rem',
206-
// color:
207-
// theme.palette.mode === 'light'
208-
// ? theme.palette.text.constant?.disabled
209-
// : theme.palette.text.disabled,
210210
marginBottom: '8px'
211-
// transition: 'color 0.3s ease',
212-
213-
// '&:hover': {
214-
// color: theme.palette.text.brand
215-
// }
216211
});
217212

218213
export const CardsContainer = styled(Box)(({ theme }) => ({

0 commit comments

Comments
 (0)