Skip to content

Commit a18436a

Browse files
committed
Refactoring
1 parent 2298417 commit a18436a

File tree

15 files changed

+47
-46
lines changed

15 files changed

+47
-46
lines changed

analysis/downloader/loader.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@ import { parse, stringify } from "csv/sync"
22
import { readFileSync, writeFileSync } from "fs"
33
import { BillHistory } from "../../functions/src/bills/types"
44
import { db } from "../../functions/src/firebase"
5-
import {
6-
currentGeneralCourt,
7-
parseApiDateTime
8-
} from "../../functions/src/malegislature"
5+
import { parseApiDateTime } from "../../functions/src/malegislature"
96
import { ClassifiedAction, History } from "./types"
7+
import { currentGeneralCourt } from "../../components/db/common"
108

119
const historyColumns = ["id", "action", "branch", "date"]
1210

components/ProfileLink/ProfileLink.tsx

+12-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { useEffect, useState } from "react"
2-
import { Container, Navbar, Nav} from "react-bootstrap"
2+
import { Container, Navbar, Nav } from "react-bootstrap"
33
import Image from "react-bootstrap/Image"
44
import { Role, signOutAndRedirectToHome, useAuth } from "../auth"
55
import { NavLink } from "../Navlink"
@@ -45,16 +45,17 @@ const ProfileLink = ({
4545
sticky={sticky ? "top" : undefined}
4646
expand={false}
4747
expanded={isExpanded}
48-
className="p-0">
48+
className="p-0"
49+
>
4950
<Container className={`py-0`}>
5051
<div className={styles.navbar_boxes_container}>
5152
<Navbar.Brand className="mx-2 p-0" onClick={toggleNav}>
5253
<Nav.Link className="p-0">
5354
<Image
5455
className={styles.profileLinkImage}
5556
src="/profile-icon.svg"
56-
alt="profile icon">
57-
</Image>
57+
alt="profile icon"
58+
></Image>
5859
{greeting(role, displayName)}
5960
</Nav.Link>
6061
</Navbar.Brand>
@@ -64,20 +65,24 @@ const ProfileLink = ({
6465
<NavLink
6566
className={"navLink-primary"}
6667
href={"/profile" + search}
67-
handleClick={closeNav}>
68+
handleClick={closeNav}
69+
>
6870
View Profile
6971
</NavLink>
7072
<NavLink
7173
className={"navLink-primary"}
7274
href="/editprofile"
73-
handleClick={closeNav}>
75+
handleClick={closeNav}
76+
>
7477
Edit Profile
7578
</NavLink>
7679
<NavLink
7780
className={"navLink-primary"}
7881
handleClick={() => {
7982
closeNav()
80-
void signOutAndRedirectToHome()}}>
83+
void signOutAndRedirectToHome()
84+
}}
85+
>
8186
Sign Out
8287
</NavLink>
8388
</Nav>

components/auth/TermsOfService.module.css

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,4 @@
3232

3333
.subscribe:a {
3434
color: #1a3185;
35-
}
35+
}

components/bill/BillDetails.tsx

+4-7
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import { Status } from "./Status"
2525
import { Summary } from "./Summary"
2626
import { BillProps } from "./types"
2727
import { useTranslation } from "next-i18next"
28+
import { isCurrentCourt } from "components/db/common"
2829

2930
const StyledContainer = styled(Container)`
3031
font-family: "Nunito";
@@ -41,11 +42,7 @@ export const BillDetails = ({ bill }: BillProps) => {
4142
const { t } = useTranslation("common")
4243
return (
4344
<>
44-
{/**
45-
* replace bill.court !== 193 with function to check for
46-
* latest court from an array of courts
47-
*/}
48-
{bill.court !== 193 && (
45+
{!isCurrentCourt(bill.court) && (
4946
<Banner>
5047
this bill is from session {bill.court} - not the current session
5148
</Banner>
@@ -69,7 +66,7 @@ export const BillDetails = ({ bill }: BillProps) => {
6966
<Row className="mb-4">
7067
<Col xs={12} className="d-flex justify-content-end">
7168
<div
72-
/* remove "div w/ d-none" for testing and/or after Soft Launch
69+
/* remove "div w/ d-none" for testing and/or after Soft Launch
7370
when we're ready to show Email related element to users
7471
*/
7572
className="d-none"
@@ -87,7 +84,7 @@ export const BillDetails = ({ bill }: BillProps) => {
8784
<Col xs={6} className="d-flex justify-content-end">
8885
<Styled>
8986
<div
90-
/* remove "div w/ d-none" for testing and/or after Soft Launch
87+
/* remove "div w/ d-none" for testing and/or after Soft Launch
9188
when we're ready to show Email related element to users
9289
*/
9390
className="d-none"

components/db/common.ts

+10-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ import { DateTime } from "luxon"
33
import { Null, Nullish, Optional, Runtype, String } from "runtypes"
44
import { firestore } from "../firebase"
55

6-
export const currentGeneralCourt = 193
7-
86
type GeneralCourt = {
97
Name: string
108
Number: number
@@ -27,6 +25,16 @@ export const generalCourts: Record<number, GeneralCourt | undefined> = {
2725
}
2826
}
2927

28+
export const supportedGeneralCourts = Object.keys(generalCourts)
29+
.map(n => Number.parseInt(n))
30+
.sort()
31+
.reverse()
32+
33+
export const currentGeneralCourt = supportedGeneralCourts[0]
34+
35+
export const isCurrentCourt = (courtNumber: number) =>
36+
courtNumber === currentGeneralCourt
37+
3038
export async function loadDoc(path: string) {
3139
const d = await getDoc(doc(firestore, path))
3240
return d.data()

components/links.tsx

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
1-
import { faExternalLinkAlt } from "@fortawesome/free-solid-svg-icons"
2-
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"
31
import Link from "next/link"
42
import { forwardRef, PropsWithChildren } from "react"
53
import { CurrentCommittee } from "../functions/src/bills/types"
64
import { Testimony } from "components/db/testimony"
75
import { Bill, MemberContent } from "./db"
8-
import { currentGeneralCourt } from "./db/common"
96
import { formatBillId } from "./formatting"
107

118
type LinkProps = PropsWithChildren<{ href: string; className?: string }>
@@ -36,7 +33,7 @@ export function External({
3633
{
3734
!plain
3835
/*
39-
Icon removed from current Figma
36+
Icon removed from current Figma
4037
*/
4138
// && <FontAwesomeIcon icon={faExternalLinkAlt} />
4239
}

functions/src/bills/BillProcessor.ts

+5-6
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { db } from "../firebase"
77
import * as api from "../malegislature"
88
import { Member } from "../members/types"
99
import { Bill } from "./types"
10+
import { currentGeneralCourt } from "../../../components/db/common"
1011

1112
export type BillUpdates = Map<string, DocUpdate<Bill>>
1213

@@ -56,9 +57,7 @@ export default abstract class BillProcessor {
5657
abstract process(): Promise<void>
5758

5859
billPath(id?: string) {
59-
return `/generalCourts/${api.currentGeneralCourt}/bills${
60-
id ? `/${id}` : ""
61-
}`
60+
return `/generalCourts/${currentGeneralCourt}/bills${id ? `/${id}` : ""}`
6261
}
6362

6463
protected async writeBills(updates: BillUpdates) {
@@ -79,15 +78,15 @@ export default abstract class BillProcessor {
7978
.then(snap => snap.docs.map(d => d.data()))
8079
this.billIds = this.bills.map(b => b.id)
8180
this.cities = await db
82-
.collection(`/generalCourts/${api.currentGeneralCourt}/cities`)
81+
.collection(`/generalCourts/${currentGeneralCourt}/cities`)
8382
.get()
8483
.then(this.load(City))
8584
this.committees = await db
86-
.collection(`/generalCourts/${api.currentGeneralCourt}/committees`)
85+
.collection(`/generalCourts/${currentGeneralCourt}/committees`)
8786
.get()
8887
.then(this.load(Committee))
8988
this.members = await db
90-
.collection(`/generalCourts/${api.currentGeneralCourt}/members`)
89+
.collection(`/generalCourts/${currentGeneralCourt}/members`)
9190
.get()
9291
.then(this.load(Member))
9392
}

functions/src/bills/backfillTestimonyCounts.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { groupBy } from "lodash"
22
import { Array, Optional, Record, String } from "runtypes"
33
import { db } from "../firebase"
4-
import { currentGeneralCourt } from "../malegislature"
4+
import { currentGeneralCourt } from "../../../components/db/common"
55
import { Testimony } from "../testimony/types"
66
import BillProcessor from "./BillProcessor"
77

functions/src/committees/updateCommitteeRosters.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@ import { db } from "../firebase"
44
import * as api from "../malegislature"
55
import { Member } from "../members/types"
66
import { Committee } from "./types"
7+
import { currentGeneralCourt } from "../../../components/db/common"
78

89
/** Updates the list of members in each committee. */
910
export const updateCommitteeRosters = runWith({ timeoutSeconds: 120 })
1011
.pubsub.schedule("every 24 hours")
1112
.onRun(async () => {
1213
const members = await db
13-
.collection(`/generalCourts/${api.currentGeneralCourt}/members`)
14+
.collection(`/generalCourts/${currentGeneralCourt}/members`)
1415
.get()
1516
.then(c => c.docs.map(d => d.data()).filter(Member.guard))
1617
const rosters = computeRosters(members)
@@ -21,7 +22,7 @@ export const updateCommitteeRosters = runWith({ timeoutSeconds: 120 })
2122
members: roster.map(m => ({ id: m.id, name: m.content.Name }))
2223
}
2324
writer.set(
24-
db.doc(`/generalCourts/${api.currentGeneralCourt}/committees/${id}`),
25+
db.doc(`/generalCourts/${currentGeneralCourt}/committees/${id}`),
2526
update,
2627
{ merge: true }
2728
)

functions/src/events/scrapeEvents.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
SpecialEvent,
1515
SpecialEventContent
1616
} from "./types"
17+
import { currentGeneralCourt } from "../../../components/db/common"
1718

1819
abstract class EventScraper<ListItem, Event extends BaseEvent> {
1920
private schedule
@@ -105,7 +106,7 @@ class SpecialEventsScraper extends EventScraper<
105106
}
106107

107108
class SessionScraper extends EventScraper<SessionContent, Session> {
108-
private court = api.currentGeneralCourt
109+
private court = currentGeneralCourt
109110

110111
constructor() {
111112
super("every 60 minutes", 120)

functions/src/malegislature.ts

-5
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,6 @@ export type MemberListing = {
6161
MemberCode: string
6262
}
6363

64-
/** The general court is the name for a session of the legislature, which lasts
65-
* two years. */
66-
export const currentGeneralCourt = 193
67-
export const supportedGeneralCourts = [192, 193]
68-
6964
/** The timezone used for datetime strings returned by the API. */
7065
export const timeZone = "America/New_York"
7166

functions/src/members/createMemberSearchIndex.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
import { pubsub } from "firebase-functions"
22
import { db } from "../firebase"
33
import * as api from "../malegislature"
4+
import { currentGeneralCourt } from "../../../components/db/common"
45

56
/** Create a document that aggregates all legislative members for easier
67
* searching on the client. */
78
export const createMemberSearchIndex = pubsub
89
.schedule("every 24 hours")
910
.onRun(async () => {
1011
const members = await db
11-
.collection(`/generalCourts/${api.currentGeneralCourt}/members`)
12+
.collection(`/generalCourts/${currentGeneralCourt}/members`)
1213
.get()
1314

1415
const index = members.docs
@@ -19,7 +20,7 @@ export const createMemberSearchIndex = pubsub
1920
.sort((m1, m2) => (m1.Name < m2.Name ? -1 : 1))
2021

2122
await db
22-
.doc(`/generalCourts/${api.currentGeneralCourt}/indexes/memberSearch`)
23+
.doc(`/generalCourts/${currentGeneralCourt}/indexes/memberSearch`)
2324
.set({
2425
representatives: index.filter(d => d.Branch === "House"),
2526
senators: index.filter(d => d.Branch === "Senate")

functions/src/scraper.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import axios, { AxiosError } from "axios"
22
import { logger, runWith } from "firebase-functions"
33
import { last } from "lodash"
44
import { db, DocumentData, FieldValue, Timestamp } from "./firebase"
5-
import { currentGeneralCourt } from "./malegislature"
5+
import { currentGeneralCourt } from "../../components/db/common"
66

77
/** Batch documents trigger the batch fetch function to scrape `ids` */
88
type Batch = {

functions/src/testimony/publishTestimony.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { Record } from "runtypes"
55
import { Bill } from "../bills/types"
66
import { checkAuth, checkRequest, DocUpdate, fail, Id } from "../common"
77
import { db, FieldValue, Timestamp } from "../firebase"
8-
import { supportedGeneralCourts } from "../malegislature"
8+
import { supportedGeneralCourts } from "../../../components/db/common"
99
import { Attachments, PublishedAttachmentState } from "./attachments"
1010
import { DraftTestimony, Testimony } from "./types"
1111
import { updateTestimonyCounts } from "./updateTestimonyCounts"

tests/integration/common.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ export const signInUser3 = () => signInUser("[email protected]")
1616
export const signInUser4 = () => signInUser("[email protected]")
1717

1818
export async function createNewBill(props?: Partial<Bill>) {
19-
const billId = props?.id ?? nanoid(),
20-
court = props?.court ?? 192
19+
const billId = props?.id ?? nanoid()
2120
const content: BillContent = {
2221
Pinslip: null,
2322
Title: "fake",

0 commit comments

Comments
 (0)