File size: 2,111 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
// API client for the flat decision browse list (GET /api/decisions). Returns the
// SAME card shape as /api/lenses (Contested-lens cards), so the Topics /
// Questions / States browse pages and search can all render the shared StoryCard.
import api from '../lib/api'
import type { ApiCard } from '../components/StoryLenses'

export type DecisionSort = 'contested' | 'recent' | 'interesting'

export interface DecisionListParams {
  /** civicsearch topic id(s) — fuzzy text match against decision search_tsv.
   *  Multiple ids are OR'd server-side (decisions matching ANY topic). */
  topicIds?: number[]
  /** EveryOrg cause slug — keyword match against decision text (cause -> decision). */
  causeId?: string
  /** policy-question id — exact link via question_instance. */
  questionId?: string
  /** With questionId: the question's outcome family (approved | denied |
   *  moratorium | deferred | other), #499. */
  outcome?: string
  /** Meeting id — drill into a single meeting's decisions. */
  meetingId?: number
  /** 2-letter state code or full state name. */
  state?: string
  city?: string
  /** Free-text filter over decision title/summary/theme/jurisdiction. */
  q?: string
  sort?: DecisionSort
  limit?: number
  offset?: number
}

export interface DecisionListResponse {
  items: ApiCard[]
  pagination: { total: number; limit: number; offset: number }
}

/** Fetch a page of decision cards, filtered/sorted server-side. Empty `items`
 *  (with total 0) is an honest "no decisions match" — never fabricated. */
export async function fetchDecisions(params: DecisionListParams = {}): Promise<DecisionListResponse> {
  const res = await api.get<DecisionListResponse>('/decisions', {
    params: {
      topic_id: params.topicIds,
      cause_id: params.causeId,
      question_id: params.questionId,
      outcome: params.questionId ? params.outcome : undefined,
      meeting_id: params.meetingId,
      state: params.state,
      city: params.city,
      q: params.q,
      sort: params.sort,
      limit: params.limit,
      offset: params.offset,
    },
  })
  return res.data
}