Skip to content

Commit

Permalink
Add basic recent debates page
Browse files Browse the repository at this point in the history
  • Loading branch information
limdingwen committed Jul 28, 2024
1 parent 6adbb44 commit 2e82891
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 7 deletions.
61 changes: 61 additions & 0 deletions site/src/app/components/ShortDebate.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import { Group, Stack } from "@mantine/core";
import StandardCardTitle from "@/app/components/StandardCardTitle";
import moment from "moment";
import StandardCardDescription from "@/app/components/StandardCardDescription";
import Markdown from "react-markdown";
import SummaryAiDisclaimer from "@/app/components/SummaryAiDisclaimer";
import SummaryNotAvailableApology from "@/app/components/SummaryNotAvailableApology";
import StandardButton from "@/app/components/StandardButton";
import StandardCard from "@/app/components/StandardCard";

export default function ShortDebate({
debate,
}: {
debate: {
id: number;
title: string;
summary: string | null;
sitting: {
sitting_date: {
sitting_date: string;
} | null;
} | null;
};
}) {
return (
<StandardCard>
<Group justify="space-between">
<StandardCardTitle>{debate.title}</StandardCardTitle>
</Group>

<StandardCardDescription>
{moment(debate.sitting!.sitting_date!.sitting_date).format(
"D MMM YYYY",
)}
</StandardCardDescription>

<StandardCardDescription>
{debate.summary ? (
<Stack>
<Markdown>{debate.summary}</Markdown>
<SummaryAiDisclaimer />
</Stack>
) : (
<SummaryNotAvailableApology />
)}
</StandardCardDescription>

<Group grow mt="md">
<StandardButton colour="blue" href={`/debates/${debate.id}`}>
Overview
</StandardButton>
<StandardButton
colour="gray"
href={`https://sprs.parl.gov.sg/search/#/fullreport?sittingdate=${moment(debate.sitting!.sitting_date!.sitting_date).format("DD-MM-YYYY")}`}
>
Original source
</StandardButton>
</Group>
</StandardCard>
);
}
2 changes: 1 addition & 1 deletion site/src/app/components/SummaryAiDisclaimer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export default function SummaryAiDisclaimer() {
return (
<AiDisclaimer
shortExplainer="Summary written by AI"
explainer="This summary was written by a cute little robot, but it may not be fully accurate. Please read the original PDF for the most accurate information. Hopefully, this summary helps you get the gist of it!"
explainer="This summary was written by a cute little robot, but it may not be fully accurate. Please read the original source for the most accurate information. Hopefully, this summary helps you get the gist of it!"
></AiDisclaimer>
);
}
17 changes: 11 additions & 6 deletions site/src/app/debates/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import StandardCardTitle from "@/app/components/StandardCardTitle";
import StandardCardDescription from "@/app/components/StandardCardDescription";
import StandardButton from "@/app/components/StandardButton";
import { Group } from "@mantine/core";
import ShortDebate from "@/app/components/ShortDebate";

export const runtime = "edge";

Expand All @@ -33,9 +34,16 @@ function calculatePaginationOffset(page: number) {
async function getRecentDebates(page: number) {
const supabase = createClient();
const [first, last] = calculatePaginationOffset(page);
const { error, data } = await supabase
const { data, error } = await supabase
.from("debate")
.select("title")
.select(
"id, title, order_no, summary, sitting ( sitting_date ( sitting_date ) )",
)
.order("sitting_date", {
ascending: false,
referencedTable: "sitting.sitting_date",
})
.order("order_no", { ascending: false })
.range(first, last);
if (error) throw error;
return data;
Expand Down Expand Up @@ -67,10 +75,7 @@ export default async function RecentDebates({
<PageTitle title={title} subtitle={subtitle} />

{(await getRecentDebates(page)).map((debate) => (
<StandardCard>
<StandardCardTitle>{debate.title}</StandardCardTitle>
<StandardCardDescription>Hello world</StandardCardDescription>
</StandardCard>
<ShortDebate key={debate.id} debate={debate} />
))}

{isLastPage && (
Expand Down

0 comments on commit 2e82891

Please sign in to comment.