-
-
Notifications
You must be signed in to change notification settings - Fork 33
Aashna/challenge schedule map qr routes #361
Changes from 10 commits
6d7db91
f8365ef
7d2e6c4
6eaf417
9530047
b10b54a
a1a98d6
18d0009
affd4a3
c7035d8
29f7f08
40fae61
05e0f93
f9a1d11
f44aa08
9f138a7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| import type { LoaderFunction } from '@remix-run/node' | ||
| import process from 'node:process' | ||
| import { ChallengesPage } from '@cuhacking/portal/pages/challenges' | ||
| import { useLoaderData } from '@remix-run/react' | ||
|
|
||
| export const loader: LoaderFunction = async () => { | ||
| try { | ||
| const API_URL = process.env.NODE_ENV === 'development' ? 'http://localhost:8000' : 'https://axiom.cuhacking.ca' | ||
| const req = await fetch(`${API_URL}/api/challenges`) | ||
coderabbitai[bot] marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| if (!req.ok) { | ||
| throw new Error('Error') | ||
coderabbitai[bot] marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| const data = await req.json() | ||
|
|
||
| return data.docs | ||
| } | ||
| catch (error) { | ||
| console.error(`Error fetching challenges`, error) | ||
| return [{ title: '', pathTitle: '', sponsor: { symbol: { url: '', alt: '' } }, challengeBlock: [] }] | ||
| } | ||
| } | ||
|
|
||
| export default function Challenges() { | ||
| const data = useLoaderData<typeof loader>() | ||
|
|
||
| return ( | ||
| <ChallengesPage data={data} /> | ||
| ) | ||
| } | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,29 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import type { LoaderFunction } from '@remix-run/node' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import process from 'node:process' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { MapsPage } from '@cuhacking/portal/pages/map' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export const loader: LoaderFunction = async () => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const API_URL = process.env.NODE_ENV === 'development' ? 'http://localhost:8000' : 'https://axiom.cuhacking.ca' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const req = await fetch(`${API_URL}/api/challenges`) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (!req.ok) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| throw new Error('Error') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const data = await req.json() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return data.docs | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| catch (error) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| console.error(`Error fetching challenges`, error) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+5
to
+21
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix missing return value in catch block and API endpoint inconsistency. The loader function has several issues:
Apply these fixes to prevent runtime errors and improve error handling: export const loader: LoaderFunction = async () => {
try {
const API_URL = process.env.NODE_ENV === 'development' ? 'http://localhost:8000' : 'https://axiom.cuhacking.ca'
- const req = await fetch(`${API_URL}/api/challenges`)
+ const req = await fetch(`${API_URL}/api/maps`)
if (!req.ok) {
- throw new Error('Error')
+ throw new Error(`Failed to fetch maps: ${req.status} ${req.statusText}`)
}
const data = await req.json()
return data.docs
}
catch (error) {
- console.error(`Error fetching challenges`, error)
+ console.error(`Error fetching maps`, error)
+ return [] // Return empty array as fallback
}
}📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export default function Map() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // const data = useLoaderData<typeof loader>() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick (assertive) Unused loader data The loader fetches challenge data but it's not being used in the component. Either uncomment this line if the data is needed or consider simplifying the loader if the data isn't required. If the map component doesn't need challenge data, consider removing the fetch or implementing a separate loader that fetches map-specific data. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <MapsPage /> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+23
to
+29
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Rename component to avoid shadowing global Map object The component name -export default function Map() {
+export default function MapRoute() {
// const data = useLoaderData<typeof loader>()
return (
<MapsPage />
)
}📝 Committable suggestion
Suggested change
🧰 Tools🪛 Biome (1.9.4)[error] 23-23: Do not shadow the global "Map" property. Consider renaming this variable. It's easy to confuse the origin of variables when they're named after a known global. (lint/suspicious/noShadowRestrictedNames) |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,50 @@ | ||||||||||||||||||||||||
| import type { UserDetails } from '@cuhacking/portal/types/user' | ||||||||||||||||||||||||
| import type { LoaderFunction } from '@remix-run/node' | ||||||||||||||||||||||||
| import process from 'node:process' | ||||||||||||||||||||||||
| import { QrPage } from '@cuhacking/portal/pages/qr' | ||||||||||||||||||||||||
| import { redirect } from '@remix-run/node' | ||||||||||||||||||||||||
| import { useLoaderData } from '@remix-run/react' | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| export const loader: LoaderFunction = async ({ request }) => { | ||||||||||||||||||||||||
| const cookie = request.headers.get('Cookie') | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| const baseUrl | ||||||||||||||||||||||||
| = process.env.NODE_ENV === 'development' | ||||||||||||||||||||||||
| ? 'http://localhost:8000' | ||||||||||||||||||||||||
| : 'https://axiom.cuhacking.ca' | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| const API_URL = baseUrl | ||||||||||||||||||||||||
|
Comment on lines
+11
to
+16
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick (assertive) Fix indentation in API_URL definition The baseUrl variable definition has inconsistent indentation. Standardize the formatting. - const baseUrl
- = process.env.NODE_ENV === 'development'
- ? 'http://localhost:8000'
- : 'https://axiom.cuhacking.ca'
+ const baseUrl = process.env.NODE_ENV === 'development'
+ ? 'http://localhost:8000'
+ : 'https://axiom.cuhacking.ca'📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||
| const res = await fetch(`${API_URL}/api/users/me`, { | ||||||||||||||||||||||||
| credentials: 'include', | ||||||||||||||||||||||||
| headers: { Cookie: cookie || '' }, | ||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| if (!res.ok) { | ||||||||||||||||||||||||
| throw new Error('Not Authenticated') | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| const { user } = await res.json() | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| if (!user) { | ||||||||||||||||||||||||
| return redirect('/') | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| if (!user.agreedToTerms) { | ||||||||||||||||||||||||
| return redirect('/') | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| return { user, cookie, API_URL } | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
| catch { | ||||||||||||||||||||||||
| return redirect('/') | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
Comment on lines
+39
to
+41
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick (assertive) Improve error handling with specific error logging The catch block should log the error for easier debugging, like in the challenges.tsx route. - catch {
+ catch (error) {
+ console.error('Authentication error:', error)
return redirect('/')
}📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
Comment on lines
+8
to
+42
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick (assertive) Consider extracting loader logic to a shared utility. |
||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| export default function QR() { | ||||||||||||||||||||||||
| const { user } = useLoaderData< { user: UserDetails, cookie: string }>() | ||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick (assertive) Fix type annotation spacing Remove the space after the opening angle bracket in the useLoaderData type annotation. - const { user } = useLoaderData< { user: UserDetails, cookie: string }>()
+ const { user } = useLoaderData<{ user: UserDetails, cookie: string }>()📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| return ( | ||||||||||||||||||||||||
| <QrPage user={user} /> | ||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| import type { LoaderFunction } from '@remix-run/node' | ||
| import process from 'node:process' | ||
| import { SchedulePage } from '@cuhacking/portal/pages/schedule' | ||
| import { useLoaderData } from '@remix-run/react' | ||
|
|
||
| export const loader: LoaderFunction = async () => { | ||
| try { | ||
| const API_URL | ||
| = process.env.NODE_ENV === 'development' | ||
| ? 'http://localhost:8000' | ||
| : 'https://axiom.cuhacking.ca' | ||
|
|
||
| let allEvents: any[] = [] | ||
| let page = 1 | ||
| let hasNextPage = true | ||
|
|
||
| while (hasNextPage) { | ||
| const req = await fetch(`${API_URL}/api/events?page=${page}&limit=100`) | ||
|
|
||
| if (!req.ok) { | ||
| throw new Response('Error fetching events', { status: req.status }) | ||
| } | ||
|
|
||
| const data = await req.json() | ||
| allEvents = [...allEvents, ...data.docs] | ||
| hasNextPage = data.hasNextPage | ||
| page = data.nextPage | ||
| } | ||
|
|
||
| return allEvents | ||
| } | ||
| catch (error) { | ||
| console.error(`Error fetching events`, error) | ||
| throw new Response('Internal Server Error', { status: 500 }) | ||
| } | ||
| } | ||
|
|
||
| export default function Schedule() { | ||
| const data = useLoaderData<typeof loader>() | ||
|
|
||
| return <SchedulePage data={data} /> | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Verification agent
🧩 Analysis chain
Key rename from
challengePrizetochallenges.This change aligns with the broader terminology standardization across the PR. Ensure all references to this key have been updated accordingly.
🏁 Script executed:
Length of output: 68
Action: Verify Key Renaming Across the Codebase
The key in
apps/axiom/src/components/Nav/navIconMap.tshas been renamed tochallenges: Trophy,to align with our broader terminology standardization. However, the original verification command encountered an issue with tsx file type recognition. Please re-run the above command manually and confirm that no remaining references tochallengePrizeexist.🏁 Script executed:
Length of output: 530
Attention: Incomplete Key Renaming for "challengePrize"
The change in
apps/axiom/src/components/Nav/navIconMap.tscorrectly updates the key tochallenges: Trophy,aligning with our standardized terminology. However, the search revealed lingering references tochallengePrizeinlibs/db/payload-types.ts, including:challengePrize: ChallengePrize;challengePrize: ChallengePrizeSelect<false> | ChallengePrizeSelect<true>;challengePrize.Please review whether these instances should also be updated for consistency across the application. If they need renaming, ensure the changes are applied to the database payload typings as well. If these references are intentionally maintained for backward compatibility or other reasons, kindly add documentation explaining the rationale.