diff --git a/app/county/[county]/page.tsx b/app/county/[county]/page.tsx index fcfc222..a27bc63 100644 --- a/app/county/[county]/page.tsx +++ b/app/county/[county]/page.tsx @@ -7,6 +7,7 @@ import PercentileLineChart from "components/PercentileLineChart" import { getMdxContent } from "hooks/useMdxContent" import { getContentDirs } from "utils/contentDirs" import { getSummaryStats } from "utils/data/summaryStats" +import TimeseriesChart from "components/TimeseriesChart" const Map = dynamic(() => import("components/Map/Map"), { ssr: false }) const operators = [ @@ -169,6 +170,9 @@ const CountyPage: React.FC = async ({ params }) => { +
+ +
)} diff --git a/app/state/page.tsx b/app/state/page.tsx index a19f2e2..f4941fb 100644 --- a/app/state/page.tsx +++ b/app/state/page.tsx @@ -1,11 +1,21 @@ -import React from "react" +"use client" +import { useRouter } from "next/navigation" +import React, { useState } from "react" +import CountyFilterSelector from "components/CountyFilterSelector" const StatePage: React.FC = () => { + const router = useRouter() + const handleChange = (e: string) => { + router.push(`/state/${e}`) + } return ( -
-

State home page

+
+
+

State Home Page

+ +
) } -export default StatePage \ No newline at end of file +export default StatePage diff --git a/components/Map/Map.tsx b/components/Map/Map.tsx index f95897b..a416025 100644 --- a/components/Map/Map.tsx +++ b/components/Map/Map.tsx @@ -232,7 +232,7 @@ export const Map: React.FC = ({ const handleSetFilter = (filter: string) => dispatch(setCurrentFilter(filter)) useEffect(() => { - if (dispatch && initialFilter) { + if (initialFilter) { dispatch(setCurrentFilter(initialFilter)) } // eslint-disable-next-line react-hooks/exhaustive-deps diff --git a/components/TimeseriesChart/Renderer.tsx b/components/TimeseriesChart/Renderer.tsx new file mode 100644 index 0000000..72ec0e7 --- /dev/null +++ b/components/TimeseriesChart/Renderer.tsx @@ -0,0 +1,23 @@ +"use client" +import React, { useEffect, useState } from "react"; +import { getTimeseriesChartProps } from "./types"; +import { ds } from "utils/data/service"; + +const TimeseriesChart: React.FC = ({ id }) => { + const [data, setData] = useState([]); + + useEffect(() => { + const fetchData = async () => { + await ds.initDb(); + await ds.initData(); + const data = await ds.getTimeseries(id); + setData(data); + }; + + fetchData(); + }, [id]); + + return
TimeseriesChart {id}
; +} + +export default TimeseriesChart; \ No newline at end of file diff --git a/components/TimeseriesChart/index.ts b/components/TimeseriesChart/index.ts new file mode 100644 index 0000000..8ca45c0 --- /dev/null +++ b/components/TimeseriesChart/index.ts @@ -0,0 +1,4 @@ +import dynamic from 'next/dynamic' +const TimeseriesChart = dynamic(() => import('components/TimeseriesChart/Renderer'), { ssr: false }) + +export default TimeseriesChart \ No newline at end of file diff --git a/components/TimeseriesChart/types.ts b/components/TimeseriesChart/types.ts new file mode 100644 index 0000000..1ed48e7 --- /dev/null +++ b/components/TimeseriesChart/types.ts @@ -0,0 +1,3 @@ +export type getTimeseriesChartProps = { + id: string +} \ No newline at end of file diff --git a/utils/data/service.ts b/utils/data/service.ts index da32d05..8a8ea63 100644 --- a/utils/data/service.ts +++ b/utils/data/service.ts @@ -244,6 +244,30 @@ export class DataService { this.tooltipResults[id] = mappedTooltipContent } + async getTimeseries( + id: string + ) { + if (this.tooltipResults[id]) { + return this.tooltipResults[id] + } + let data: any[] = [] + for (let i = 0; i < this.config.length; i++) { + const c = this.config[i] + if (!c) { + continue + } + if (!c.columns?.length) { + continue + } + const query = `SELECT * FROM ${this.getFromQueryString(c.filename)} WHERE "${c.id}" = '${id}'` + console.log(query) + const result = await this.runQuery(query, true) + data.push(JSON.parse(JSON.stringify(result))) + } + console.log(data) + return data + } + setCompleteCallback(cb: (s: string) => void) { this.completeCallback = cb this.complete.forEach(cb)