templatized storymaking
This commit is contained in:
1 parent
02ec81c16a
commit
a9c3e9c890
9 files changed
+255
-172
No files matched your search
@@ -0,0 +1,34 @@
|
||||
import { HassEntities } from "home-assistant-js-websocket";
|
||||
import { FC } from "react";
|
||||
import { AutomationData } from "types/automations";
|
||||
import { consolidateAutomations } from "../helpers";
|
||||
import { useTagDB } from "../TagDB";
|
||||
import { useAutomationManagerState } from "./state";
|
||||
|
||||
export type AutomationManagerLoadedProps = {
|
||||
configAutomations: AutomationData[];
|
||||
hassEntities: HassEntities;
|
||||
onUpdateTags: (aid: string, tags: Record<string, string>) => void;
|
||||
};
|
||||
export const AutomationManagerLoaded: FC<AutomationManagerLoadedProps> = ({
|
||||
configAutomations,
|
||||
onUpdateTags,
|
||||
hassEntities,
|
||||
}) => {
|
||||
const state = useAutomationManagerState();
|
||||
const tagsDB = useTagDB(
|
||||
configAutomations.map(({ metadata: { id }, tags }) => ({
|
||||
id,
|
||||
tags,
|
||||
})),
|
||||
onUpdateTags
|
||||
);
|
||||
|
||||
const automations = consolidateAutomations(
|
||||
hassEntities,
|
||||
configAutomations.map(({ metadata }) => metadata),
|
||||
tagsDB
|
||||
);
|
||||
|
||||
return <></>;
|
||||
};
|
||||
@@ -0,0 +1,25 @@
|
||||
import { useState } from "react";
|
||||
import { useCookies } from "react-cookie";
|
||||
|
||||
export const useAutomationManagerState = () => {
|
||||
const [
|
||||
cookies,
|
||||
setCookies,
|
||||
// eslint-disable-next-line
|
||||
_,
|
||||
] = useCookies(["selectedAutomation"]);
|
||||
let initialCurrent = null;
|
||||
try {
|
||||
initialCurrent = cookies.selectedAutomation ?? null;
|
||||
} catch (_) {}
|
||||
|
||||
const [current, setCurrent] = useState<string | null>(initialCurrent);
|
||||
|
||||
return {
|
||||
current,
|
||||
setCurrent(i: string | null) {
|
||||
setCurrent(i);
|
||||
setCookies("selectedAutomation", i === null ? undefined : i);
|
||||
},
|
||||
};
|
||||
};
|
||||
Reference in new issue
Block a user