2024-02-08 22:48:27 +02:00
|
|
|
import { Component, Match, Switch } from "solid-js";
|
2024-01-15 23:22:45 +02:00
|
|
|
|
|
|
|
|
import { CityChart } from "../../components/chart/CityChart";
|
2023-08-03 00:03:48 +03:00
|
|
|
import { DataQuery } from "../helpers";
|
2023-06-22 19:39:49 +03:00
|
|
|
|
2024-01-25 16:19:59 +02:00
|
|
|
export const GridResult: Component<{ city: string, query: DataQuery, result: any }> = ({ city, query, result }) => {
|
2023-06-22 19:39:49 +03:00
|
|
|
return (
|
2024-01-25 16:19:59 +02:00
|
|
|
<div class="item">
|
2023-06-22 19:39:49 +03:00
|
|
|
<h4>{ city }</h4>
|
2024-02-08 22:48:27 +02:00
|
|
|
<Switch fallback={<p>{ result }</p>}>
|
|
|
|
|
<Match when={query.field === "phenomena"}>
|
|
|
|
|
{ result.join(", ") }
|
|
|
|
|
</Match>
|
|
|
|
|
<Match when={isDateNumber(result)}>
|
|
|
|
|
<CityChart city={()=>city} data={()=>result} query={()=>query}/>
|
|
|
|
|
</Match>
|
|
|
|
|
</Switch>
|
2023-06-22 19:39:49 +03:00
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function isDateNumber(value: unknown): value is [string, number | null][] {
|
|
|
|
|
if (!Array.isArray(value)) return false;
|
|
|
|
|
for (let i = 0; i < value.length; i++) {
|
|
|
|
|
let item = value[i];
|
2023-08-03 22:54:02 +03:00
|
|
|
if (
|
|
|
|
|
!Array.isArray(item)
|
|
|
|
|
|| item.length !== 2
|
|
|
|
|
|| typeof item[0] !== "string"
|
|
|
|
|
|| (typeof item[1] !== "number" && item[1] !== null)
|
|
|
|
|
) {
|
2023-06-22 19:39:49 +03:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|