Skip to content

Commit 7fea141

Browse files
committed
fix: code review
1 parent 1be27b3 commit 7fea141

File tree

8 files changed

+54
-27
lines changed

8 files changed

+54
-27
lines changed

CLAUDE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ className="border-border-light dark:border-border-dark"
5656

5757
#### Brand/Accent Colors
5858
```tsx
59-
// Primary brand color (blue)
59+
// Primary brand color (blue) - use for primary actions and highlights
6060
className="bg-brand" // #4190EB
6161

6262
// Primary buttons

app/[lang]/(common)/Header/index.tsx

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,16 @@ import Button from '../Button';
2121
import SwitchToggle from './SwitchToggle';
2222

2323
const inter = Inter({subsets: ['latin']});
24+
const normalizePath = (path: string): string => path.replace(/\/+$/, '');
25+
const isActivePath = (
26+
pathname: string | null,
27+
lang: string,
28+
path: string,
29+
): boolean => {
30+
const target = normalizePath(`/${lang}${path}`);
31+
const current = normalizePath(pathname ?? '');
32+
return current === target || current.startsWith(`${target}/`);
33+
};
2434

2535
export type NavLink = {
2636
name: string;
@@ -46,13 +56,6 @@ function DesktopNavMenus(
4656
const router = useRouter();
4757
const supabase = getSupabaseBrowserClient();
4858

49-
const normalizePath = (path: string): string => path.replace(/\/+$/, '');
50-
const isActivePath = (path: string): boolean => {
51-
const target = normalizePath(`/${lang}${path}`);
52-
const current = normalizePath(pathname ?? '');
53-
return current === target || current.startsWith(`${target}/`);
54-
};
55-
5659
return (
5760
<div
5861
className={clsx('flex-1 justify-between items-center', 'max-md:hidden')}
@@ -71,7 +74,9 @@ function DesktopNavMenus(
7174
href={`${link.path}`}
7275
className={clsx(
7376
'text-body4 truncate',
74-
isActivePath(link.path) ? 'opacity-100' : 'opacity-30',
77+
isActivePath(pathname, lang, link.path)
78+
? 'opacity-100'
79+
: 'opacity-30',
7580
)}
7681
>
7782
<li
@@ -137,13 +142,6 @@ function MobileNavMenus(
137142

138143
const [isNavCollapsed, setIsNavCollapsed] = useState(true);
139144

140-
const normalizePath = (path: string): string => path.replace(/\/+$/, '');
141-
const isActivePath = (path: string): boolean => {
142-
const target = normalizePath(`/${lang}${path}`);
143-
const current = normalizePath(pathname ?? '');
144-
return current === target || current.startsWith(`${target}/`);
145-
};
146-
147145
return (
148146
<div className={clsx('md:hidden flex-1', 'flex flex-row-reverse')}>
149147
<div className="cursor-pointer">
@@ -183,7 +181,9 @@ function MobileNavMenus(
183181
'text-body4 truncate flex-1 h-10 px-8',
184182
'flex items-center',
185183
'hover:opacity-100',
186-
isActivePath(link.path) ? 'opacity-100' : 'opacity-30',
184+
isActivePath(pathname, lang, link.path)
185+
? 'opacity-100'
186+
: 'opacity-30',
187187
)}
188188
>
189189
<li
@@ -261,7 +261,7 @@ export default function Header(props: Props): ReactElement {
261261
path: `/stats/${login}`,
262262
},
263263
{
264-
name: t.recentList,
264+
name: t.leaderboards,
265265
path: '/leaderboards',
266266
},
267267
]
@@ -271,7 +271,7 @@ export default function Header(props: Props): ReactElement {
271271
path: `/stats`,
272272
},
273273
{
274-
name: t.recentList,
274+
name: t.leaderboards,
275275
path: '/leaderboards',
276276
},
277277
];

app/[lang]/leaderboards/GithubUserList.tsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ const TIER_ORDER: Tier[] = [
3232
];
3333

3434
type Props = {
35-
t: Translates['recentList'];
35+
t: Translates['leaderboards'];
3636
initialData: UserListItem[];
3737
};
3838

@@ -142,10 +142,14 @@ export default function GithubUserList({t, initialData}: Props): ReactElement {
142142
cursor,
143143
});
144144

145-
const filteredUsers = users.filter((el) => !data.includes(el));
145+
const filteredUsers = users.filter(
146+
(el) => !data.some((existing) => existing.login === el.login),
147+
);
146148

147-
setData([...data, ...filteredUsers]);
148-
setCursor(new Date(filteredUsers?.[filteredUsers.length - 1]?.createdAt));
149+
if (filteredUsers.length > 0) {
150+
setData([...data, ...filteredUsers]);
151+
setCursor(new Date(filteredUsers[filteredUsers.length - 1].createdAt));
152+
}
149153
}
150154
};
151155

app/[lang]/leaderboards/TopTierUsers.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ export default function TopTierUsers({title}: Props): ReactElement {
2424
const fetchTopUsers = async () => {
2525
try {
2626
const response = await fetch(API_TOP_TIER_USERS);
27+
if (!response.ok) {
28+
throw new Error(`HTTP error: ${response.status}`);
29+
}
2730
const data = await response.json();
2831
if (data.users) {
2932
setTopTierUsers(data.users);
@@ -63,7 +66,7 @@ export default function TopTierUsers({title}: Props): ReactElement {
6366
}
6467

6568
if (topTierUsers.length === 0) {
66-
return <div />;
69+
return <></>;
6770
}
6871

6972
return (

app/[lang]/stats/[login]/Scouter/StatsDetails/SectionDooboo.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ function SectionHeader({t, stats, endDate}: SectionProps): ReactElement {
5151
} else {
5252
router.push(pathname);
5353
}
54-
router.refresh();
5554
},
5655
[pathname, router],
5756
);

app/[lang]/stats/[login]/Scouter/StatsDetails/StatsChart.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,10 @@ export default function StatsChart({
8282
// Format month for display (YYYY-MM -> MMM)
8383
const formatMonth = (month: string): string => {
8484
const [, monthNum] = month.split('-');
85+
const monthIndex = parseInt(monthNum, 10) - 1;
86+
if (Number.isNaN(monthIndex) || monthIndex < 0 || monthIndex > 11) {
87+
return month;
88+
}
8589
const months = [
8690
'Jan',
8791
'Feb',
@@ -96,7 +100,7 @@ export default function StatsChart({
96100
'Nov',
97101
'Dec',
98102
];
99-
return months[parseInt(monthNum, 10) - 1];
103+
return months[monthIndex];
100104
};
101105

102106
const chartData = monthlyContributions?.map((item) => ({

app/[lang]/stats/[login]/SearchTextInput.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ export default function SearchTextInput({
5050
}, [initialValue]);
5151

5252
const navigateTo = (loginValue: string) => {
53+
// Avoid toggling loading when navigating to the same user
54+
if (loginValue === initialValue) {
55+
return;
56+
}
57+
5358
pendingLoginRef.current = loginValue;
5459
setIsLoading(true);
5560
router.push(`/${lang}/stats/${loginValue}`);

server/services/githubService.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,19 @@ export const getGithubUser = async (
5757
let date: Date;
5858
if (startDate) {
5959
const [year, month] = startDate.split('-').map(Number);
60-
date = new Date(Date.UTC(year, month - 1, 1, 12, 0, 0));
60+
if (
61+
Number.isFinite(year) &&
62+
Number.isFinite(month) &&
63+
month >= 1 &&
64+
month <= 12
65+
) {
66+
date = new Date(Date.UTC(year, month - 1, 1, 12, 0, 0));
67+
} else {
68+
const now = new Date();
69+
date = new Date(
70+
Date.UTC(now.getUTCFullYear(), now.getUTCMonth() - 12, 1, 12, 0, 0),
71+
);
72+
}
6173
} else {
6274
const now = new Date();
6375
date = new Date(

0 commit comments

Comments
 (0)