diff --git a/frontend/.yarn/install-state.gz b/frontend/.yarn/install-state.gz deleted file mode 100644 index 6ddc82f..0000000 Binary files a/frontend/.yarn/install-state.gz and /dev/null differ diff --git a/frontend/index.html b/frontend/index.html index dee24f9..82945ac 100644 --- a/frontend/index.html +++ b/frontend/index.html @@ -1,13 +1,13 @@ - - - - - frontend - - -
- - + + + + + weather portal + + +
+ + diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index 140c3a3..002a47d 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -1,102 +1,19 @@ -import { createSignal } from 'solid-js' -import solidLogo from './assets/solid.svg' -import viteLogo from './assets/vite.svg' -import heroImg from './assets/hero.png' -import './App.css' +// import { createSignal } from 'solid-js' +// import "./App.css"; function App() { - const [count, setCount] = createSignal(0) + // const [count, setCount] = createSignal(0) return ( <> -
-
- - Solid logo - Vite logo -
-
-

Get started

-

- Edit src/App.tsx and save to test HMR -

-
- -
- -
- -
-
- -

Documentation

-

Your questions, answered

- -
-
- -

Connect with us

-

Join the Vite community

- -
-
- -
-
+
+ - ) + ); } -export default App +export default App; diff --git a/frontend/src/assets/hero.png b/frontend/src/assets/hero.png deleted file mode 100644 index cc51a3d..0000000 Binary files a/frontend/src/assets/hero.png and /dev/null differ diff --git a/frontend/src/assets/solid.svg b/frontend/src/assets/solid.svg deleted file mode 100644 index 025aa30..0000000 --- a/frontend/src/assets/solid.svg +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/frontend/src/assets/vite.svg b/frontend/src/assets/vite.svg deleted file mode 100644 index 5101b67..0000000 --- a/frontend/src/assets/vite.svg +++ /dev/null @@ -1 +0,0 @@ -Vite diff --git a/frontend/src/useWebSocket.ts b/frontend/src/useWebSocket.ts new file mode 100644 index 0000000..69657dd --- /dev/null +++ b/frontend/src/useWebSocket.ts @@ -0,0 +1,70 @@ +import { createSignal, createEffect, onCleanup } from 'solid-js' + +export interface SensorReading { + sensor: + | 'Temperature' + | 'Humidity' + | 'Pressure' + | 'ParticalMatterOne' + | 'ParticalMatterTwoPointFive' + | 'ParticalMatterTen' + value: number +} + +export interface WebSocketState { + isConnected: boolean + readings: SensorReading[] + error: string | null +} + +export function useWebSocket(url: string) { + const [state, setState] = createSignal({ + isConnected: false, + readings: [], + error: null, + }) + + createEffect(() => { + const ws = new WebSocket(url) + + ws.onopen = () => { + setState((s) => ({ ...s, isConnected: true, error: null })) + } + + ws.onmessage = (event) => { + try { + const reading: SensorReading = JSON.parse(event.data) + setState((s) => ({ + ...s, + readings: [reading, ...s.readings.slice(0, 99)], // Keep last 100 + })) + } catch (e) { + setState((s) => ({ + ...s, + error: `Failed to parse message: ${e}`, + })) + } + } + + ws.onerror = () => { + setState((s) => ({ + ...s, + isConnected: false, + error: 'WebSocket connection error', + })) + } + + ws.onclose = () => { + setState((s) => ({ + ...s, + isConnected: false, + })) + } + + onCleanup(() => { + ws.close() + }) + }) + + return state +}