import with_main_layout from "../../layouts/with_main_layout.ts.tsx"; import useLocalStorageState from 'use-local-storage-state'; // install via npm import {Client, WeatherForecast} from "../../ApiCient.ts"; import {FontAwesomeIcon} from "@fortawesome/react-fontawesome"; import {faDownload, faTrash} from "@fortawesome/free-solid-svg-icons"; import {useState} from "react"; import WeatherGrid from "./WeatherGrid.tsx"; import {useSignalR} from "../../signalr/SignalRHelper.ts"; function WeatherPage() { // Use the hook to persist your weather data. It will default to null. const [weatherData, setWeatherData] = useLocalStorageState('WeatherPage-Forecast', {defaultValue: [],}); const [loading, setLoading] = useState(false); const [currentState, setCurrentState] = useState(null); const {subscribe} = useSignalR('http://localhost:5175', 'WeatherUpdateHub'); const fetchWeatherData = async () => { const apiClient = new Client(); try { const progressCleanup = subscribe('ProgressUpdate', (_, message) => { setCurrentState(message); }); setLoading(true); const data = await apiClient.getWeatherForecast(); setWeatherData(data); setLoading(false); progressCleanup(); setCurrentState(null); } catch (error) { console.error("Error fetching weather data:", error); } }; return (
Weather Data
{loading ?
{/*

Progress: {currentState ? JSON.parse(currentState).percentage : 0}% - {currentState ? JSON.parse(currentState).message : ''}

*/} {(() => { const percentage = currentState ? JSON.parse(currentState).percentage : 0; return (
{percentage}%
); })()}
: !weatherData || weatherData.length === 0 ? (

No weather data, please request it!

) : ( )}
); } export const PageWithLayout = with_main_layout(WeatherPage); export default PageWithLayout;