Compare commits

...
3 Commits
Author SHA1 Message Date
ari cd1b4e8e2b ensuring scroll 2022-07-31 22:22:21 -04:00
ari 2b4c64c94b added ignore 2022-07-29 21:43:27 -04:00
ari 067f5fa642 added delay to save 2022-07-29 21:42:50 -04:00
5 changed files with 50 additions and 24 deletions

No files matched your search

+6 -2
View File
@@ -2,13 +2,17 @@
"version": "2.0.0", "version": "2.0.0",
"tasks": [ "tasks": [
{ {
"icon": {
"id": "server-environment"
},
"type": "shell", "type": "shell",
"label": "Docker: Server", "label": "Docker: Start Server",
"group": "none", "group": "none",
"command": [".vscode/bin/start-docker-server.sh"], "command": [".vscode/bin/start-docker-server.sh"],
"runOptions": { "runOptions": {
"runOn": "folderOpen" "runOn": "folderOpen"
} },
"problemMatcher": []
}, },
{ {
"type": "npm", "type": "npm",
@@ -85,7 +85,10 @@ export const AutomationManagerSidebar: FC<AutomationManagerSidebarProps> = ({
<ListBoxGroup <ListBoxGroup
{...item} {...item}
key={i} key={i}
onSelect={onSelectedAutomationId} onSelect={(id) => {
onSelectedAutomationId(id);
setHidden(true);
}}
{...events} {...events}
tagsDB={tagsDB} tagsDB={tagsDB}
initialOpenState={true} initialOpenState={true}
@@ -1,6 +1,6 @@
import "./index.css"; import "./index.css";
import { FC, useState } from "react"; import { FC, useEffect, useState } from "react";
import LinearProgress from "@mui/material/LinearProgress"; import LinearProgress from "@mui/material/LinearProgress";
import Skeleton from "@mui/material/Skeleton"; import Skeleton from "@mui/material/Skeleton";
@@ -28,6 +28,11 @@ export const AutomationManager: FC<AutomationManagerProps> = ({
const snackbr = useSnackbar(); const snackbr = useSnackbar();
const [isSaving, setIsSaving] = useState(false); const [isSaving, setIsSaving] = useState(false);
useEffect(() => {
refreshAutomations();
// eslint-disable-next-line
}, []);
// handle bad states // handle bad states
if (!haEntities.ready && haEntities.error) { if (!haEntities.ready && haEntities.error) {
return ( return (
+11 -1
View File
@@ -1,5 +1,6 @@
import { Collection, Connection } from "home-assistant-js-websocket"; import { Collection, Connection } from "home-assistant-js-websocket";
import { useState, useEffect, useMemo } from "react"; import { useState, useEffect, useMemo } from "react";
import { useDelayedFunction } from "utils/useDelay";
import { useHAConnection } from "./connection"; import { useHAConnection } from "./connection";
type _HACollectionState<T> = type _HACollectionState<T> =
@@ -19,9 +20,10 @@ export const useHassCollection = <T, D extends {} = {}>(
getHACollection: (c: Connection) => Collection<T>, getHACollection: (c: Connection) => Collection<T>,
updateAdditionalProps?: (n: T | {}) => D updateAdditionalProps?: (n: T | {}) => D
): HACollectionState<T, D> => { ): HACollectionState<T, D> => {
const [state, setState] = useState<_HACollectionState<T>>({ const [state, _setState] = useState<_HACollectionState<T>>({
ready: false, ready: false,
}); });
const setState = useDelayedFunction(_setState, 500);
const conn = useHAConnection(); const conn = useHAConnection();
const collection = useMemo(() => { const collection = useMemo(() => {
if (conn.status === "loaded") { if (conn.status === "loaded") {
@@ -39,6 +41,12 @@ export const useHassCollection = <T, D extends {} = {}>(
} }
const unsub = collection.subscribe((d) => { const unsub = collection.subscribe((d) => {
if (d) { if (d) {
console.log(
"updating with",
Object.keys(d).length,
Object.fromEntries(Object.entries(d).map(([k, v]) => [k, v.state])),
getHACollection
);
setState({ setState({
ready: true, ready: true,
collection: d, collection: d,
@@ -49,6 +57,7 @@ export const useHassCollection = <T, D extends {} = {}>(
unsub(); unsub();
}; };
} }
// eslint-disable-next-line
}, [collection, state.ready]); }, [collection, state.ready]);
useEffect(() => { useEffect(() => {
@@ -60,6 +69,7 @@ export const useHassCollection = <T, D extends {} = {}>(
}); });
} }
} }
// eslint-disable-next-line
}, [conn, state]); }, [conn, state]);
if (state.ready) { if (state.ready) {
+23 -19
View File
@@ -1,24 +1,28 @@
import { useRef, useEffect } from 'react'; import { useRef, useEffect } from "react";
export const useDelayEffect = (
export const useDelayEffect = (cb: () => void, deps: any[], timeout: number) => { cb: () => void,
const fcn = useDelayedFunction(cb, timeout); deps: any[],
useEffect(() => { timeout: number
fcn() ) => {
// eslint-disable-next-line const fcn = useDelayedFunction(cb, timeout);
}, deps) useEffect(() => {
} fcn();
// eslint-disable-next-line
}, deps);
};
export const useDelayedFunction = <FcnParams extends any[]>( export const useDelayedFunction = <FcnParams extends any[]>(
cb: (...p: FcnParams) => void, timeout: number cb: (...p: FcnParams) => void,
timeout: number
) => { ) => {
const timeid = useRef<number | null>(null); const timeid = useRef<number | null>(null);
return (...args: FcnParams) => { return (...args: FcnParams) => {
if (timeid.current) { if (timeid.current) {
window.clearTimeout(timeid.current) window.clearTimeout(timeid.current);
}
timeid.current = window.setTimeout(() => {
cb(...args)
}, timeout)
} }
} timeid.current = window.setTimeout(() => {
cb(...args);
}, timeout);
};
};