diff --git a/heat-stack/app/components/WeatherExample.tsx b/heat-stack/app/components/WeatherExample.tsx index 01fbb8b6..63be69c8 100644 --- a/heat-stack/app/components/WeatherExample.tsx +++ b/heat-stack/app/components/WeatherExample.tsx @@ -1,22 +1,23 @@ -import { loader } from "#app/root.tsx"; -import test from "@playwright/test"; -import { json } from "@remix-run/node"; // or cloudflare/deno -import { useLoaderData } from "@remix-run/react"; +import { useLoaderData } from '@remix-run/react' +import { type loader } from '#app/root.tsx' +// import test from "@playwright/test"; +// import { json } from "@remix-run/node"; // or cloudflare/deno // weather `loader` is in root.tsx export function WeatherExample() { + const one_loader = useLoaderData() + if (!one_loader.weather) { + return
Loading weather...
+ } + const time: string = one_loader.weather.daily?.time[0] + const temp: number = one_loader.weather.daily?.temperature_2m_max[0] - const one_loader = useLoaderData(); - if (!one_loader.weather) { - return
Loading weather...
; - } - const time: string = one_loader.weather.daily?.time[0] - const temp: number = one_loader.weather.daily?.temperature_2m_max[0] - - return ( -
- time/temp first item: {time}/{temp} -
- ); + return ( +
+ + time/temp first item: {time}/{temp} + +
+ ) } diff --git a/heat-stack/app/root.tsx b/heat-stack/app/root.tsx index 9225a479..31b38d0e 100644 --- a/heat-stack/app/root.tsx +++ b/heat-stack/app/root.tsx @@ -24,8 +24,14 @@ import { useSubmit, } from '@remix-run/react' import { withSentry } from '@sentry/remix' -import { Suspense, lazy, useEffect, useRef, useState } from 'react' -import { object, z } from 'zod' + +import * as pyodideModule from 'pyodide' + +import { useEffect, useRef, useState } from 'react' +import { z } from 'zod' + +import engine from '../../rules-engine/src/rules_engine/engine.py' + import { Confetti } from './components/confetti.tsx' import { GeneralErrorBoundary } from './components/error-boundary.tsx' import { ErrorList } from './components/forms.tsx' @@ -60,11 +66,10 @@ import { makeTimings, time } from './utils/timing.server.ts' import { getToast } from './utils/toast.server.ts' import { useOptionalUser, useUser } from './utils/user.ts' +// eslint-disable-next-line import/order import { WeatherExample } from './components/WeatherExample.tsx' -import type { Weather } from './WeatherExample.d.ts'; - -import * as pyodideModule from 'pyodide' -import engine from '../../rules-engine/src/rules_engine/engine.py'; +// eslint-disable-next-line import/consistent-type-specifier-style +import type { Weather } from './WeatherExample.d.ts' const getPyodide = async () => { // public folder: @@ -74,13 +79,12 @@ const getPyodide = async () => { } const runPythonScript = async () => { - const pyodide: any = await getPyodide(); + const pyodide: any = await getPyodide() // console.log(engine); - await pyodide.loadPackage("numpy") - await pyodide.runPythonAsync(engine); - return pyodide; -}; - + await pyodide.loadPackage('numpy') + await pyodide.runPythonAsync(engine) + return pyodide +} export const links: LinksFunction = () => { return [ @@ -159,8 +163,9 @@ export async function loader({ request }: DataFunctionArgs) { const { confettiId, headers: confettiHeaders } = getConfetti(request) // Weather station data - const w_href: string = 'https://archive-api.open-meteo.com/v1/archive?latitude=52.52&longitude=13.41&daily=temperature_2m_max&timezone=America%2FNew_York&start_date=2022-01-01&end_date=2023-08-30&temperature_unit=fahrenheit'; - const w_res: Response = await fetch(w_href); + const w_href: string = + 'https://archive-api.open-meteo.com/v1/archive?latitude=52.52&longitude=13.41&daily=temperature_2m_max&timezone=America%2FNew_York&start_date=2022-01-01&end_date=2023-08-30&temperature_unit=fahrenheit' + const w_res: Response = await fetch(w_href) const weather: Weather = (await w_res.json()) as Weather return json( @@ -235,17 +240,17 @@ function Document({ theme?: Theme env?: Record }) { - const [output, setOutput] = useState('(loading python...)'); + const [output, setOutput] = useState('(loading python...)') useEffect(() => { const run = async () => { - const pyodide: any = await runPythonScript(); - // console.log(pyodide); - const result = await pyodide.runPythonAsync("hdd(57, 60)"); - setOutput(result); - }; - run(); - }, []); + const pyodide: any = await runPythonScript() + // console.log(pyodide); + const result = await pyodide.runPythonAsync('hdd(57, 60)') + setOutput(result) + } + run() + }, []) return ( @@ -256,21 +261,21 @@ function Document({ -
-
Output:
- {output} -
- - {children} -