Skip to content
This repository was archived by the owner on Oct 7, 2025. It is now read-only.

Commit 867d886

Browse files
committed
feat(portal/challenge): add challenge page
1 parent 388203f commit 867d886

File tree

12 files changed

+273
-208
lines changed

12 files changed

+273
-208
lines changed
Lines changed: 20 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,31 @@
1-
// import type { LoaderFunction } from '@remix-run/node'
2-
// import process from 'node:process'
1+
import type { LoaderFunction } from '@remix-run/node'
2+
import process from 'node:process'
33
import { ChallengesPage } from '@cuhacking/portal/pages/challenges'
4-
// import { useLoaderData } from '@remix-run/react'
4+
import { useLoaderData } from '@remix-run/react'
55

6-
// export const loader: LoaderFunction = async () => {
7-
// try {
8-
// const API_URL = process.env.NODE_ENV === 'development' ? 'http://localhost:8000' : 'https://axiom.cuhacking.ca'
9-
// const req = await fetch(`${API_URL}/api/challenges`)
6+
export const loader: LoaderFunction = async () => {
7+
try {
8+
const API_URL = process.env.NODE_ENV === 'development' ? 'http://localhost:8000' : 'https://axiom.cuhacking.ca'
9+
const req = await fetch(`${API_URL}/api/challenges`)
1010

11-
// if (!req.ok) {
12-
// throw new Error('Error')
13-
// }
11+
if (!req.ok) {
12+
throw new Error('Error')
13+
}
1414

15-
// // const { res } = await req.json()
15+
const data = await req.json()
1616

17-
// const data = { title: '', pathTitle: '', symbol: {}, challengeBlock: [] }
18-
19-
// //console.log(data)
20-
21-
// return {
22-
// title: data.title,
23-
// pathTitle: data.pathTitle,
24-
// symbol: data.symbol,
25-
// challengeBlock: data.challengeBlock
26-
// }
27-
// }
28-
// catch () {
29-
// console.error(`Error fetching challenges`)
30-
// return { title: '', pathTitle: '', symbol: {}, challengeBlock: [] }
31-
// }
32-
// }
17+
return data.docs
18+
}
19+
catch (error) {
20+
console.error(`Error fetching challenges`, error)
21+
return [{ title: '', pathTitle: '', sponsor: { symbol: { url: '', alt: '' } }, challengeBlock: [] }]
22+
}
23+
}
3324

3425
export default function Challenges() {
35-
// const data = useLoaderData<typeof loader>()
26+
const data = useLoaderData<typeof loader>()
3627

3728
return (
38-
<ChallengesPage />
29+
<ChallengesPage data={data} />
3930
)
4031
}

apps/portal/app/routes/map.tsx

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import type { LoaderFunction } from '@remix-run/node'
2+
import process from 'node:process'
3+
import { MapsPage } from '@cuhacking/portal/pages/map'
4+
5+
export const loader: LoaderFunction = async () => {
6+
try {
7+
const API_URL = process.env.NODE_ENV === 'development' ? 'http://localhost:8000' : 'https://axiom.cuhacking.ca'
8+
const req = await fetch(`${API_URL}/api/challenges`)
9+
10+
if (!req.ok) {
11+
throw new Error('Error')
12+
}
13+
14+
const data = await req.json()
15+
16+
return data.docs
17+
}
18+
catch (error) {
19+
console.error(`Error fetching challenges`, error)
20+
}
21+
}
22+
23+
export default function Map() {
24+
// const data = useLoaderData<typeof loader>()
25+
26+
return (
27+
<MapsPage />
28+
)
29+
}

apps/portal/app/routes/qr.tsx

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import type { LoaderFunction } from '@remix-run/node'
2+
import process from 'node:process'
3+
import { QrPage } from '@cuhacking/portal/pages/qr'
4+
5+
export const loader: LoaderFunction = async () => {
6+
try {
7+
const API_URL = process.env.NODE_ENV === 'development' ? 'http://localhost:8000' : 'https://axiom.cuhacking.ca'
8+
const req = await fetch(`${API_URL}/api/challenges`)
9+
10+
if (!req.ok) {
11+
throw new Error('Error')
12+
}
13+
14+
const data = await req.json()
15+
16+
return data.docs
17+
}
18+
catch (error) {
19+
console.error(`Error fetching challenges`, error)
20+
}
21+
}
22+
23+
export default function QR() {
24+
// const data = useLoaderData<typeof loader>()
25+
26+
return (
27+
<QrPage />
28+
)
29+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import type { LoaderFunction } from '@remix-run/node'
2+
import process from 'node:process'
3+
import { SchedulePage } from '@cuhacking/portal/pages/schedule'
4+
5+
export const loader: LoaderFunction = async () => {
6+
try {
7+
const API_URL = process.env.NODE_ENV === 'development' ? 'http://localhost:8000' : 'https://axiom.cuhacking.ca'
8+
const req = await fetch(`${API_URL}/api/challenges`)
9+
10+
if (!req.ok) {
11+
throw new Error('Error')
12+
}
13+
14+
const data = await req.json()
15+
16+
return data.docs
17+
}
18+
catch (error) {
19+
console.error(`Error fetching challenges`, error)
20+
}
21+
}
22+
23+
export default function Schedule() {
24+
// const data = useLoaderData<typeof loader>()
25+
26+
return (
27+
<SchedulePage />
28+
)
29+
}

libs/db/collections/models/Challenges.ts

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export const Challenges: CollectionConfig = {
1212
fields: [
1313
{name: "pathTitle", type: "text"},
1414
{name: "title", type: "text"},
15-
{name: "symbol", type: "upload", relationTo: "media"},
15+
{name: "sponsor", type: "relationship", relationTo: "brands"},
1616
{
1717
name: 'challengeBlock',
1818
type: 'blocks',
@@ -65,7 +65,7 @@ export async function seedChallenges(payload: Payload, req: any) {
6565
{
6666
pathTitle: "E:[email protected]",
6767
title: "Best use of QNX - Software",
68-
symbol: "qnx-logo.png",
68+
sponsor: "QNX",
6969
challengeBlock: [
7070
{
7171
blockName: "QNX Details",
@@ -114,7 +114,7 @@ export async function seedChallenges(payload: Payload, req: any) {
114114
{
115115
pathTitle: "E:[email protected]",
116116
title: "Best use of QNX - Hardware",
117-
symbol: "qnx-hardware.png",
117+
sponsor: "QNX",
118118
challengeBlock: [
119119
{
120120
blockName: "QNX Hardware Details",
@@ -154,7 +154,7 @@ export async function seedChallenges(payload: Payload, req: any) {
154154
{
155155
pathTitle: "E:[email protected]",
156156
title: "Best overall project (1st, 2nd, and 3rd place)",
157-
symbol: "external-judges.png",
157+
sponsor: "cuHacking",
158158
challengeBlock: [
159159
{
160160
blockName: "Overall Project Details",
@@ -188,7 +188,7 @@ export async function seedChallenges(payload: Payload, req: any) {
188188
{
189189
pathTitle: "E:[email protected]",
190190
title: "Wolfram Award - Top 5 teams",
191-
symbol: "judges.png",
191+
sponsor: "Wolfram",
192192
challengeBlock: [
193193
{
194194
blockName: "Wolfram Award Details",
@@ -223,7 +223,7 @@ export async function seedChallenges(payload: Payload, req: any) {
223223
{
224224
pathTitle: "E:[email protected]",
225225
title: "Best Hardware Hack",
226-
symbol: "safaa.png",
226+
sponsor: "QNX",
227227
challengeBlock: [
228228
{
229229
blockName: "Hardware Hack Details",
@@ -253,7 +253,7 @@ export async function seedChallenges(payload: Payload, req: any) {
253253
{
254254
pathTitle: "E:[email protected]",
255255
title: "Gadget Challenge",
256-
symbol: "gadget-logo.png",
256+
sponsor: "Gadget",
257257
challengeBlock: [
258258
{
259259
blockName: "Gadget Challenge Details",
@@ -280,7 +280,7 @@ export async function seedChallenges(payload: Payload, req: any) {
280280
{
281281
pathTitle: "E:[email protected]",
282282
title: "Carleton Impact Challenge",
283-
symbol: "impact-logo.png",
283+
sponsor: "cuHacking",
284284
challengeBlock: [
285285
{
286286
blockName: "Impact Challenge Details",
@@ -305,7 +305,7 @@ export async function seedChallenges(payload: Payload, req: any) {
305305
{
306306
pathTitle: "E:[email protected]",
307307
title: "Best use of Figma",
308-
symbol: "figma-logo.png",
308+
sponsor: "cuHacking",
309309
challengeBlock: [
310310
{
311311
blockName: "Figma Challenge Details",
@@ -335,7 +335,7 @@ export async function seedChallenges(payload: Payload, req: any) {
335335
{
336336
pathTitle: "E:[email protected]",
337337
title: "Boopbot fan art",
338-
symbol: "boopbot-logo.png",
338+
sponsor: "cuHacking",
339339
challengeBlock: [
340340
{
341341
blockName: "Boopbot Fan Art Details",
@@ -365,7 +365,7 @@ export async function seedChallenges(payload: Payload, req: any) {
365365
{
366366
pathTitle: "E:[email protected]",
367367
title: "Marketing challenge",
368-
symbol: "organizers-logo.png",
368+
sponsor: "cuHacking",
369369
challengeBlock: [
370370
{
371371
blockName: "Marketing Challenge Details",
@@ -395,7 +395,7 @@ export async function seedChallenges(payload: Payload, req: any) {
395395
{
396396
pathTitle: "E:[email protected]",
397397
title: "Best Use of Gemini API",
398-
symbol: "mlh-logo.png",
398+
sponsor: "MLH",
399399
challengeBlock: [
400400
{
401401
blockName: "Gemini API Details",
@@ -420,7 +420,7 @@ export async function seedChallenges(payload: Payload, req: any) {
420420
{
421421
pathTitle: "E:[email protected]",
422422
title: "Best Use of Auth0",
423-
symbol: "mlh-logo.png",
423+
sponsor: "MLH",
424424
challengeBlock: [
425425
{
426426
blockName: "Auth0 Challenge Details",
@@ -445,7 +445,7 @@ export async function seedChallenges(payload: Payload, req: any) {
445445
{
446446
pathTitle: "E:[email protected]",
447447
title: "Best AI Application Built with Cloudflare",
448-
symbol: "mlh-logo.png",
448+
sponsor: "MLH",
449449
challengeBlock: [
450450
{
451451
blockName: "Cloudflare AI Details",
@@ -470,7 +470,7 @@ export async function seedChallenges(payload: Payload, req: any) {
470470
{
471471
pathTitle: "E:[email protected]",
472472
title: "Best Domain Name from GoDaddy Registry",
473-
symbol: "mlh-logo.png",
473+
sponsor: "MLH",
474474
challengeBlock: [
475475
{
476476
blockName: "Domain Name Details",
@@ -495,7 +495,7 @@ export async function seedChallenges(payload: Payload, req: any) {
495495
{
496496
pathTitle: "E:[email protected]",
497497
title: "People’s choice - Best overall project",
498-
symbol: "devpost-logo.png",
498+
sponsor: "cuHacking",
499499
challengeBlock: [
500500
{
501501
blockName: "People's Choice Details",
@@ -525,7 +525,7 @@ export async function seedChallenges(payload: Payload, req: any) {
525525
{
526526
pathTitle: "E:[email protected]",
527527
title: "Most Outrageous Hack/Turn Brainrot into brain nourishment",
528-
symbol: "organizers-logo.png",
528+
sponsor: "cuHacking",
529529
challengeBlock: [
530530
{
531531
blockName: "Outrageous Hack Details",
@@ -555,7 +555,7 @@ export async function seedChallenges(payload: Payload, req: any) {
555555
{
556556
pathTitle: "E:[email protected]",
557557
title: "Best School Crossover",
558-
symbol: "judges-logo.png",
558+
sponsor: "cuHacking",
559559
challengeBlock: [
560560
{
561561
blockName: "School Crossover Details",
@@ -585,7 +585,7 @@ export async function seedChallenges(payload: Payload, req: any) {
585585
{
586586
pathTitle: "E:[email protected]",
587587
title: "Best First Time Hack",
588-
symbol: "judges-logo.png",
588+
sponsor: "cuHacking",
589589
challengeBlock: [
590590
{
591591
blockName: "First Time Hack Details",
@@ -618,20 +618,20 @@ export async function seedChallenges(payload: Payload, req: any) {
618618

619619
].map(async (challenge) => {
620620
try {
621-
const existingMedia = await payload.find({
622-
collection: "media",
623-
where: { alt: { equals: challenge.symbol.alt } },
621+
const existingSponsor = await payload.find({
622+
collection: "brands",
623+
where: { name: { equals: challenge.sponsor } },
624624
pagination: false,
625625
});
626626

627-
const selectedImage =
628-
existingMedia.docs.length > 0 ? existingMedia.docs[0].id : null;
627+
const selectedSponsor =
628+
existingSponsor.docs.length > 0 ? existingSponsor.docs[0].id : null;
629629

630630
await payload.create({
631631
collection: "challenges",
632632
data: {
633633
pathTitle: challenge.pathTitle,
634-
symbol: selectedImage,
634+
sponsor: selectedSponsor,
635635
title: challenge.title,
636636
challengeBlock: challenge.challengeBlock
637637
},

0 commit comments

Comments
 (0)