Spaces:
Running on CPU Upgrade
Running on CPU Upgrade
File size: 4,390 Bytes
d15f07c | 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 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 | // Where policy is moving on a topic (#1274): GET /api/topics/{topic}/legislation, /positions and /local-actions.
import api from '../lib/api'
export type BillStatus = 'enacted' | 'passed_chamber' | 'pending' | 'failed'
export interface LegislationBill {
bill_id: string
identifier: string | null
title: string | null
session: string | null
/** Calendar year of the latest action, as a string (CLAUDE.md: bare years go on the wire as strings). */
year: string | null
category: string
status: BillStatus
passed_a_chamber: boolean
url: string | null
introduced_date: string | null
last_action_date: string | null
last_action: string | null
}
/** Bills in one state with one category, latest-action year and status: what the map colours from. */
export interface LegislationSummaryRow {
state_code: string
state: string | null
category: string
year: string | null
status: BillStatus
bills: number
}
export interface LegislationCategory {
category: string
label: string | null
description: string | null
display_order: number | null
bills: number
}
export interface TopicLegislationResponse {
topic: string
topic_id: number | null
state_code: string | null
available: boolean
total_bills: number
states_with_bills: number
status_counts: Partial<Record<BillStatus, number>>
categories: LegislationCategory[]
summary: LegislationSummaryRow[]
}
export interface TopicStateBillsResponse {
topic: string
state_code: string
state: string | null
since_year: string | null
category: string | null
/** Bills matching the filters; `bills` holds the first `limit`, furthest status first, newest first. */
matching: number
limit: number
bills: LegislationBill[]
}
export interface PositionCount {
key: string
meetings: number
}
export interface TopicPositionsResponse {
topic: string
state_code: string | null
available: boolean
/** 'five' = the topic's own five positions; 'lean' = mostly supportive / mixed / mostly opposed. */
scale: 'five' | 'lean' | null
read_meetings: number
spoke_meetings: number
did_not_speak: number
states: number
options: PositionCount[]
}
export type ActionGroup = 'advanced' | 'blocked' | 'tabled_or_deferred'
export type ActionCounts = Record<ActionGroup, number>
export interface ActionMeeting {
video_id: string
jurisdiction_name: string | null
state_code: string | null
meeting_date: string | null
outcome_group: ActionGroup
outcome: string | null
outcome_p: number | null
url: string | null
title: string | null
}
export interface TopicLocalActionsResponse {
topic: string
state_code: string | null
available: boolean
total: number
undated: number
totals: ActionCounts
by_state: { state_code: string; state: string | null; counts: ActionCounts }[]
by_year: { year: string; counts: ActionCounts }[]
meetings: ActionMeeting[]
}
const params = (state?: string): Record<string, string> => (state ? { state } : {})
export async function fetchTopicLegislation(topic: string): Promise<TopicLegislationResponse> {
// Always national counts: the map shows every state, and the scoped state is highlighted and opened on the client.
const res = await api.get<TopicLegislationResponse>(`/topics/${encodeURIComponent(topic)}/legislation`)
return res.data
}
export async function fetchTopicStateBills(
topic: string,
state: string,
filter: { sinceYear: number | null; category: string | null },
): Promise<TopicStateBillsResponse> {
const p: Record<string, string> = {}
if (filter.sinceYear != null) p.since_year = String(filter.sinceYear)
if (filter.category) p.category = filter.category
const res = await api.get<TopicStateBillsResponse>(
`/topics/${encodeURIComponent(topic)}/legislation/${encodeURIComponent(state)}`,
{ params: p },
)
return res.data
}
export async function fetchTopicPositions(topic: string, state?: string): Promise<TopicPositionsResponse> {
const res = await api.get<TopicPositionsResponse>(`/topics/${encodeURIComponent(topic)}/positions`, { params: params(state) })
return res.data
}
export async function fetchTopicLocalActions(topic: string, state?: string): Promise<TopicLocalActionsResponse> {
const res = await api.get<TopicLocalActionsResponse>(`/topics/${encodeURIComponent(topic)}/local-actions`, {
params: params(state),
})
return res.data
}
|