2023-06-22 19:39:49 +03:00
|
|
|
import { Component } 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
|
|
|
|
2023-08-03 00:03:48 +03:00
|
|
|
export const CityResult: Component<{ city: string, query: DataQuery, result: any }> = ({ city, query, result }) => {
|
2023-06-22 19:39:49 +03:00
|
|
|
return (
|
|
|
|
|
<div class="result-item">
|
|
|
|
|
<h4>{ city }</h4>
|
|
|
|
|
{
|
2023-08-03 00:03:48 +03:00
|
|
|
isDateNumber(result)
|
2024-01-15 23:22:45 +02:00
|
|
|
? <CityChart city={()=>city} data={()=>result} query={()=>query}/>
|
2023-08-03 00:03:48 +03:00
|
|
|
: result
|
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;
|
|
|
|
|
}
|