Skip to content

Commit 251dc07

Browse files
committed
Fix several linter and type issues
1 parent 3b2d36d commit 251dc07

File tree

11 files changed

+53
-60
lines changed

11 files changed

+53
-60
lines changed

front_end/src/app/(main)/(home)/new/components/future_eval_section.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { getTranslations } from "next-intl/server";
21
import Link from "next/link";
2+
import { getTranslations } from "next-intl/server";
33
import { FC } from "react";
44

55
import WithServerComponentErrorBoundary from "@/components/server_component_error_boundary";

front_end/src/app/(main)/(home)/new/components/future_eval_table.tsx

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,32 @@ import Link from "next/link";
44
import { useTranslations } from "next-intl";
55
import { useMemo, useState } from "react";
66

7+
import MedalIcon from "@/app/(main)/(leaderboards)/components/medal_icon";
78
import {
89
entryIconPair,
910
entryLabel,
1011
shouldDisplayEntry,
1112
} from "@/app/(main)/aib/components/aib/leaderboard/utils";
1213
import { LightDarkIcon } from "@/app/(main)/aib/components/aib/light-dark-icon";
13-
import MedalIcon from "@/app/(main)/(leaderboards)/components/medal_icon";
1414
import type { LeaderboardDetails, MedalType } from "@/types/scoring";
1515
import cn from "@/utils/core/cn";
1616

1717
type Props = { details: LeaderboardDetails; className?: string };
1818

1919
const INITIAL_ROWS = 5;
2020

21+
const MedalRow = ({ rank }: { rank: number }) => {
22+
const medalType: MedalType =
23+
rank === 1 ? "gold" : rank === 2 ? "silver" : "bronze";
24+
25+
return rank <= 3 ? (
26+
<MedalIcon type={medalType} className="size-8" />
27+
) : (
28+
<span className="text-sm font-normal text-gray-1000 dark:text-gray-1000-dark">
29+
{rank}
30+
</span>
31+
);
32+
};
2133
const FutureEvalTable: React.FC<Props> = ({ details, className }) => {
2234
const t = useTranslations();
2335
const [expanded, setExpanded] = useState(false);
@@ -46,13 +58,6 @@ const FutureEvalTable: React.FC<Props> = ({ details, className }) => {
4658

4759
const visibleRows = expanded ? rows : rows.slice(0, INITIAL_ROWS);
4860

49-
const getMedalType = (rank: number): MedalType | null => {
50-
if (rank === 1) return "gold";
51-
if (rank === 2) return "silver";
52-
if (rank === 3) return "bronze";
53-
return null;
54-
};
55-
5661
return (
5762
<div className={cn("flex max-h-full w-full flex-col gap-2", className)}>
5863
<div
@@ -86,16 +91,7 @@ const FutureEvalTable: React.FC<Props> = ({ details, className }) => {
8691
>
8792
<Td className="pl-6">
8893
<div className="flex items-center justify-center">
89-
{getMedalType(r.rank) ? (
90-
<MedalIcon
91-
type={getMedalType(r.rank)!}
92-
className="size-8"
93-
/>
94-
) : (
95-
<span className="text-sm font-normal text-gray-1000 dark:text-gray-1000-dark">
96-
{r.rank}
97-
</span>
98-
)}
94+
<MedalRow rank={r.rank} />
9995
</div>
10096
</Td>
10197

front_end/src/app/(main)/(home)/new/components/hero_ctas.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { useTranslations } from "next-intl";
21
import Image from "next/image";
32
import Link from "next/link";
3+
import { useTranslations } from "next-intl";
44
import { FC, PropsWithChildren } from "react";
55

66
import Button from "@/components/ui/button";

front_end/src/app/(main)/(home)/new/components/homepage_forecasts.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"use client";
22

3-
import { useTranslations } from "next-intl";
43
import Link from "next/link";
4+
import { useTranslations } from "next-intl";
55
import { FC, useState, useTransition } from "react";
66

77
import PostCard from "@/components/post_card";
@@ -39,7 +39,7 @@ const HomePageForecasts: FC<Props> = ({ initialPopularPosts, className }) => {
3939
setActiveTab(tabId);
4040

4141
if (cachedPosts[tabId]) {
42-
setPosts(cachedPosts[tabId]!);
42+
setPosts(cachedPosts[tabId] ?? []);
4343
return;
4444
}
4545

front_end/src/app/(main)/(home)/new/components/research_and_updates.tsx

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
"use server";
22
import { intlFormat } from "date-fns";
3+
import Image from "next/image";
34
import Link from "next/link";
45
import { getLocale, getTranslations } from "next-intl/server";
56
import { FC } from "react";
67

7-
import Button from "@/components/ui/button";
88
import WithServerComponentErrorBoundary from "@/components/server_component_error_boundary";
9+
import Button from "@/components/ui/button";
910
import { NotebookPost } from "@/types/post";
1011
import cn from "@/utils/core/cn";
1112
import { estimateReadingTime, getMarkdownSummary } from "@/utils/markdown";
1213
import { getPostLink } from "@/utils/navigation";
13-
import Image from "next/image";
1414

1515
const CARD_GRADIENTS = [
1616
"radial-gradient(ellipse at center, #ede28f 0%, #c5b3c2 50%, #9d83f5 100%)",
@@ -51,13 +51,7 @@ const ResearchAndUpdates: FC<Props> = async ({ posts, className }) => {
5151

5252
<div className="mt-10 grid gap-4 sm:grid-cols-2 xl:grid-cols-4">
5353
{posts.slice(0, 4).map((post, index) => (
54-
<PostCard
55-
key={post.id}
56-
post={post}
57-
index={index}
58-
locale={locale}
59-
t={t}
60-
/>
54+
<PostCard key={post.id} post={post} index={index} locale={locale} />
6155
))}
6256
</div>
6357
</section>
@@ -68,10 +62,10 @@ type PostCardProps = {
6862
post: NotebookPost;
6963
index: number;
7064
locale: string;
71-
t: (key: string, values?: Record<string, unknown>) => string;
7265
};
7366

74-
const PostCard: FC<PostCardProps> = ({ post, index, locale, t }) => {
67+
const PostCard: FC<PostCardProps> = async ({ post, index, locale }) => {
68+
const t = await getTranslations();
7569
const {
7670
title,
7771
created_at,
@@ -81,6 +75,7 @@ const PostCard: FC<PostCardProps> = ({ post, index, locale, t }) => {
8175
author_username,
8276
comment_count = 0,
8377
} = post;
78+
8479
const readingTime = estimateReadingTime(notebook.markdown);
8580
const summary =
8681
notebook.markdown_summary ||

front_end/src/app/(main)/(home)/new/components/staff_picks.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import Link from "next/link";
2+
import { useTranslations } from "next-intl";
23
import { FC, ReactNode } from "react";
34

45
import cn from "@/utils/core/cn";
5-
import { useTranslations } from "next-intl";
66

77
type StaffPickItem = {
88
name: string;
@@ -17,7 +17,7 @@ type Props = {
1717
const StaffPicks: FC<Props> = ({ items }) => {
1818
const t = useTranslations();
1919
return (
20-
<div className="mb-6 flex items-center gap-4 overflow-hidden border-b border-gray-300 px-4 py-2.5 lg:px-20 dark:border-gray-200-dark bg-gray-200 dark:bg-gray-200-dark">
20+
<div className="mb-6 flex items-center gap-4 overflow-hidden border-b border-gray-300 bg-gray-200 px-4 py-2.5 dark:border-gray-200-dark dark:bg-gray-200-dark lg:px-20">
2121
<h2 className="m-0 shrink-0 text-xs font-medium uppercase leading-3 text-gray-700 dark:text-gray-700-dark">
2222
{t("staffPicks")}
2323
</h2>

front_end/src/app/(main)/(home)/new/components/tournaments_section.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import { getTranslations } from "next-intl/server";
22
import { FC } from "react";
33

4-
import Button from "@/components/ui/button";
4+
import WithServerComponentErrorBoundary from "@/components/server_component_error_boundary";
55
import TournamentCard from "@/components/tournament_card";
6+
import Button from "@/components/ui/button";
67
import ServerProjectsApi from "@/services/api/projects/projects.server";
78
import { TournamentType } from "@/types/projects";
89
import cn from "@/utils/core/cn";
9-
import WithServerComponentErrorBoundary from "@/components/server_component_error_boundary";
1010

1111
const TournamentsSection: FC<{ className?: string }> = async ({
1212
className,

front_end/src/app/(main)/(home)/new/components/why_metaculus.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
import { useTranslations } from "next-intl";
44
import React, { FC, useEffect, useState } from "react";
55

6-
import cn from "@/utils/core/cn";
76
import ClientMiscApi from "@/services/api/misc/misc.client";
7+
import cn from "@/utils/core/cn";
88

99
const AeiLogo: FC<{ className?: string }> = ({ className }) => (
1010
<svg

front_end/src/app/(main)/(home)/new/page.tsx

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,24 @@
11
import { redirect } from "next/navigation";
2-
32
import { Suspense } from "react";
43

54
import OnboardingCheck from "@/components/onboarding/onboarding_check";
65
import serverMiscApi from "@/services/api/misc/misc.server";
76
import ServerPostsApi from "@/services/api/posts/posts.server";
7+
import ServerProjectsApi from "@/services/api/projects/projects.server";
8+
import { NotebookPost } from "@/types/post";
89
import { getPublicSettings } from "@/utils/public_settings.server";
910
import { convertSidebarItem } from "@/utils/sidebar";
1011

1112
import EmailConfirmation from "../components/email_confirmation";
13+
import AllCategoriesSection from "./components/all_categories_section";
1214
import FutureEvalSection from "./components/future_eval_section";
1315
import HeroCTAs from "./components/hero_ctas";
1416
import { FILTERS } from "./components/homepage_filters";
1517
import HomePageForecasts from "./components/homepage_forecasts";
18+
import ResearchAndUpdates from "./components/research_and_updates";
1619
import StaffPicks from "./components/staff_picks";
1720
import TournamentsSection from "./components/tournaments_section";
1821
import WhyMetaculus from "./components/why_metaculus";
19-
import { NotebookPost } from "@/types/post";
20-
import ResearchAndUpdates from "./components/research_and_updates";
21-
import ServerProjectsApi from "@/services/api/projects/projects.server";
22-
import AllCategoriesSection from "./components/all_categories_section";
23-
import cn from "@/utils/core/cn";
2422

2523
export default async function Home() {
2624
const { PUBLIC_LANDING_PAGE_URL } = getPublicSettings();

front_end/src/app/(main)/components/footer.tsx

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ type FooterLink =
6363
| { labelKey: string; isModal: true; href?: undefined; external?: false }
6464
| { href: string; labelKey: string; external: true; isModal?: false };
6565

66-
const FOOTER_LINKS: Record<string, FooterLink[]> = {
66+
const FOOTER_LINKS = {
6767
explore: [
6868
{ href: "/questions", labelKey: "questions" },
6969
{ href: "/tournaments", labelKey: "tournaments" },
@@ -90,17 +90,17 @@ const FOOTER_LINKS: Record<string, FooterLink[]> = {
9090
{ href: "/press", labelKey: "forJournalists" },
9191
{ href: "/api", labelKey: "api" },
9292
],
93-
};
93+
} as const satisfies Record<string, readonly FooterLink[]>;
9494

95-
const THEME_OPTIONS: { value: AppTheme; labelKey: string }[] = [
95+
const THEME_OPTIONS = [
9696
{ value: AppTheme.System, labelKey: "settingsThemeSystemDefault" },
9797
{ value: AppTheme.Light, labelKey: "settingsThemeLightMode" },
9898
{ value: AppTheme.Dark, labelKey: "settingsThemeDarkMode" },
99-
];
99+
] as const satisfies readonly { value: AppTheme; labelKey: string }[];
100100

101101
const FooterLinkColumn: FC<{
102102
title: string;
103-
links: FooterLink[];
103+
links: readonly FooterLink[];
104104
onContactClick?: () => void;
105105
}> = ({ title, links, onContactClick }) => {
106106
const t = useTranslations();
@@ -151,7 +151,12 @@ const FooterLinkColumn: FC<{
151151
const LanguageSelector: FC = () => {
152152
const locale = useLocale();
153153
const currentLanguage =
154-
APP_LANGUAGES.find((l) => l.locale === locale) ?? APP_LANGUAGES[0]!;
154+
APP_LANGUAGES.find((l) => l.locale === locale) ??
155+
APP_LANGUAGES[APP_LANGUAGES.length - 1];
156+
157+
if (!currentLanguage) {
158+
return null;
159+
}
155160

156161
const handleLanguageChange = (newLocale: string) => {
157162
updateLanguagePreference(newLocale, false)
@@ -162,7 +167,7 @@ const LanguageSelector: FC = () => {
162167
return (
163168
<Listbox value={locale} onChange={handleLanguageChange}>
164169
<div className="relative">
165-
<ListboxButton className="flex h-10 items-center gap-2 rounded-lg border border-gray-300 bg-white px-3 text-sm font-medium text-gray-900">
170+
<ListboxButton className="flex h-10 items-center gap-2 text-nowrap rounded-lg border border-gray-300 bg-white px-3 text-sm font-medium text-gray-900">
166171
<span className="flex items-center text-base font-bold">
167172
<span className="text-blue-800">a</span>
168173
<span className="text-gray-400">/</span>
@@ -202,8 +207,7 @@ const ThemeSelector: FC = () => {
202207

203208
const currentTheme = mounted ? themeChoice : AppTheme.System;
204209
const currentOption =
205-
THEME_OPTIONS.find((opt) => opt.value === currentTheme) ??
206-
THEME_OPTIONS[0]!;
210+
THEME_OPTIONS.find((opt) => opt.value === currentTheme) ?? THEME_OPTIONS[0];
207211

208212
const handleThemeChange = (value: AppTheme) => {
209213
setTheme(value);
@@ -212,7 +216,7 @@ const ThemeSelector: FC = () => {
212216
return (
213217
<Listbox value={currentTheme} onChange={handleThemeChange}>
214218
<div className="relative">
215-
<ListboxButton className="flex h-10 items-center gap-2 rounded-lg border border-gray-300 bg-white px-3 text-sm font-medium text-gray-900">
219+
<ListboxButton className="flex h-10 items-center gap-2 text-nowrap rounded-lg border border-gray-300 bg-white px-3 text-sm font-medium text-gray-900">
216220
<ComputerIcon className="size-5 text-gray-700" />
217221
<span>{t(currentOption.labelKey as Parameters<typeof t>[0])}</span>
218222
<FontAwesomeIcon
@@ -227,7 +231,7 @@ const ThemeSelector: FC = () => {
227231
value={option.value}
228232
className={({ selected }) =>
229233
cn(
230-
"cursor-pointer px-3 py-2 text-sm text-gray-900 hover:bg-gray-100",
234+
"cursor-pointer text-nowrap px-3 py-2 text-sm text-gray-900 hover:bg-gray-100",
231235
selected && "bg-gray-100 font-medium"
232236
)
233237
}
@@ -299,23 +303,23 @@ const Footer: FC = () => {
299303
<div className="flex gap-6 sm:gap-[120px]">
300304
<FooterLinkColumn
301305
title={t("explore")}
302-
links={FOOTER_LINKS.explore!}
306+
links={FOOTER_LINKS.explore}
303307
/>
304308
<FooterLinkColumn
305309
title={t("services")}
306-
links={FOOTER_LINKS.services!}
310+
links={FOOTER_LINKS.services}
307311
/>
308312
</div>
309313
{/* Second row on mobile */}
310314
<div className="flex gap-[122px] sm:gap-[218px] lg:gap-[120px]">
311315
<FooterLinkColumn
312316
title={t("company")}
313-
links={FOOTER_LINKS.company!}
317+
links={FOOTER_LINKS.company}
314318
onContactClick={handleContactClick}
315319
/>
316320
<FooterLinkColumn
317321
title={t("resources")}
318-
links={FOOTER_LINKS.resources!}
322+
links={FOOTER_LINKS.resources}
319323
/>
320324
</div>
321325
</div>

0 commit comments

Comments
 (0)