-
-
Notifications
You must be signed in to change notification settings - Fork 158
Expand file tree
/
Copy pathbills.ts
More file actions
106 lines (97 loc) · 2.35 KB
/
bills.ts
File metadata and controls
106 lines (97 loc) · 2.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import {
collection,
getDocs,
limit,
orderBy,
Timestamp,
where
} from "firebase/firestore"
import { useAsync } from "react-async-hook"
import type {
BillHistory,
CurrentCommittee
} from "../../functions/src/bills/types"
import { firestore } from "../firebase"
import { loadDoc, midnight, nullableQuery } from "./common"
import { currentGeneralCourt } from "functions/src/shared"
export type { BillHistory } from "../../functions/src/bills/types"
export type MemberReference = {
Id: string
Name: string
/** 1 = Legislative Member, 2 = Committee, 3 = Public Request, 4 = Special
* Request */
Type: number
}
export type BillContent = {
Title: string
BillNumber: string
DocketNumber: string
GeneralCourtNumber: number
PrimarySponsor?: MemberReference
Cosponsors: MemberReference[]
LegislationTypeName: string
Pinslip: string
DocumentText?: string
}
export type BillTopic = {
category: string
topic: string
}
export type Bill = {
id: string
court: number
content: BillContent
cosponsorCount: number
testimonyCount: number
endorseCount: number
opposeCount: number
neutralCount: number
nextHearingAt?: Timestamp
latestTestimonyAt?: Timestamp
latestTestimonyId?: string
fetchedAt: Timestamp
history: BillHistory
currentCommittee?: CurrentCommittee
city?: string
topics?: BillTopic[]
summary?: string
hearingIds?: string[]
}
export function useBill(court: number, id: string) {
return useAsync(getBill, [court, id])
}
export type SortOptions =
| "id"
| "cosponsorCount"
| "testimonyCount"
| "latestTestimony"
| "hearingDate"
export type FilterOptions =
| { type: "bill"; id: string }
| { type: "primarySponsor"; id: string }
| { type: "committee"; id: string }
| { type: "city"; name: string }
export async function getBill(
court: number,
id: string
): Promise<Bill | undefined> {
const bill = await loadDoc(`/generalCourts/${court}/bills/${id}`)
return bill as any
}
export async function listBillsByHearingDate(
limitCount: number
): Promise<Bill[]> {
const billsRef = collection(
firestore,
`/generalCourts/${currentGeneralCourt}/bills`
)
const result = await getDocs(
nullableQuery(
billsRef,
where("nextHearingAt", ">=", midnight()),
orderBy("nextHearingAt", "asc"),
limit(limitCount)
)
)
return result.docs.map(d => d.data() as Bill)
}