Skip to content

Commit

Permalink
Revert "Implement caching mechanism for portal (#988)"
Browse files Browse the repository at this point in the history
This reverts commit ee26190.
  • Loading branch information
johnmeshulam committed Feb 8, 2025
1 parent ee26190 commit 55ff1c4
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 109 deletions.
18 changes: 5 additions & 13 deletions apps/portal/pages/events/[id]/awards.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useRef, useEffect, useState } from 'react';
import { GetStaticPaths, GetStaticProps, GetStaticPropsContext, NextPage } from 'next';
import { Container, Box, Typography } from '@mui/material';
import { GetServerSideProps, GetServerSidePropsContext, NextPage } from 'next';
import { Container, Box, Typography, Stack } from '@mui/material';
import { AwardNames, PortalAward, PortalEvent } from '@lems/types';
import { localizedAward } from '@lems/season';
import { fetchAwards, fetchEvent } from '../../../lib/api';
Expand Down Expand Up @@ -91,21 +91,13 @@ const Page: NextPage<Props> = ({ awards, event }) => {
);
};

export const getStaticProps: GetStaticProps = async ({ params }: GetStaticPropsContext) => {
const eventId = params?.id as string;
export const getServerSideProps: GetServerSideProps = async (ctx: GetServerSidePropsContext) => {
const eventId = ctx.params?.id as string;
const { event } = await fetchEvent(eventId);
const awards = await fetchAwards(eventId);
if (awards === null) return { redirect: { destination: `/events/${eventId}`, permanent: false } };

return {
props: { awards, event },
revalidate: 10 * 60 // 10 minutes
};
return { props: { awards, event } };
};

export const getStaticPaths: GetStaticPaths = async () => {
// We don't know the events at build time, Next.js will generate the pages at runtime.
return { paths: [], fallback: 'blocking' };
}

export default Page;
16 changes: 4 additions & 12 deletions apps/portal/pages/events/[id]/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { NextPage, GetStaticProps, GetStaticPropsContext, GetStaticPaths } from 'next';
import { NextPage, GetServerSideProps, GetServerSidePropsContext } from 'next';
import { Box, Container, Stack, Typography } from '@mui/material';
import { PortalEvent, PortalTeam, PortalEventStatus } from '@lems/types';
import { fetchAwards, fetchEvent } from '../../../lib/api';
Expand Down Expand Up @@ -43,19 +43,11 @@ const Page: NextPage<Props> = ({ event, teams, hasAwards }) => {
);
};

export const getStaticProps: GetStaticProps = async ({ params }: GetStaticPropsContext) => {
const eventId = params?.id as string;
export const getServerSideProps: GetServerSideProps = async (ctx: GetServerSidePropsContext) => {
const eventId = ctx.params?.id as string;
const { event, teams } = await fetchEvent(eventId);
const awards = await fetchAwards(eventId);
return {
props: { event, teams, hasAwards: !!awards },
revalidate: 10 * 60 // 10 mintues
};
return { props: { event, teams, hasAwards: !!awards } };
};

export const getStaticPaths: GetStaticPaths = async () => {
// We don't know the events at build time, Next.js will generate the pages at runtime.
return { paths: [], fallback: 'blocking' };
}

export default Page;
16 changes: 4 additions & 12 deletions apps/portal/pages/events/[id]/schedule/field.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { GetStaticPaths, GetStaticProps, GetStaticPropsContext, NextPage } from 'next';
import { GetServerSideProps, GetServerSidePropsContext, NextPage } from 'next';
import dayjs from 'dayjs';
import {
TableContainer,
Expand Down Expand Up @@ -115,19 +115,11 @@ const Page: NextPage<Props> = ({ event }) => {
);
};

export const getStaticProps: GetStaticProps = async ({ params }: GetStaticPropsContext) => {
const eventId = params?.id as string;
export const getServerSideProps: GetServerSideProps = async (ctx: GetServerSidePropsContext) => {
const eventId = ctx.params?.id as string;

const { event } = await fetchEvent(eventId);
return {
props: { event },
revalidate: 10 * 60 // 10 minutes
};
return { props: { event } };
};

export const getStaticPaths: GetStaticPaths = async () => {
// We don't know the events at build time, Next.js will generate the pages at runtime.
return { paths: [], fallback: 'blocking' };
}

export default Page;
18 changes: 5 additions & 13 deletions apps/portal/pages/events/[id]/schedule/general.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { GetStaticPaths, GetStaticProps, GetStaticPropsContext, NextPage } from 'next';
import { GetServerSideProps, GetServerSidePropsContext, NextPage } from 'next';
import dayjs from 'dayjs';
import { Typography, Container, Stack, Divider, Paper } from '@mui/material';
import { PortalActivity, PortalEvent } from '@lems/types';
import { PortalActivity, PortalEvent, RobotGameMatchStage } from '@lems/types';
import { fetchEvent, fetchGeneralSchedule } from '../../../../lib/api';
import StyledEventSubtitle from '../../../../components/events/styled-event-subtitle';

Expand Down Expand Up @@ -36,20 +36,12 @@ const Page: NextPage<Props> = ({ event, schedule }) => {
);
};

export const getStaticProps: GetStaticProps = async ({ params }: GetStaticPropsContext) => {
const eventId = params?.id as string;
export const getServerSideProps: GetServerSideProps = async (ctx: GetServerSidePropsContext) => {
const eventId = ctx.params?.id as string;

const { event } = await fetchEvent(eventId);
const schedule = await fetchGeneralSchedule(eventId);
return {
props: { event, schedule },
revalidate: 10 * 60 // 10 minutes
};
return { props: { event, schedule } };
};

export const getStaticPaths: GetStaticPaths = async () => {
// We don't know the events at build time, Next.js will generate the pages at runtime.
return { paths: [], fallback: 'blocking' };
}

export default Page;
16 changes: 4 additions & 12 deletions apps/portal/pages/events/[id]/schedule/judging.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { GetStaticPaths, GetStaticProps, GetStaticPropsContext, NextPage } from 'next';
import { GetServerSideProps, GetServerSidePropsContext, NextPage } from 'next';
import dayjs from 'dayjs';
import {
TableContainer,
Expand Down Expand Up @@ -99,19 +99,11 @@ const Page: NextPage<Props> = ({ event }) => {
);
};

export const getStaticProps: GetStaticProps = async ({ params }: GetStaticPropsContext) => {
const eventId = params?.id as string;
export const getServerSideProps: GetServerSideProps = async (ctx: GetServerSidePropsContext) => {
const eventId = ctx.params?.id as string;

const { event } = await fetchEvent(eventId);
return {
props: { event },
revalidate: 10 * 60 // 10 minutes
};
return { props: { event } };
};

export const getStaticPaths: GetStaticPaths = async () => {
// We don't know the events at build time, Next.js will generate the pages at runtime.
return { paths: [], fallback: 'blocking' };
}

export default Page;
16 changes: 4 additions & 12 deletions apps/portal/pages/events/[id]/scoreboard.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useRef, useEffect, useState } from 'react';
import { NextPage, GetStaticProps, GetStaticPropsContext, GetStaticPaths } from 'next';
import { NextPage, GetServerSideProps, GetServerSidePropsContext } from 'next';
import { Container, Typography, Box, Stack } from '@mui/material';
import { PortalScore, PortalEvent, PortalEventStatus } from '@lems/types';
import { fetchEvent } from '../../../lib/api';
Expand Down Expand Up @@ -83,18 +83,10 @@ const Page: NextPage<Props> = ({ event }) => {
);
};

export const getStaticProps: GetStaticProps = async ({ params }: GetStaticPropsContext) => {
const eventId = params?.id as string;
export const getServerSideProps: GetServerSideProps = async (ctx: GetServerSidePropsContext) => {
const eventId = ctx.params?.id as string;
const { event } = await fetchEvent(eventId);
return {
props: { event },
revalidate: 10 * 60 // 10 minutes
};
return { props: { event } };
};

export const getStaticPaths: GetStaticPaths = async () => {
// We don't know the events at build time, Next.js will generate the pages at runtime.
return { paths: [], fallback: 'blocking' };
}

export default Page;
13 changes: 4 additions & 9 deletions apps/portal/pages/events/[id]/teams/[number].tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { NextPage, GetStaticProps, GetStaticPropsContext, GetStaticPaths } from 'next';
import { NextPage, GetServerSideProps, GetServerSidePropsContext } from 'next';
import { Container } from '@mui/material';
import Grid from '@mui/material/Grid2';
import {
Expand Down Expand Up @@ -70,18 +70,13 @@ const Page: NextPage<Props> = ({ team, event, awards }) => {
);
};

export const getStaticProps: GetStaticProps = async ({ params }: GetStaticPropsContext) => {
const eventId = params?.id as string;
const teamNumber = params?.number as string;
export const getServerSideProps: GetServerSideProps = async (ctx: GetServerSidePropsContext) => {
const eventId = ctx.params?.id as string;
const teamNumber = ctx.params?.number as string;

const { team, awards } = await fetchTeam(eventId, teamNumber);
const { event } = await fetchEvent(eventId);
return { props: { team, awards, event } };
};

export const getStaticPaths: GetStaticPaths = async () => {
// We don't know the events at build time, Next.js will generate the pages at runtime.
return { paths: [], fallback: 'blocking' };
}

export default Page;
17 changes: 4 additions & 13 deletions apps/portal/pages/events/index.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { useMemo } from 'react';
import dayjs from 'dayjs';
import { NextPage, GetStaticProps } from 'next';
import { NextPage, GetServerSideProps } from 'next';
import { Container, Typography, Stack, Paper, List, ListItem, ListItemButton } from '@mui/material';
import Grid from '@mui/material/Grid2';
import { PortalEvent } from '@lems/types';
import { fetchEvents } from '../../lib/api';
import EventList from '../../components/events/event-list';
import { PHASE_PRODUCTION_BUILD } from 'next/dist/shared/lib/constants';

interface Props {
events: Array<PortalEvent>;
Expand Down Expand Up @@ -107,17 +106,9 @@ const Page: NextPage<Props> = ({ events }) => {
);
};

export const getStaticProps: GetStaticProps = async () => {
let events: PortalEvent[] = []
// We cannot reach the backend while initial build
if (process.env.NEXT_PHASE !== PHASE_PRODUCTION_BUILD) {
events = await fetchEvents();
}

return {
props: { events },
revalidate: 10 * 60 // 10 minutes
};
export const getServerSideProps: GetServerSideProps = async () => {
const events = await fetchEvents();
return { props: { events } };
};

export default Page;
17 changes: 4 additions & 13 deletions apps/portal/pages/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { NextPage, GetStaticProps } from 'next';
import { NextPage, GetServerSideProps } from 'next';
import Link from 'next/link';
import dayjs from 'dayjs';
import Image from 'next/image';
Expand All @@ -7,7 +7,6 @@ import { PortalEvent } from '@lems/types';
import { fetchEvents } from '../lib/api';
import EventList from '../components/events/event-list';
import LiveIcon from '../components/live-icon';
import { PHASE_PRODUCTION_BUILD } from 'next/dist/shared/lib/constants';

interface Props {
events: Array<PortalEvent>;
Expand Down Expand Up @@ -72,17 +71,9 @@ const Page: NextPage<Props> = ({ events }) => {
);
};

export const getStaticProps: GetStaticProps = async () => {
let events: PortalEvent[] = []
// We cannot reach the backend while initial build
if (process.env.NEXT_PHASE !== PHASE_PRODUCTION_BUILD) {
events = await fetchEvents();
}

return {
props: { events },
revalidate: 10 * 60 // 10 minutes
};
export const getServerSideProps: GetServerSideProps = async () => {
const events = await fetchEvents();
return { props: { events } };
};

export default Page;

0 comments on commit 55ff1c4

Please sign in to comment.