Skip to content

Commit

Permalink
useContext for settings and light state
Browse files Browse the repository at this point in the history
  • Loading branch information
sidoh committed Oct 20, 2024
1 parent 9b4621a commit 9591654
Show file tree
Hide file tree
Showing 17 changed files with 691 additions and 152 deletions.
4 changes: 2 additions & 2 deletions dist/bundle.css.gz.h

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions dist/bundle.js.gz.h

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions dist/index.html.gz.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#define index_html_gz_len 1821
static const char index_html_filename[] = "/dist/index.b9c8026f.html";
static const char index_html_gz[] PROGMEM = {31,139,8,0,0,0,0,0,2,10,237,88,91,115,218,200,18,126,79,213,254,135,89,157,108,149,40,97,141,236,128,193,216,184,206,32,225,216,9,198,144,216,187,235,108,109,109,132,52,186,24,33,113,70,3,2,187,248,239,167,71,18,32,1,78,242,112,222,78,84,197,92,187,123,190,238,233,203,20,111,46,126,53,238,244,251,199,65,23,121,124,18,92,190,185,16,29,10,204,208,109,75,52,148,196,2,53,109,232,38,148,155,200,242,76,22,83,222,150,30,238,175,142,154,210,122,57,52,39,180,45,205,125,154,76,35,198,37,100,69,33,167,33,144,37,190,205,189,182,77,231,190,69,143,210,73,21,249,161,207,125,51,56,138,45,51,160,237,99,85,19,98,184,207,3,122,121,235,247,124,215,227,232,122,54,186,192,217,210,155,139,192,15,199,200,99,212,105,75,182,201,205,150,63,49,93,138,23,71,62,156,114,62,50,99,122,90,171,18,66,58,132,116,73,23,90,209,235,164,19,117,134,132,92,185,48,213,69,67,134,162,185,33,235,253,245,215,37,229,175,60,199,239,154,125,210,49,20,61,49,240,211,48,38,103,211,135,59,210,249,52,195,48,191,30,38,68,113,7,140,12,106,183,35,66,190,52,157,38,209,23,163,51,152,191,31,39,250,31,152,68,196,120,124,82,200,160,126,166,15,141,198,21,25,19,29,227,144,124,120,252,136,135,100,136,147,26,177,220,57,38,131,198,177,158,232,159,141,65,147,40,100,252,8,115,6,106,244,177,162,17,188,232,90,100,112,204,244,132,220,226,104,76,12,71,185,38,55,184,1,42,245,112,61,38,198,224,172,78,136,246,0,120,106,216,133,249,159,76,1,75,220,97,215,8,116,12,242,230,90,159,144,119,184,155,116,106,93,192,215,76,88,131,12,180,27,10,242,27,131,26,25,57,205,30,33,179,15,56,209,127,55,230,64,239,89,239,137,126,173,24,110,231,25,39,49,232,215,192,164,115,175,124,25,146,91,125,174,17,211,13,49,249,112,143,141,161,161,116,7,226,252,70,76,238,28,108,16,3,27,11,192,235,158,192,77,212,250,216,237,104,216,77,136,241,229,25,248,123,96,47,192,223,121,36,74,242,159,91,242,243,251,249,253,252,254,207,63,200,115,165,239,33,134,70,233,39,132,188,127,190,217,172,222,60,105,228,163,71,200,181,215,204,87,34,209,244,211,97,39,73,83,52,252,10,28,233,55,33,34,229,27,241,83,97,237,115,47,121,5,74,231,54,236,151,87,216,173,145,252,222,251,84,174,5,134,241,96,191,166,205,7,163,64,171,63,212,68,247,209,40,171,120,165,11,26,75,12,79,11,181,230,207,28,132,168,73,127,244,92,98,146,45,206,222,71,168,90,119,67,33,167,86,6,211,25,15,54,227,65,29,108,96,76,190,0,95,115,12,118,234,205,1,167,238,40,192,251,140,33,221,14,176,176,145,163,64,115,141,221,124,14,213,6,232,67,60,206,233,141,229,61,204,235,19,43,151,71,218,18,98,52,104,75,162,204,74,136,47,167,80,225,139,165,87,66,24,138,115,204,151,162,72,35,244,175,32,50,109,63,116,209,11,76,16,154,70,49,84,249,40,108,33,199,95,80,251,60,93,228,209,180,133,234,218,111,217,44,160,14,47,76,57,51,195,216,137,216,164,149,13,3,147,83,249,8,182,171,72,180,149,140,202,129,151,197,81,236,63,211,22,58,169,77,23,133,69,199,156,248,193,178,133,8,131,199,69,21,197,32,226,40,166,204,119,4,205,234,205,5,206,161,94,196,22,243,167,252,82,118,102,161,37,32,34,185,130,94,126,1,34,80,42,230,200,178,195,14,60,42,80,27,73,30,231,211,184,133,49,44,169,79,177,77,3,127,206,212,144,114,236,122,56,246,237,200,195,52,158,54,79,78,79,255,129,163,197,195,229,31,111,54,250,119,66,71,39,56,109,108,63,230,120,78,89,12,167,196,24,94,58,170,134,165,243,237,81,142,31,208,24,14,250,235,151,84,141,151,172,67,169,177,91,72,74,1,199,30,165,92,170,174,183,0,202,192,228,94,107,3,83,65,210,104,22,218,1,85,173,56,222,210,5,17,188,174,50,74,41,133,177,38,162,103,167,141,145,53,42,83,103,6,157,138,183,221,77,200,101,169,249,174,126,44,85,209,177,86,201,73,86,213,87,32,166,182,252,33,120,79,63,128,78,51,71,141,51,141,154,37,226,93,112,39,39,154,86,175,31,128,247,55,152,86,244,155,139,181,24,5,39,250,188,49,99,15,94,146,178,120,73,86,214,138,100,247,144,190,48,219,200,142,172,217,4,158,173,106,198,215,13,168,152,201,146,216,150,42,231,25,135,152,168,16,24,194,63,10,23,84,220,21,39,192,182,232,242,101,70,249,140,133,233,110,186,178,58,12,52,53,166,28,51,107,7,95,102,229,111,32,204,175,97,141,49,155,170,32,8,120,160,45,47,219,212,161,12,54,56,155,209,50,190,140,224,32,66,206,150,61,8,240,7,22,200,51,38,194,11,46,165,42,248,216,82,143,102,161,0,167,85,209,196,92,124,130,37,63,245,234,250,70,139,92,188,67,185,229,9,246,202,250,106,85,238,209,80,150,25,132,17,40,74,43,168,125,185,117,49,132,124,7,201,191,174,55,213,104,92,41,110,130,15,122,44,74,80,72,19,212,101,44,98,178,212,167,60,137,216,24,173,89,80,98,198,40,140,56,138,182,247,151,186,203,118,152,67,27,176,104,226,195,25,192,25,5,115,186,69,180,225,90,109,65,91,166,208,67,166,226,208,67,144,11,86,185,40,152,100,7,189,184,218,8,124,62,49,89,40,127,21,52,75,145,62,223,190,128,129,86,72,126,251,82,16,163,160,227,21,126,251,178,149,181,170,124,45,42,180,209,227,187,215,4,146,138,215,84,178,10,162,1,216,236,128,137,83,77,15,217,111,85,249,150,179,92,65,122,147,69,142,219,113,103,63,54,232,156,6,209,84,56,175,136,163,41,139,236,89,202,42,161,118,27,22,236,237,254,58,178,132,97,75,140,5,115,238,43,47,78,85,55,89,166,154,102,90,53,51,6,184,169,182,86,123,87,229,87,4,229,89,109,95,204,218,21,132,23,108,205,243,195,56,234,27,159,218,0,58,100,78,81,89,7,80,120,229,141,202,1,133,58,53,99,12,204,32,140,124,19,218,116,33,34,48,79,128,59,188,125,186,72,201,228,130,201,132,57,247,36,92,182,179,146,164,6,52,116,185,87,114,216,77,234,113,41,207,243,78,103,121,99,67,118,204,234,190,84,81,211,116,168,66,62,159,6,230,82,220,107,24,133,84,58,223,13,182,109,72,173,209,22,235,33,202,49,252,181,139,238,239,243,45,249,158,131,109,207,248,78,74,249,110,82,57,144,86,174,76,56,194,134,215,75,106,205,20,158,84,142,190,213,129,80,220,28,49,10,162,145,92,10,180,125,184,130,102,31,106,102,21,8,100,48,202,195,167,94,158,245,239,70,79,212,226,48,207,184,74,64,132,99,208,236,118,10,230,90,171,157,122,159,168,220,89,148,21,202,215,158,17,114,33,112,240,193,34,42,146,120,217,2,89,36,29,58,37,175,77,223,61,33,171,126,251,146,203,122,108,252,80,252,45,165,154,211,41,13,109,221,243,3,91,206,5,150,185,119,189,72,81,202,246,42,133,199,107,119,244,173,132,191,77,228,233,182,252,245,128,183,180,32,171,23,19,201,234,107,53,203,169,255,43,172,219,236,145,13,48,70,159,185,201,56,90,63,202,211,144,202,115,199,190,152,156,111,99,90,211,182,187,115,24,244,224,105,70,67,10,33,96,220,221,234,217,127,122,34,238,168,13,175,47,185,104,137,109,138,202,4,138,110,85,73,103,240,240,206,30,220,48,202,255,74,28,69,246,18,58,219,159,35,223,110,75,83,96,148,10,243,117,70,185,236,101,3,85,85,47,224,45,61,23,18,242,46,151,128,179,255,44,255,11,163,229,130,173,197,20,0,0};
#define index_html_gz_len 1834
static const char index_html_filename[] = "/dist/index.55f2c33c.html";
static const char index_html_gz[] PROGMEM = {31,139,8,0,0,0,0,0,2,10,237,88,223,115,218,184,22,126,103,166,255,131,214,183,59,99,198,196,34,41,4,66,112,230,30,108,210,164,37,4,210,102,119,211,157,157,173,177,133,81,48,50,87,18,56,36,195,255,126,71,182,1,59,33,109,31,246,109,171,7,235,215,209,209,119,62,29,157,163,113,169,253,139,115,109,127,190,27,116,209,68,206,194,179,82,91,85,40,116,89,96,105,132,105,106,128,184,254,89,169,61,35,210,69,222,196,229,130,72,75,187,253,124,126,208,212,54,195,204,157,17,75,91,82,18,207,35,46,53,228,69,76,18,38,45,45,166,190,156,88,62,89,82,143,28,36,157,10,162,140,74,234,134,7,194,115,67,98,29,154,85,165,70,82,25,146,179,43,218,163,193,68,162,139,197,168,141,211,161,82,59,164,108,138,38,156,140,45,205,119,165,219,162,51,55,32,248,225,128,122,17,59,29,185,130,28,215,42,0,208,1,232,66,183,3,160,106,27,58,81,103,8,112,30,0,128,173,62,48,84,159,75,216,204,111,74,23,138,165,216,199,239,154,125,232,56,134,29,59,248,126,40,224,100,126,123,13,157,155,5,142,29,124,49,140,193,8,6,28,6,181,171,17,192,151,230,184,9,246,195,232,4,6,181,247,211,216,254,29,67,4,206,221,189,1,131,250,137,61,116,26,231,48,5,27,99,6,31,238,62,226,33,12,113,92,3,47,88,98,24,52,14,237,216,254,228,12,154,96,192,244,14,6,13,222,1,232,99,163,10,248,161,235,193,224,144,219,49,92,225,104,10,206,216,184,128,75,220,176,3,232,225,186,0,103,112,82,7,168,222,226,216,169,225,64,128,243,7,55,160,3,215,56,112,66,27,55,193,88,86,251,0,239,112,55,238,212,186,227,38,52,99,222,128,65,245,146,0,244,27,131,26,140,198,205,30,192,226,3,142,237,223,156,101,19,140,137,247,30,236,11,195,9,58,143,56,22,96,4,13,12,157,207,198,151,33,92,217,203,42,184,1,195,240,225,51,118,134,142,209,29,168,253,27,2,174,199,216,1,7,59,15,85,192,193,17,64,167,214,199,65,167,138,131,24,156,47,143,24,58,189,5,86,248,59,119,96,196,255,187,130,159,229,103,249,89,254,229,101,122,87,236,223,10,0,48,250,49,192,251,199,203,237,232,229,125,21,62,78,0,46,38,205,108,36,82,159,126,210,236,196,73,136,6,128,220,138,164,204,64,133,124,71,220,231,198,62,245,226,87,160,116,174,88,191,56,194,175,156,248,183,222,77,49,23,56,206,173,255,154,53,31,156,156,172,125,91,83,213,71,167,104,226,185,173,100,60,213,60,206,229,154,63,50,16,42,39,253,222,11,192,133,29,206,222,199,33,192,245,80,233,169,21,193,116,166,131,109,123,80,199,0,206,236,75,12,208,156,54,1,122,75,31,192,30,27,67,128,71,124,5,48,192,138,163,177,1,0,23,56,200,250,206,160,25,3,48,60,205,228,157,213,231,24,160,62,243,50,125,96,105,136,147,208,210,84,154,213,144,92,205,137,165,229,83,175,134,240,89,169,45,228,74,37,105,132,254,19,70,174,79,89,128,158,74,8,33,52,143,4,149,52,98,45,52,166,15,196,63,77,6,101,52,111,161,122,245,215,180,23,146,177,204,117,37,119,153,24,71,124,214,74,155,161,43,137,126,80,175,254,90,65,234,91,78,165,198,17,147,7,130,62,146,22,58,170,205,31,114,131,99,119,70,195,85,11,1,167,110,88,65,194,101,226,64,16,78,199,74,102,93,106,227,12,106,91,120,156,206,229,153,62,94,48,79,65,68,122,25,61,189,41,33,245,106,17,18,121,62,235,184,130,32,11,105,19,41,231,162,133,177,231,51,243,94,248,36,164,75,110,50,34,113,48,193,130,250,209,4,19,49,111,30,29,31,255,61,163,161,122,184,252,61,89,140,254,27,147,209,17,78,62,62,21,18,47,9,23,52,98,2,31,154,85,243,16,107,167,187,173,198,52,36,2,89,232,207,55,137,25,79,105,133,18,178,91,72,75,0,139,9,33,82,171,108,166,60,159,13,92,57,105,109,97,26,72,27,45,152,31,18,211,19,98,39,23,70,158,27,166,146,90,2,99,35,68,78,142,27,35,111,84,148,78,9,157,171,183,221,37,147,186,214,124,215,108,104,21,116,88,45,103,34,235,202,43,16,19,46,127,8,222,253,15,160,243,143,235,222,241,113,163,86,16,126,14,238,232,168,90,63,174,237,129,247,215,233,155,146,170,183,7,235,113,226,74,242,105,75,99,143,178,169,174,94,146,229,141,33,233,57,36,47,76,11,249,145,183,152,17,38,205,116,93,55,36,170,167,107,106,90,43,159,166,43,84,199,228,36,84,254,145,59,160,252,172,218,1,89,201,147,53,27,230,68,46,56,75,102,147,145,245,126,160,9,153,186,224,222,51,124,41,203,223,64,152,29,195,6,99,218,53,5,247,144,133,4,247,138,195,62,25,19,142,44,36,249,130,20,241,165,2,123,17,74,190,234,69,174,127,203,67,125,193,213,245,162,143,164,162,214,241,149,29,45,152,2,87,173,160,153,251,112,67,36,167,137,87,215,183,86,100,234,199,68,122,19,181,188,188,57,90,83,78,8,211,117,78,196,60,98,130,148,145,117,182,115,49,132,232,24,233,191,108,38,205,104,90,206,79,34,36,39,60,138,17,35,49,234,114,30,113,93,235,19,25,71,124,138,54,75,80,236,10,196,34,137,162,221,249,37,238,178,107,102,208,6,60,154,81,65,76,78,68,20,46,201,14,209,118,213,122,7,218,115,149,29,58,81,155,238,131,156,99,165,157,163,228,25,122,117,180,81,72,204,216,229,76,255,170,100,86,42,124,190,125,90,240,112,141,244,183,79,57,53,6,58,92,227,183,79,59,93,235,242,215,188,65,91,59,190,123,76,6,58,204,31,83,129,21,68,66,65,246,81,156,88,186,143,191,117,249,91,206,114,78,67,162,171,24,247,204,157,169,112,200,146,132,209,92,57,175,186,71,115,30,249,139,100,169,134,44,203,66,154,191,155,223,220,44,69,108,97,97,142,206,151,198,171,93,205,109,148,169,36,145,214,76,201,168,86,80,117,99,246,115,147,95,81,148,69,181,151,106,54,174,160,188,96,71,207,15,227,168,111,125,106,11,104,31,157,42,179,14,220,128,232,91,147,67,34,145,183,224,156,48,169,72,190,100,62,121,80,55,48,11,128,207,214,246,201,67,34,166,231,40,83,116,190,208,112,102,165,41,201,12,9,11,228,164,224,176,219,208,19,16,153,197,157,206,234,210,215,181,44,239,107,101,51,9,135,166,79,197,60,116,87,234,92,89,196,136,118,250,252,178,237,174,212,6,109,62,31,162,12,195,159,207,209,253,117,186,19,127,225,96,187,61,190,19,82,190,27,84,246,132,149,115,151,134,196,71,50,74,216,76,224,105,197,219,183,222,115,21,183,91,140,194,104,164,23,46,218,75,184,74,230,37,212,148,149,5,87,201,230,246,166,151,69,253,235,209,61,241,228,237,77,47,93,85,0,162,28,131,164,167,147,163,107,99,118,226,125,42,115,167,183,44,151,190,94,144,144,41,65,214,254,36,170,130,120,145,129,244,38,237,219,37,203,77,223,221,33,205,126,47,53,23,237,216,250,161,250,45,101,186,243,57,97,190,61,161,161,175,103,10,139,171,159,123,145,97,20,249,42,92,143,215,206,232,91,1,127,23,200,147,105,253,235,30,111,105,161,183,79,249,64,178,254,90,73,99,234,63,133,117,23,61,210,6,198,232,147,116,185,68,155,71,121,114,165,178,216,241,82,77,182,110,75,173,235,251,221,37,97,178,71,133,36,140,112,93,115,174,175,236,244,159,158,186,119,196,215,42,72,207,51,177,11,81,169,66,85,173,203,73,175,141,179,7,119,169,141,179,95,137,163,200,95,157,149,218,62,93,34,234,91,218,220,13,136,150,235,111,34,202,89,47,109,152,166,217,198,62,93,42,13,89,149,105,192,233,63,203,255,3,193,15,247,154,197,20,0,0};
14 changes: 2 additions & 12 deletions web2/components/light/light-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,11 @@ import { api } from "@/lib/api";
import { z } from "zod";
import { useToast } from "@/hooks/use-toast";
import { useWebSocketContext } from "@/lib/websocket";
import { useLightState } from "@/lib/light-state";

export function LightList() {
const { lightStates, dispatch } = useLightState();
const { lastMessage } = useWebSocketContext();
const [lightStates, dispatch] = useReducer(reducer, {
lights: [],
isLoading: true,
});
const [isDeleteMode, setIsDeleteMode] = useState(false);
const [showConfirmation, setShowConfirmation] = useState(false);
const [lightToDelete, setLightToDelete] = useState<z.infer<
Expand All @@ -37,14 +35,6 @@ export function LightList() {
const [isAddLightDialogOpen, setIsAddLightDialogOpen] = useState(false);
const toast = useToast();

useEffect(() => {
const loadInitialState = async () => {
const response = await api.getGateways();
dispatch({ type: "SET_LIGHTS", lights: response });
};
loadInitialState();
}, []);

useEffect(() => {
if (lastMessage && lastMessage.t == "packet") {
dispatch({
Expand Down
5 changes: 4 additions & 1 deletion web2/components/ui/main-nav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@ import * as React from "react";
import { cn } from "@/lib/utils";
import { NavLink, Link } from "@/components/ui/link";
import { Settings } from "lucide-react";
import { useSettings } from "@/lib/settings";

export function MainNav({
className,
...props
}: React.HTMLAttributes<HTMLElement>) {
const { settings, isLoading } = useSettings();

return (
<div className="w-full">
<div className="flex h-16 items-center px-4 justify-between">
Expand All @@ -15,7 +18,7 @@ export function MainNav({
className="hover:text-slate-900 dark:hover:text-slate-100 text-slate-900 dark:text-slate-100 text-lg font-bold"
href="#/dashboard"
>
MiLight Hub
{!isLoading ? `MiLight Hub: ${settings?.hostname}` : "MiLight Hub"}
</Link>
<nav
className={cn(
Expand Down
98 changes: 49 additions & 49 deletions web2/dist/versions/1.0.0/bundle.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions web2/dist/versions/1.0.0/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
{
type: "script",
cdnPath: cdnBase + "bundle.js",
localPath: "dist/bundle.0ab790ea.js",
size: parseInt("220055", 10),
localPath: "dist/bundle.6b07b0eb.js",
size: parseInt("219462", 10),
},
];

Expand Down
1 change: 1 addition & 0 deletions web2/dist/versions/1.0.1/bundle.css

Large diffs are not rendered by default.

327 changes: 327 additions & 0 deletions web2/dist/versions/1.0.1/bundle.js

Large diffs are not rendered by default.

Loading

0 comments on commit 9591654

Please sign in to comment.