Skip to content

Commit 2dd4b54

Browse files
committed
create component for games showcase on landing page
created component to not convolute index with checks etc.
1 parent 254d5d4 commit 2dd4b54

2 files changed

Lines changed: 61 additions & 26 deletions

File tree

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import Image from "next/image";
2+
import Link from "next/link";
3+
4+
import { useGameshowcase } from "@/hooks/useGameshowcase";
5+
6+
export default function LandingGame() {
7+
const { data: showcases, isPending, isError, error } = useGameshowcase();
8+
if (isPending) {
9+
return (
10+
<main className="mx-auto min-h-screen max-w-7xl px-6 py-16">
11+
<p>Loading games...</p>
12+
</main>
13+
);
14+
}
15+
16+
if (isError) {
17+
const errorMessage =
18+
error?.response?.status === 404
19+
? "Games not found."
20+
: "Failed to Load Games";
21+
return (
22+
<main className="mx-auto min-h-screen max-w-7xl px-6 py-16">
23+
<p className="text-red-500" role="alert">
24+
{errorMessage}
25+
</p>
26+
</main>
27+
);
28+
}
29+
return (
30+
<div className="grid grid-cols-1 gap-10 md:grid-cols-3">
31+
{showcases.slice(0, 3).map((game) => (
32+
<div
33+
key={game.game_id}
34+
className="rounded-xl p-6 text-background shadow-lg duration-200 ease-in-out hover:scale-110"
35+
>
36+
<Link key={game.game_id} href={`/games/${game.game_id}`}>
37+
<div className="relative aspect-[16/9] w-full overflow-hidden rounded-lg">
38+
<Image
39+
src={game.gameCover}
40+
alt={game.game_name}
41+
fill
42+
className="object-cover"
43+
/>
44+
</div>
45+
<h3 className="mb-2 mt-4 font-jersey10 text-2xl text-white">
46+
{game.game_name}
47+
</h3>
48+
49+
<p className="mb-4 truncate text-sm text-primary">
50+
{game.game_description}
51+
</p>
52+
<div className="h-px w-full bg-white/30" />
53+
</Link>
54+
</div>
55+
))}
56+
</div>
57+
);
58+
}

client/src/pages/index.tsx

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ import {
66
EventHighlightCard,
77
eventHighlightCardType,
88
} from "@/components/ui/eventHighlightCard";
9-
import { placeholderEvents, placeholderGames } from "@/placeholderData";
9+
import LandingGame from "@/components/ui/landingGames";
10+
import { placeholderEvents } from "@/placeholderData";
1011

1112
import { Button } from "../components/ui/button";
1213

@@ -170,31 +171,7 @@ export default function Landing() {
170171
</Link>
171172
</div>
172173
</div>
173-
174-
<div className="grid grid-cols-1 gap-10 md:grid-cols-3">
175-
{placeholderGames.map((game) => (
176-
<div
177-
key={game.id}
178-
className="rounded-xl p-6 text-background shadow-lg"
179-
>
180-
<div className="relative aspect-[16/9] w-full overflow-hidden rounded-lg">
181-
<Image
182-
src={game.thumbnail}
183-
alt={game.name}
184-
fill
185-
className="object-cover"
186-
/>
187-
</div>
188-
<h3 className="mb-2 mt-4 font-jersey10 text-2xl text-white">
189-
{game.name}
190-
</h3>
191-
192-
<p className="mb-4 text-sm text-primary">{game.description}</p>
193-
194-
<div className="h-px w-full bg-white/30" />
195-
</div>
196-
))}
197-
</div>
174+
<LandingGame />
198175
</div>
199176
</section>
200177
</div>

0 commit comments

Comments
 (0)