File size: 2,907 Bytes
a8fb296
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import { Link } from 'react-router-dom'
import { adjacentScreens, screenLabel } from '../../utils/matrixStory'
import type { MatrixCtx } from './types'

/** The app's decisions browse page (App.tsx `browse-topics`); it reads `?state=<2-letter code>` and is national without it. */
const DECISIONS_PATH = '/browse-topics'

/** Where "See decisions" goes: the state in scope, or the national page. Exported for the tests. */
export function decisionsHref(stateCode: string | null): string {
  return stateCode ? `${DECISIONS_PATH}?${new URLSearchParams({ state: stateCode }).toString()}` : DECISIONS_PATH
}

/**
 * The last screen: large square buttons that carry the scope in view. Every destination is a route that
 * exists in App.tsx. The Table section's own CSV download is the third button.
 */
export default function ActionBlock({ ctx, onDownload }: { ctx: MatrixCtx; onDownload: () => void }) {
  const state = ctx.stateScope
  const { prev } = adjacentScreens('action')
  return (
    <section className="folio-action" id="action" aria-labelledby="action-h">
      <p className="folio-eyebrow">Go further</p>
      <h3 className="folio-action-title" id="action-h" tabIndex={-1}>
        Take it further
      </h3>
      <p className="folio-lede">
        {ctx.metricLabel}, {ctx.vintage} ACS 5-year, {state ? state.name : 'all states and territories'}.
      </p>
      <ul className="folio-action-grid">
        <li>
          <Link className="folio-action-btn" to={decisionsHref(state?.code ?? null)}>
            <span className="folio-action-label">{state ? `See decisions in ${state.name}` : 'See decisions nationwide'}</span>
            <span aria-hidden="true" className="folio-action-arrow">
              →
            </span>
          </Link>
        </li>
        <li>
          <button type="button" className="folio-action-btn" onClick={onDownload}>
            <span className="folio-action-label">Download this table (CSV)</span>
            <span aria-hidden="true" className="folio-action-arrow">
              ↓
            </span>
          </button>
        </li>
        <li>
          <Link className="folio-action-btn" to={ctx.mapHref}>
            <span className="folio-action-label">Open the map view</span>
            <span aria-hidden="true" className="folio-action-arrow">
              →
            </span>
          </Link>
        </li>
      </ul>
      <div className="folio-pager folio-pager-end">
        {prev && (
          <button type="button" className="folio-pager-back" onClick={() => ctx.goTo(prev.domId)}>
            <span aria-hidden="true">↑</span> Back: {screenLabel(prev.section, ctx.labelInput)}
          </button>
        )}
        <button type="button" className="folio-pager-back" onClick={() => ctx.goTo('top')}>
          <span aria-hidden="true">↑</span> Back to the start
        </button>
      </div>
    </section>
  )
}