Skip to content

Commit

Permalink
fix: Exhibitor single page error
Browse files Browse the repository at this point in the history
  • Loading branch information
hampfh committed Mar 10, 2024
1 parent f1bf2c8 commit e3e14bf
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
4 changes: 3 additions & 1 deletion src/app/student/exhibitors/[exhibitor]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ interface RouteProps {
// This tells Next about all the companies that it should
// prerender, these will be compiled at build time
export async function generateStaticParams() {
const years = await fetchAllYearExhibitors()
const years = await fetchAllYearExhibitors({
cache: "force-cache"
})
const exhibitors = years.flatMap(x => x.exhibitors)

return exhibitors.map(exhibitor => ({
Expand Down
16 changes: 11 additions & 5 deletions src/components/shared/hooks/api/useExhibitors.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,16 @@ export interface Group {

const defaultYear = DateTime.now().minus({ months: 6 }).year

export async function fetchExhibitors(options?: { year?: number }) {
export async function fetchExhibitors(
options?: RequestInit & { year?: number }
) {
const res = await fetch(
`${env.NEXT_PUBLIC_API_URL}/api/exhibitors?year=${options?.year ?? defaultYear}`,
{
cache: "no-cache",
cache: options?.cache ?? "no-cache",
next: {
tags: [
...options?.next,
tags: options?.next?.tags ?? [
"exhibitors",
options?.year?.toString() ?? defaultYear.toString()
]
Expand All @@ -75,13 +78,16 @@ export async function fetchExhibitors(options?: { year?: number }) {
* this is ok since this is statically compiled in
* next. This should NOT be called in a client component
*/
export async function fetchAllYearExhibitors() {
export async function fetchAllYearExhibitors(options?: RequestInit) {
const exhibitorYears = await Promise.allSettled(
new Array(DateTime.now().year - 2021).fill(0).map(async (_, i) => {
const year = DateTime.now().year - i
return {
year: year.toString(),
exhibitors: await fetchExhibitors({ year })
exhibitors: await fetchExhibitors({
...options,
year
})
}
})
)
Expand Down

0 comments on commit e3e14bf

Please sign in to comment.