Skip to content

Commit

Permalink
Add bill to second debate button
Browse files Browse the repository at this point in the history
  • Loading branch information
limdingwen committed Aug 6, 2024
1 parent c2dd3b6 commit efb6344
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 6 deletions.
4 changes: 2 additions & 2 deletions site/src/app/bills/[year]/[billNoOfYear]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ async function getBill(billNo: string) {
const { error, data } = await supabase
.from("bill")
.select(
"bill_no, name, summary, pdf_url, date_introduced, second_reading_date_type, second_reading_date, is_passed, passed_date",
"id, bill_no, name, summary, pdf_url, date_introduced, second_reading_date_type, second_reading_date, is_passed, passed_date",
)
.eq("bill_no", billNo)
.single();
Expand All @@ -49,7 +49,7 @@ async function getBill(billNo: string) {
export default async function FullBill({
params,
}: {
params: { year: string; billNoOfYear: string };
params: { id: number; year: string; billNoOfYear: string };
}) {
const bill = await getBill(
buildBillNoFromBillPath(params.year, params.billNoOfYear),
Expand Down
2 changes: 1 addition & 1 deletion site/src/app/bills/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ async function getRecentBills(page: number) {
const { error, data } = await supabase
.from("bill")
.select(
"bill_no, name, second_reading_date_type, second_reading_date, is_passed, passed_date, summary, pdf_url",
"id, bill_no, name, second_reading_date_type, second_reading_date, is_passed, passed_date, summary, pdf_url",
)
.order("date_introduced", { ascending: false })
.order("bill_no", { ascending: false })
Expand Down
38 changes: 38 additions & 0 deletions site/src/app/components/BillDebateButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import StandardButton from "@/app/components/StandardButton";
import { createClient } from "@/utils/supabase/server";

async function getSecondDebate(billId: number) {
const supabase = createClient();
const { data, error } = await supabase
.from("debate_bill_match_view")
.select("debate_id")
.eq("bill_id", billId)
.eq("is_second_reading", true)
// If there's multiple second readings detected, just ignore it for now...
.limit(1)
.maybeSingle();
if (error) throw error;
return data ? data.debate_id : null;
}

async function getSecondDebateUrl(billId: number) {
const debateId = await getSecondDebate(billId);
return debateId ? `/debates/${debateId}` : null;
}

export default async function BillDebateButton({
bill,
}: {
bill: { id: number };
}) {
const secondDebateUrl = await getSecondDebateUrl(bill.id);
return secondDebateUrl ? (
<StandardButton colour="gray" href={secondDebateUrl}>
Debate
</StandardButton>
) : (
<StandardButton colour="gray" href="#" disabled>
Debate
</StandardButton>
);
}
9 changes: 7 additions & 2 deletions site/src/app/components/BillSummary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ import SummaryAiDisclaimer from "@/app/components/SummaryAiDisclaimer";
import BillOriginalPdfButton from "@/app/components/BillOriginalPdfButton";
import SummaryNotAvailableApology from "@/app/components/SummaryNotAvailableApology";
import React from "react";
import BillDebateButton from "@/app/components/BillDebateButton";

export default function BillSummary({
bill,
}: {
bill: { summary: string | null; pdf_url: string };
bill: { id: number; summary: string | null; pdf_url: string };
}) {
return (
<StandardCard>
Expand All @@ -23,13 +24,17 @@ export default function BillSummary({
<Markdown>{bill.summary}</Markdown>
<Group justify="space-between">
<SummaryAiDisclaimer />
<BillOriginalPdfButton bill={bill} />
<Group>
<BillOriginalPdfButton bill={bill} />
<BillDebateButton bill={bill} />
</Group>
</Group>
</Stack>
) : (
<Group justify="space-between">
<SummaryNotAvailableApology />
<BillOriginalPdfButton bill={bill} />
<BillDebateButton bill={bill} />
</Group>
)}
</StandardCardDescription>
Expand Down
3 changes: 3 additions & 0 deletions site/src/app/components/ShortBill.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import SummaryNotAvailableApology from "@/app/components/SummaryNotAvailableApol
import StandardButton from "@/app/components/StandardButton";
import BillOriginalPdfButton from "@/app/components/BillOriginalPdfButton";
import StandardMarkdown from "./StandardMarkdown";
import BillDebateButton from "@/app/components/BillDebateButton";

function flipBillNo(billNo: string) {
const [billOfYear, year] = billNo.split("/");
Expand All @@ -17,6 +18,7 @@ export default async function ShortBill({
bill,
}: {
bill: {
id: number;
bill_no: string;
name: string;
second_reading_date_type: string;
Expand Down Expand Up @@ -69,6 +71,7 @@ export default async function ShortBill({
Overview
</StandardButton>
<BillOriginalPdfButton bill={bill} />
<BillDebateButton bill={bill} />
</Group>
</StandardCard>
);
Expand Down
10 changes: 9 additions & 1 deletion site/src/app/components/StandardButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,21 @@ export default function StandardButton({
colour,
href,
children,
disabled = false,
}: {
colour: string;
href: string;
children: React.ReactNode;
disabled?: boolean;
}) {
return (
<Button color={colour} radius="md" component={Link} href={href}>
<Button
disabled={disabled}
color={colour}
radius="md"
component={Link}
href={href}
>
{children}
</Button>
);
Expand Down

0 comments on commit efb6344

Please sign in to comment.