-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: link sheet data in individual bill page
- Loading branch information
Showing
6 changed files
with
65 additions
and
175 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,19 +1,25 @@ | ||
<script lang="ts"> | ||
import type { Politician } from '$models/politician'; | ||
export let party: string; | ||
export let politicians: Politician[]; | ||
export let name: string; | ||
export let politicians: (Politician | string)[]; | ||
$: party = | ||
typeof politicians[0] === 'object' | ||
? politicians[0].partyRoles.find((e) => !e.endedAt)?.party | ||
: undefined; | ||
</script> | ||
|
||
<div class="flex gap-2"> | ||
<div | ||
class="flex items-center justify-center overflow-hidden rounded-full border border-gray-30" | ||
style="width: 24px; height: 24px;" | ||
> | ||
<img src={politicians[0].partyRoles.find((e) => !e.endedAt)?.party.logo} alt="" /> | ||
<img src={party?.logo || '/images/politicians/_placeholder.webp'} alt="" /> | ||
</div> | ||
<div class="flex"> | ||
<p class="underline">พรรค{party}</p> | ||
<!-- TODO: link to party when implemented --> | ||
<p>{party ? 'พรรค' : ''}{name}</p> | ||
<p class="body-02 ml-1 text-text-02">{politicians.length} คน</p> | ||
</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
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,150 +1,22 @@ | ||
import type { RelatedVotingResults } from '$components/bills/Progress.svelte'; | ||
import { fetchVotings } from '$lib/datasheets/index'; | ||
import { fetchFromIdOr404, fetchBills } from '$lib/datasheets'; | ||
import { createSeo } from '$lib/seo'; | ||
import { BillStatus, type Bill } from '$models/bill'; | ||
import type { Bill } from '$models/bill'; | ||
import type { BillEvent } from '$models/bill-event'; | ||
import { inProgressBill, enactedBill } from '../../../mocks/data/bill'; | ||
import { | ||
enforcementEvent, | ||
failingMp3Event, | ||
hearingEvent, | ||
inProgressMp2Event, | ||
passingMergedMp2Event, | ||
passingMp1Event, | ||
passingMp2Event, | ||
passingMp3Event, | ||
passingSenate1Event, | ||
passingSenate2Event, | ||
passingSenate3Event, | ||
royalAssentEvent | ||
} from '../../../mocks/data/event'; | ||
|
||
export interface VotingResultSummary { | ||
agreed: number; | ||
total: number; | ||
subResults?: { | ||
affiliationName: string; | ||
agreed: number; | ||
total: number; | ||
}[]; | ||
} | ||
|
||
export async function load({ params }) { | ||
/* | ||
* | billId | Status | | ||
* | ------ | ----------- | | ||
* | 1 | InProgress | | ||
* | 2 | Success | | ||
* | 3 | Rejected | | ||
* | 4 | Merged | | ||
*/ | ||
const billId = Number(params.id); | ||
const bill = enactedBill; | ||
bill.id = billId; | ||
|
||
let mergedBills: Bill[] | undefined; | ||
|
||
let events: BillEvent[] = []; | ||
let mergedIntoBill: Bill | undefined; | ||
let mergedIntoBillLatestEvent: BillEvent | undefined; | ||
let relatedVotingResults: RelatedVotingResults = {}; | ||
|
||
const votings = await fetchVotings(); | ||
|
||
if (billId === 1) { | ||
bill.status = BillStatus.InProgress; | ||
mergedBills = [ | ||
{ ...enactedBill, status: BillStatus.Merged }, | ||
{ ...enactedBill, status: BillStatus.Merged } | ||
]; | ||
events = [hearingEvent, passingMp1Event, inProgressMp2Event]; | ||
relatedVotingResults = { | ||
1: { voting: votings[0], resultSummary: fakeMpPassedVotingResultSummary } | ||
}; | ||
} else if (billId === 2) { | ||
bill.status = BillStatus.Enacted; | ||
events = [ | ||
hearingEvent, | ||
passingMp1Event, | ||
passingMp2Event, | ||
passingMp3Event, | ||
passingSenate1Event, | ||
passingSenate2Event, | ||
passingSenate3Event, | ||
royalAssentEvent, | ||
enforcementEvent | ||
]; | ||
relatedVotingResults = { | ||
'1': { voting: votings[0], resultSummary: fakeMpPassedVotingResultSummary }, | ||
'3': { voting: votings[0], resultSummary: fakeSenatePassedVotingResultSummary } | ||
}; | ||
} else if (billId === 3) { | ||
bill.status = BillStatus.Rejected; | ||
events = [hearingEvent, passingMp1Event, passingMp2Event, failingMp3Event]; | ||
relatedVotingResults = { | ||
'1': { voting: votings[0], resultSummary: fakeMpPassedVotingResultSummary }, | ||
'2': { voting: votings[1], resultSummary: fakeMpFailedVotingResultSummary } | ||
}; | ||
} else if (billId === 4) { | ||
bill.status = BillStatus.Merged; | ||
events = [hearingEvent, passingMp1Event, passingMergedMp2Event]; | ||
mergedIntoBill = inProgressBill; | ||
mergedIntoBillLatestEvent = { ...inProgressMp2Event, billId: inProgressBill.id }; | ||
relatedVotingResults = { | ||
'1': { voting: votings[0], resultSummary: fakeMpPassedVotingResultSummary } | ||
}; | ||
} | ||
|
||
events.reverse(); | ||
const bill = await fetchFromIdOr404(fetchBills, params.id); | ||
|
||
return { | ||
bill, | ||
mergedBills, // Bills that got merged into this bill. | ||
events, | ||
mergedIntoBill, // The bill that this bill got merged into. (merged event) | ||
mergedIntoBillLatestEvent, | ||
relatedVotingResults, // Info of votings in events | ||
// TODO: merged bill and event data is not ready yet | ||
mergedBills: [] as Bill[], // Bills that got merged into this bill. | ||
events: [] as BillEvent[], | ||
mergedIntoBill: undefined as Bill | undefined, // The bill that this bill got merged into. (merged event) | ||
mergedIntoBillLatestEvent: undefined as BillEvent | undefined, | ||
relatedVotingResults: {} as RelatedVotingResults, // Info of votings in events | ||
seo: createSeo({ | ||
title: bill.nickname | ||
}) | ||
}; | ||
} | ||
|
||
const fakeMpPassedVotingResultSummary: VotingResultSummary = { | ||
agreed: 324, | ||
total: 500, | ||
subResults: [ | ||
{ | ||
affiliationName: 'สส.ฝ่ายรัฐบาล', | ||
agreed: 310, | ||
total: 310 | ||
}, | ||
{ | ||
affiliationName: 'สส.ฝ่ายค้าน', | ||
agreed: 14, | ||
total: 190 | ||
} | ||
] | ||
}; | ||
|
||
const fakeMpFailedVotingResultSummary: VotingResultSummary = { | ||
agreed: 130, | ||
total: 500, | ||
subResults: [ | ||
{ | ||
affiliationName: 'สส.ฝ่ายรัฐบาล', | ||
agreed: 0, | ||
total: 310 | ||
}, | ||
{ | ||
affiliationName: 'สส.ฝ่ายค้าน', | ||
agreed: 130, | ||
total: 190 | ||
} | ||
] | ||
}; | ||
|
||
const fakeSenatePassedVotingResultSummary: VotingResultSummary = { | ||
agreed: 200, | ||
total: 250 | ||
}; |
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