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