-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix an ESlint TS error in inconv way
- Loading branch information
Showing
5 changed files
with
135 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,59 @@ | ||
import Link from 'next/link'; | ||
import { getEventsInsecure } from '../../database/events'; | ||
|
||
export const metadata = { | ||
title: 'Upcoming Events', | ||
description: 'Upcoming events around the city', | ||
}; | ||
|
||
export default function EventsPage() { | ||
return <h1>Upcoming Events</h1>; | ||
function formatDuration(duration: number | null): string { | ||
if (duration === null) { | ||
return 'N/A'; | ||
} | ||
const hours = Math.floor(duration / 60); | ||
const minutes = duration % 60; | ||
return `${hours}h ${minutes}m`; | ||
} | ||
|
||
export default async function EventsPage() { | ||
const events = await getEventsInsecure(); | ||
return ( | ||
<div> | ||
<h1>These Are Our Currently Available Products</h1> | ||
<div> | ||
<br /> | ||
{events.map((event) => { | ||
return ( | ||
<div key={`events-${event.id}`}> | ||
<div> | ||
{event.name} | ||
<br /> | ||
{event.type} | ||
<br /> | ||
{event.date.toLocaleDateString()} | ||
<br /> | ||
{event.location} | ||
<br /> | ||
{formatDuration(event.duration)} | ||
<br /> | ||
{event.image} | ||
<br /> | ||
{event.category} | ||
<br /> | ||
|
||
<br /> | ||
</div> | ||
<br /> | ||
<br /> | ||
</div> | ||
); | ||
})} | ||
<br /> | ||
</div> | ||
<br /> | ||
<div> | ||
<Link href="/">Back to Home page</Link> | ||
</div> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,60 @@ | ||
export type Event = { | ||
id: number; | ||
user_id: number; | ||
name: string; | ||
type: string; | ||
date: Date; | ||
location: string; | ||
duration: number | null; | ||
entry_fee: number | null; | ||
category: string; | ||
description: string; | ||
image: string; | ||
organizer_url: string; | ||
age_restriction: boolean | null; | ||
archived: boolean | null; | ||
}; | ||
import { cache } from 'react'; | ||
import { sql } from './connect'; | ||
|
||
export const getEventsInsecure = cache(async () => { | ||
const events = await sql< | ||
{ | ||
id: number; | ||
userId: number; | ||
name: string; | ||
type: string; | ||
date: Date; | ||
location: string; | ||
duration: number | null; | ||
entryFee: number | null; | ||
category: string; | ||
description: string; | ||
image: string; | ||
organizerUrl: string; | ||
ageRestriction: boolean | null; | ||
archived: boolean; | ||
}[] | ||
>` | ||
SELECT | ||
* | ||
FROM | ||
events | ||
`; | ||
|
||
return events; | ||
}); | ||
|
||
export const getEventInsecure = cache(async (id: number) => { | ||
const [event] = await sql< | ||
{ | ||
id: number; | ||
userId: number; | ||
name: string; | ||
type: string; | ||
date: Date; | ||
location: string; | ||
duration: number | null; | ||
entryFee: number | null; | ||
category: string; | ||
description: string; | ||
image: string; | ||
organizerUrl: string; | ||
ageRestriction: boolean | null; | ||
archived: boolean; | ||
}[] | ||
>` | ||
SELECT | ||
* | ||
FROM | ||
events | ||
WHERE | ||
id = ${id} | ||
`; | ||
|
||
return event; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters