Files
WeatherTool/web/src/harmonie/GribFile.tsx
T

35 lines
922 B
TypeScript
Raw Normal View History

2025-02-02 23:33:15 +02:00
import { Accessor, Component, createSignal } from 'solid-js'
import styles from './harmonie.module.css'
import { apiHost } from '../consts'
export const GribFile: Component<{
name: string,
isActive: Accessor<boolean>,
onClick: (name: string) => void,
}> = ({ name, isActive, onClick }) => {
const [getStructure, setStructure] = createSignal<any[]>([])
function onFileClick() {
onClick(name)
if (getStructure().length === 0) {
fetch(`${apiHost}/api/show/grib/${name}`)
.then(re => re.json())
.then(setStructure)
}
}
return <li
class={isActive() ? styles.active : ''}
onClick={onFileClick}
>
<div class={styles.name}>{ name }</div>
<ul class={styles.meteoParams}>
{ getStructure().map(grib =>
<li>{ grib.title }</li>
)}
</ul>
</li>
}