Spaces:
Running on CPU Upgrade
Running on CPU Upgrade
File size: 17,499 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 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 | import { lazy, useEffect } from 'react'
import { useQuery } from '@tanstack/react-query'
import { Route, Routes, Navigate, useParams, useLocation, useSearchParams } from 'react-router-dom'
import { tracer } from './instrumentation'
import Layout from './components/Layout'
import SkipLink from './components/SkipLink'
import ScrollToTop from './components/ScrollToTop'
import Home from './pages/Home'
import HomeV9 from './pages/HomeV9'
import PolicyQuestionsPage from './pages/PolicyQuestionsPage'
import PolicyQuestionPage from './pages/PolicyQuestionPage'
import BrowseTopics from './pages/BrowseTopics'
import BrowseCauses from './pages/BrowseCauses'
import DataCenters from './pages/DataCenters'
import MoneyTalk from './pages/MoneyTalk'
import Dashboard from './pages/Dashboard'
import Analytics from './pages/Analytics'
import Heatmap from './pages/Heatmap'
import Documents from './pages/Documents'
import Opportunities from './pages/Opportunities'
import Nonprofits from './pages/Nonprofits'
import Efile990Viewer from './pages/Efile990Viewer'
import NonprofitsHF from './pages/NonprofitsHF'
import Settings from './pages/Settings'
import PeopleFinder from './pages/PeopleFinder'
import PersonDetail from './pages/PersonDetail'
import DebateFinder from './pages/DebateGrader'
import Profile from './pages/Profile'
import FeedSetup from './pages/FeedSetup'
import Explore from './pages/Explore'
import Events from './pages/Events'
import Services from './pages/Services'
import Developers from './pages/Developers'
import Support from './pages/Support'
import JurisdictionMappingQualityPage from './pages/JurisdictionMappingQualityPage'
import LighthouseReportPage from './pages/LighthouseReportPage'
import BatchJobStatusPage from './pages/BatchJobStatusPage'
import BatchFailureReasonsPage from './pages/BatchFailureReasonsPage'
import ApplicationLinksAdminPage from './pages/ApplicationLinksAdminPage'
import MeetingKindsAdminPage from './pages/MeetingKindsAdminPage'
import Hackathons from './pages/Hackathons'
import OpenSource from './pages/OpenSource'
import AdvocacyTopics from './pages/AdvocacyTopics'
import FactChecking from './pages/FactChecking'
import UnifiedSearch from './pages/UnifiedSearch'
import MeetingChat from './pages/MeetingChat'
import JurisdictionsSearch from './pages/JurisdictionsSearch'
import PolicyMap from './pages/PolicyMap'
import DecisionsMapPage from './pages/DecisionsMapPage'
import CensusMapPage from './pages/CensusMapPage'
import CensusDrilldownMapPage from './pages/CensusDrilldownMapPage'
import DataExplorerLayout from './components/DataExplorerLayout'
import AdminLayout from './components/AdminLayout'
import DataExplorerScorecardPage from './pages/DataExplorerScorecardPage'
import LazyRouteBoundary from './components/LazyRouteBoundary'
import BillDetail from './pages/BillDetail'
import GrantDetail from './pages/GrantDetail'
import DecisionDetail from './pages/DecisionDetail'
import MeetingDetail from './pages/MeetingDetail'
import BodyDetail from './pages/BodyDetail'
import MeetingDocuments from './pages/MeetingDocuments'
import MeetingCompare from './pages/MeetingCompare'
import EventBillDetail from './pages/EventBillDetail'
import NotFound from './pages/NotFound'
import { DATA_EXPLORER_MAP_BASE } from './utils/dataExplorerPaths'
import { storyRoute } from './utils/topicStories'
import { recordLocation } from './lib/pageClose'
import { STORIES } from './utils/dataStory'
import { useTopicStories } from './hooks/useTopicStories'
import { useDocumentTitle } from './utils/useDocumentTitle'
import { stateName, storyPageTitle } from './utils/routeMeta'
import RouteMetaSync from './components/RouteMetaSync'
import { BoxFlightProvider } from './components/stance/BoxFlightProvider'
// Loaded only when its route is visited (#856): its fonts and chart code stay out of the main bundle, and a
// failure to load it cannot blank the rest of the site.
const DataExplorerMatrixPage = lazy(() => import('./pages/DataExplorerMatrixPage'))
/** Old route-based drill-down (`/map/state/13/...`, `/map/place/13/...`) is now in-page;
* redirect those bookmarks to the unified `/map/us/{vintage}/{metric}` entry. */
function LegacyStatePlaceRedirect() {
const { vintage, metric } = useParams<{ vintage: string; metric: string }>()
const { search } = useLocation()
const v = vintage ?? '2024'
const m = metric ?? 'median_household_income'
return <Navigate to={`${DATA_EXPLORER_MAP_BASE}/us/${v}/${m}${search}`} replace />
}
/** `/map-v2/...` was the staging URL while the new page lived alongside the old one. */
function MapV2AliasRedirect() {
const { pathname, search } = useLocation()
const next = pathname.replace(/^\/data-explorer\/map-v2/, DATA_EXPLORER_MAP_BASE)
return <Navigate to={`${next}${search}`} replace />
}
/** Old bookmarked URLs used `/census-map/county/...`; national view is now state-level under Data explorer. */
function CensusCountyAliasRedirect() {
const { vintage, metric } = useParams<{ vintage: string; metric: string }>()
const { search } = useLocation()
const v = vintage ?? '2024'
const m = metric ?? 'median_household_income'
return <Navigate to={`${DATA_EXPLORER_MAP_BASE}/us/${v}/${m}${search}`} replace />
}
function DataExplorerMapDefaultRedirect() {
const { data, isError, isPending } = useQuery({
queryKey: ['data-explorer-map-root-redirect'],
queryFn: async (): Promise<string> => {
const rm = await fetch('/data/census-map/manifest.json')
if (!rm.ok) throw new Error('manifest')
const manifest = (await rm.json()) as {
vintage?: string
vintages?: string[]
metrics?: { slug: string }[]
}
const mv =
Array.isArray(manifest.vintages) && manifest.vintages.length > 0
? manifest.vintages
: manifest.vintage
? [manifest.vintage]
: []
let vintages = mv
const rt = await fetch('/data/census-map/state_trends.json')
if (rt.ok) {
const t = (await rt.json()) as { vintages?: string[] }
if (t.vintages?.length) vintages = t.vintages
}
const v = vintages.length ? vintages[vintages.length - 1]! : (manifest.vintage ?? '2024')
const metric = manifest.metrics?.[0]?.slug ?? 'median_household_income'
return `${DATA_EXPLORER_MAP_BASE}/us/${v}/${metric}`
},
})
if (isPending) return <div className="p-8 text-slate-600">Loading map…</div>
if (isError) return <Navigate to={`${DATA_EXPLORER_MAP_BASE}/us/2024/median_household_income`} replace />
return <Navigate to={data!} replace />
}
/** Rewrites `/census-map/...` bookmarks to `/data-explorer/map/...`. */
function LegacyCensusMapRedirect() {
const { pathname, search } = useLocation()
if (pathname === '/census-map' || pathname === '/census-map/') {
return <DataExplorerMapDefaultRedirect />
}
const path = pathname.replace(/^\/census-map/, DATA_EXPLORER_MAP_BASE)
return <Navigate to={`${path}${search}`} replace />
}
/**
* Emits a short `route.change` span on every navigation. Rendered inside the
* Router so `useLocation()` is available. Attribute is the path only (no query
* string) to keep cardinality bounded and avoid leaking search terms.
*/
function RouteChangeTracer() {
const location = useLocation()
// The trail lets Close (#1405) know the page before this one.
recordLocation({ pathname: location.pathname, search: location.search })
useEffect(() => {
const span = tracer.startSpan('route.change', {
attributes: { 'route.path': location.pathname },
})
span.end()
}, [location.pathname])
return null
}
// The challenge and the story pull in gsap and lenis, so they load on their own route chunks and no other page pays for them.
const DataStory = lazy(() => import('./pages/DataStory'))
const TopicStory = lazy(() => import('./pages/TopicStory'))
const BrowseAllTopics = lazy(() => import('./pages/BrowseAllTopics'))
const WhereTownsStand = lazy(() => import('./pages/WhereTownsStand'))
const OrganizationPage = lazy(() => import('./pages/OrganizationPage'))
const DataStories = lazy(() => import('./pages/DataStories'))
/**
* The Data Center Challenge is retired (#981): its statements are asked in the story itself. `/challenge`,
* `/challenge/:packId`, `/play` and `/play/:packId` go to the story for that topic, keeping the place in the URL.
*/
function ChallengeRedirect({ to = 'data-centers' }: { to?: string }) {
const { search } = useLocation()
return <Navigate to={`/stories/${to}${search}`} replace />
}
function PlayPackRedirect() {
const { packId = 'data-centers' } = useParams()
return <ChallengeRedirect to={encodeURIComponent(packId)} />
}
/** `/stories/:storyId` (#1133): the registry's stories (data centers) on DataStory, topic slugs on TopicStory. */
function StoryRoute() {
const { storyId = '' } = useParams()
// The tab names the story's topic (#1191): the registry's topic, else the curated topic's name from the catalog.
const { stories } = useTopicStories()
const [params] = useSearchParams()
const reg = STORIES[storyId]
const topic = reg ? reg.topic : stories[storyId]?.title
// The same title the server sends in the page's HTML (#1430): "Gun control in Alabama — Data story".
useDocumentTitle(topic ? storyPageTitle(topic, stateName(params.get('state'))) : 'Data story')
return storyRoute(storyId) === 'data' ? <DataStory /> : <TopicStory slug={storyId} />
}
function App() {
return (
<>
<SkipLink />
<ScrollToTop />
<RouteChangeTracer />
<RouteMetaSync />
<BoxFlightProvider>
<Routes>
{/* v9 prototype homepage (single-column; has its own header) */}
<Route path="/" element={<HomeV9 />} />
{/* Previous homepage, kept reachable for comparison/rollback */}
<Route path="/home-original" element={<Home />} />
{/* All other pages with sidebar layout */}
<Route path="/" element={<Layout />}>
<Route path="explore" element={<Explore />} />
<Route path="search" element={<UnifiedSearch />} />
<Route path="chat" element={<MeetingChat />} />
<Route path="jurisdictions" element={<JurisdictionsSearch />} />
<Route path="dashboard" element={<Dashboard />} />
<Route path="analytics" element={<Analytics />} />
<Route path="people" element={<PeopleFinder />} />
<Route path="person/:id" element={<PersonDetail />} />
<Route path="heatmap" element={<Heatmap />} />
<Route path="policy-map" element={<PolicyMap />} />
<Route path="decisions-map" element={<DecisionsMapPage />} />
<Route path="policy-questions" element={<PolicyQuestionsPage />} />
<Route path="policy-question/:questionId" element={<PolicyQuestionPage />} />
<Route path="browse-topics" element={<BrowseTopics />} />
{/* Every main topic, last year against this year, in one animated dumbbell (#1343). */}
<Route
path="browse-topics/all"
element={
<LazyRouteBoundary name="Browse all topics">
<BrowseAllTopics />
</LazyRouteBoundary>
}
/>
{/* Where towns stand: per place and topic, how public speakers leaned (#1438). */}
<Route
path="where-towns-stand"
element={
<LazyRouteBoundary name="Where towns stand">
<WhereTownsStand />
</LazyRouteBoundary>
}
/>
<Route path="browse-causes" element={<BrowseCauses />} />
<Route path="data-centers" element={<DataCenters />} />
<Route path="play" element={<ChallengeRedirect />} />
<Route path="play/:packId" element={<PlayPackRedirect />} />
<Route path="challenge" element={<ChallengeRedirect />} />
<Route path="challenge/:packId" element={<PlayPackRedirect />} />
<Route
path="stories"
element={
<LazyRouteBoundary name="Data stories">
<DataStories />
</LazyRouteBoundary>
}
/>
{/* One route for every story (#1133): the registry's stories on DataStory, any curated topic on TopicStory. */}
<Route
path="stories/:storyId"
element={
<LazyRouteBoundary name="Data story">
<StoryRoute />
</LazyRouteBoundary>
}
/>
{/* Organization page (#1015). */}
<Route
path="organizations/:masterOrgId"
element={
<LazyRouteBoundary name="Organization">
<OrganizationPage />
</LazyRouteBoundary>
}
/>
<Route path="money-and-talk" element={<MoneyTalk />} />
<Route path="census-map/county/:vintage/:metric" element={<CensusCountyAliasRedirect />} />
<Route path="census-map/*" element={<LegacyCensusMapRedirect />} />
<Route path="data-explorer" element={<DataExplorerLayout />}>
<Route index element={<DataExplorerMapDefaultRedirect />} />
<Route path="scorecard" element={<DataExplorerScorecardPage />} />
<Route
path="matrix"
element={
<LazyRouteBoundary name="How states compare">
<DataExplorerMatrixPage />
</LazyRouteBoundary>
}
/>
<Route path="jurisdiction-quality" element={<JurisdictionMappingQualityPage />} />
{/* Lighthouse report + batch jobs moved to the Admin area; keep old URLs working. */}
<Route path="lighthouse-report" element={<Navigate to="/admin/lighthouse-report" replace />} />
<Route path="batch-jobs" element={<Navigate to="/admin/batch-jobs" replace />} />
<Route path="map/us/:vintage/:metric" element={<CensusDrilldownMapPage />} />
<Route path="map/state/:stateFips/:vintage/:metric" element={<LegacyStatePlaceRedirect />} />
<Route path="map/place/:stateFips/:vintage/:metric" element={<LegacyStatePlaceRedirect />} />
<Route path="map" element={<DataExplorerMapDefaultRedirect />} />
{/* Legacy staging URLs while the drilldown lived alongside the old page.
Anyone with a bookmark to /map-v2/... lands on the canonical /map/... now. */}
<Route path="map-v2/*" element={<MapV2AliasRedirect />} />
{/* Old CensusMapPage retained at `/map-legacy/...` for one-click rollback if needed. */}
<Route path="map-legacy/us/:vintage/:metric" element={<CensusMapPage />} />
<Route path="map-legacy/state/:stateFips/:vintage/:metric" element={<CensusMapPage />} />
<Route path="map-legacy/place/:stateFips/:vintage/:metric" element={<CensusMapPage />} />
</Route>
{/* Admin area — operational tools, reachable from the logged-in profile menu. */}
<Route path="admin" element={<AdminLayout />}>
<Route index element={<Navigate to="/admin/batch-jobs" replace />} />
<Route path="lighthouse-report" element={<LighthouseReportPage />} />
<Route path="batch-jobs" element={<BatchJobStatusPage />} />
<Route path="batch-jobs/failures" element={<BatchFailureReasonsPage />} />
<Route path="application-links" element={<ApplicationLinksAdminPage />} />
<Route path="meeting-kinds" element={<MeetingKindsAdminPage />} />
</Route>
<Route path="bill/:billId" element={<BillDetail />} />
<Route path="grants/:id" element={<GrantDetail />} />
<Route path="efile990" element={<Efile990Viewer />} />
<Route path="efile990/:objectId" element={<Efile990Viewer />} />
<Route path="decisions/:id" element={<DecisionDetail />} />
<Route path="meetings/:id" element={<MeetingDetail />} />
<Route path="bodies/:bodyId" element={<BodyDetail />} />
<Route path="jurisdiction/:jurisdictionId/meetings" element={<MeetingDocuments />} />
<Route
path="jurisdiction/:jurisdictionId/meetings/:eventMeetingId/compare"
element={<MeetingCompare />}
/>
<Route path="bills/:id" element={<EventBillDetail />} />
<Route path="documents" element={<Documents />} />
<Route path="opportunities" element={<Opportunities />} />
<Route path="nonprofits" element={<Nonprofits />} />
<Route path="nonprofits-hf" element={<NonprofitsHF />} />
<Route path="debate-grader" element={<DebateFinder />} />
<Route path="profile" element={<Profile />} />
<Route path="feed-setup" element={<FeedSetup />} />
<Route path="settings" element={<Settings />} />
<Route path="events" element={<Events />} />
<Route path="services" element={<Services />} />
<Route path="developers" element={<Developers />} />
<Route path="support" element={<Support />} />
<Route
path="build/jurisdiction-mapping-quality"
element={<Navigate to="/data-explorer/jurisdiction-quality" replace />}
/>
<Route path="hackathons" element={<Hackathons />} />
<Route path="opensource" element={<OpenSource />} />
<Route path="advocacy-topics" element={<AdvocacyTopics />} />
<Route path="fact-checking" element={<FactChecking />} />
</Route>
{/* 404 Page - Catch all unmatched routes */}
<Route path="*" element={<NotFound />} />
</Routes>
</BoxFlightProvider>
</>
)
}
export default App
|