Skip to content

Commit

Permalink
fix linter
Browse files Browse the repository at this point in the history
  • Loading branch information
thadk committed Nov 22, 2023
1 parent c945e6a commit a040a8f
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 53 deletions.
33 changes: 17 additions & 16 deletions heat-stack/app/components/WeatherExample.tsx
Original file line number Diff line number Diff line change
@@ -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<typeof loader>()
if (!one_loader.weather) {
return <div>Loading weather...</div>
}
const time: string = one_loader.weather.daily?.time[0]
const temp: number = one_loader.weather.daily?.temperature_2m_max[0]

const one_loader = useLoaderData<typeof loader>();
if (!one_loader.weather) {
return <div>Loading weather...</div>;
}
const time: string = one_loader.weather.daily?.time[0]
const temp: number = one_loader.weather.daily?.temperature_2m_max[0]

return (
<div>
<span>time/temp first item: {time}/{temp}</span>
</div>
);
return (
<div>
<span>
time/temp first item: {time}/{temp}
</span>
</div>
)
}
79 changes: 42 additions & 37 deletions heat-stack/app/root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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:
Expand All @@ -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 [
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -235,17 +240,17 @@ function Document({
theme?: Theme
env?: Record<string, string>
}) {
const [output, setOutput] = useState<string | null>('(loading python...)');
const [output, setOutput] = useState<string | null>('(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 (
<html lang="en" className={`${theme} h-full overflow-x-hidden`}>
<head>
Expand All @@ -256,21 +261,21 @@ function Document({
<Links />
</head>
<body className="bg-background text-foreground">
<div>
<div>Output:</div>
{output}
</div>
<WeatherExample />
{children}
<script
nonce={nonce}
dangerouslySetInnerHTML={{
__html: `window.ENV = ${JSON.stringify(env)}`,
}}
/>
<ScrollRestoration nonce={nonce} />
<Scripts nonce={nonce} />
<LiveReload nonce={nonce} />
<div>
<div>Output:</div>
{output}
</div>
<WeatherExample />
{children}
<script
nonce={nonce}
dangerouslySetInnerHTML={{
__html: `window.ENV = ${JSON.stringify(env)}`,
}}
/>
<ScrollRestoration nonce={nonce} />
<Scripts nonce={nonce} />
<LiveReload nonce={nonce} />
</body>
</html>
)
Expand Down

0 comments on commit a040a8f

Please sign in to comment.