File size: 2,648 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
// What is coming up on a topic (#1302): GET /api/topics/{topic}/upcoming.
import api from '../lib/api'

export type UpcomingKind = 'meeting' | 'hearing' | 'deadline' | 'bill_action' | 'event'
/** Why the item is about the topic: the agenda names it, an official hearing notice, or the place discussed it before. */
export type UpcomingBasis = 'agenda_text' | 'official_notice' | 'place_discussed_before' | 'hosted_by_org'

export interface UpcomingItem {
  upcoming_id: string
  kind: UpcomingKind
  match_basis: UpcomingBasis
  /** ISO date, today or later. */
  date: string
  time: string | null
  jurisdiction_name: string | null
  state_code: string
  state: string | null
  body_name: string | null
  title: string | null
  location: string | null
  /** Where to take part: the agenda, the meeting page, the livestream or the official notice. */
  source_url: string
  source_label: string
  /** Verbatim evidence with the topic's words in <mark> (render with highlightSnippet). */
  matched_text: string
  /** place_discussed_before: the earlier recorded meeting the evidence comes from. */
  prior_meeting_date: string | null
  prior_url: string | null
  tentative: boolean
  /** hosted_by_org (#1347): the nonprofit hosting the event, which links to its page. */
  host_org_name?: string | null
  host_master_org_id?: string | null
}

export interface PendingBill {
  bill_id: string
  identifier: string | null
  title: string | null
  state_code: string
  state: string | null
  status: 'pending' | 'passed_chamber'
  last_action: string | null
  last_action_date: string | null
  url: string | null
}

export interface TopicUpcomingResponse {
  topic: string
  topic_id: number | null
  state_code: string | null
  state: string | null
  city: string | null
  available: boolean
  as_of: string
  last_updated: string | null
  built_at: string | null
  total: number
  counts: Record<UpcomingKind, number>
  items: UpcomingItem[]
  pending_bills: { total: number; latest_action_seen: string | null; items: PendingBill[] }
  /** Set when the scope has nothing upcoming: the count one level up (city -> state -> national). */
  broader: { state_code: string | null; label: string; total: number } | null
}

export async function fetchTopicUpcoming(topic: string, stateCode?: string | null, city?: string | null, limit = 12): Promise<TopicUpcomingResponse> {
  const params: Record<string, string | number> = { limit }
  if (stateCode) params.state = stateCode
  if (stateCode && city) params.city = city
  const { data } = await api.get<TopicUpcomingResponse>(`/topics/${encodeURIComponent(topic)}/upcoming`, { params })
  return data
}