Skip to content

Commit cfbbb5e

Browse files
authored
Merge pull request #130 from codersforcauses/issue-124-Add_event_link_to_individual_game_games
Issue 124 add event link to individual game page
2 parents 35a1ae3 + d68446f commit cfbbb5e

2 files changed

Lines changed: 33 additions & 6 deletions

File tree

client/src/pages/games/[id].tsx

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import Image from "next/image";
2+
import Link from "next/link";
23
import { useRouter } from "next/router";
34
import React from "react";
45
import { SocialIcon } from "react-social-icons";
56

67
import { GameEmbed } from "@/components/ui/GameEmbed";
78
import { ItchEmbed } from "@/components/ui/ItchEmbed";
9+
import { useEvent } from "@/hooks/useEvent";
810
import { useGame } from "@/hooks/useGames";
911

1012
export default function IndividualGamePage() {
@@ -17,6 +19,9 @@ export default function IndividualGamePage() {
1719
error,
1820
isError,
1921
} = useGame(router.isReady ? id : undefined);
22+
const { data: eventData } = useEvent(
23+
game?.event ? String(game.event) : undefined,
24+
);
2025

2126
if (isPending) {
2227
return (
@@ -55,6 +60,8 @@ export default function IndividualGamePage() {
5560
const gameEmbedID = game.itchGameEmbedID;
5661
const gameWidth = game.itchGameWidth;
5762
const gameHeight = game.itchGameHeight;
63+
const eventID = game.event;
64+
const eventName = eventData?.name || "";
5865

5966
const completionLabels: Record<number, string> = {
6067
1: "WIP",
@@ -65,8 +72,6 @@ export default function IndividualGamePage() {
6572

6673
const devStage = completionLabels[game.completion] ?? "Stage Unknown";
6774

68-
// TODO ADD EVENT
69-
const event = "Game Jam November 2025";
7075
// TODO ADD ARTIMAGES
7176
const artImages: { src: string; alt: string }[] = [];
7277
// const artImages = [
@@ -129,12 +134,12 @@ export default function IndividualGamePage() {
129134
key={c.member_id}
130135
className="flex items-center gap-x-2"
131136
>
132-
<a
137+
<Link
133138
href={`/members/${c.member_id}`}
134139
className="text-primary hover:underline"
135140
>
136141
{c.name}
137-
</a>
142+
</Link>
138143
{Array.isArray(c.social_media) &&
139144
c.social_media.map((sm) => (
140145
<SocialIcon
@@ -175,7 +180,20 @@ export default function IndividualGamePage() {
175180
<td className="py-1 pr-2 text-muted-foreground sm:py-2">
176181
Event
177182
</td>
178-
<td className="py-1 text-right sm:py-2">{event}</td>
183+
<td className="py-1 text-right sm:py-2">
184+
{eventID && eventName ? (
185+
<Link
186+
href={`/events/${eventID}`}
187+
className="text-primary hover:underline"
188+
>
189+
{eventName}
190+
</Link>
191+
) : (
192+
<span className="text-muted-foreground">
193+
No past/upcoming event
194+
</span>
195+
)}
196+
</td>
179197
</tr>
180198
</tbody>
181199
</table>

server/game_dev/views.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,16 @@ class EventDetailAPIView(generics.RetrieveAPIView):
6060
lookup_url_kwarg = "id"
6161

6262
def get_queryset(self):
63-
return Event.objects.filter(id=self.kwargs["id"])
63+
now = timezone.now().date()
64+
return Event.objects.filter(id=self.kwargs["id"], publicationDate__lte=now)
65+
66+
def get_object(self):
67+
queryset = self.get_queryset()
68+
try:
69+
return queryset.get()
70+
except Event.DoesNotExist:
71+
from rest_framework.exceptions import NotFound
72+
raise NotFound(detail="The event is not yet published by admin or does not exist.")
6473

6574

6675
class GameshowcaseAPIView(APIView):

0 commit comments

Comments
 (0)