Skip to content

Commit bc17634

Browse files
authored
Merge pull request #88 from codersforcauses/issue-68-Add_showcased_games_to_landing_page
Issue 68 add showcased games to landing page
2 parents 2e2999d + 3a7b962 commit bc17634

2 files changed

Lines changed: 69 additions & 26 deletions

File tree

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

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 LandingGames 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+
<LandingGames />
198175
</div>
199176
</section>
200177
</div>

0 commit comments

Comments
 (0)