Files
WeatherTool/web/src/pages/cities/result/GridResult.tsx
T

36 lines
1.2 KiB
TypeScript
Raw Normal View History

2024-02-08 22:48:27 +02:00
import { Component, Match, Switch } from "solid-js";
2025-03-14 11:31:47 +02:00
import { CityChart } from "../../../components/chart/CityChart";
import { DataQuery } from "../helpers";
2023-06-22 19:39:49 +03:00
export const GridResult: Component<{ city: string, query: DataQuery, result: any }> = ({ city, query, result }) => {
2023-06-22 19:39:49 +03:00
return (
<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;
}