modifiable tags
This commit is contained in:
1 parent
2b1b7526c3
commit
81f22ccd2a
10 files changed
+283
-149
No files matched your search
@@ -55,74 +55,6 @@
|
||||
color: var(--secondary);
|
||||
}
|
||||
|
||||
.automation-list-box--body--item:hover, .automation-list-box--body--item.selected {
|
||||
background-color: var(--primary-accent);
|
||||
color: var(--primary);
|
||||
}
|
||||
|
||||
.automation-list-box--body--item:hover>.automation-list-box--body--item--tags>span {
|
||||
border-color: var(--primary);
|
||||
}
|
||||
|
||||
.automation-list-box--body--item--tags--add:hover {
|
||||
border-color: var(--primary);
|
||||
color: var(--primary-accent);
|
||||
background-color: var(--secondary);
|
||||
}
|
||||
|
||||
.automation-list-box--body--item {
|
||||
padding-left: 1em;
|
||||
cursor: pointer;
|
||||
display: flex;
|
||||
justify-content: left;
|
||||
align-items: flex-start;
|
||||
gap: 1em;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.automation-list-box--body--item::before {
|
||||
content: "⊚ ";
|
||||
}
|
||||
|
||||
.automation-list-box--body--item--title {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
padding-left: 0.25em;
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.automation-list-box--body--item--title>b {
|
||||
font-size: 1em;
|
||||
}
|
||||
|
||||
.automation-list-box--body--item--title>span, .automation-list-box--body--item--title>b>span {
|
||||
font-size: 0.75em;
|
||||
}
|
||||
|
||||
.automation-list-box--body--item>button {
|
||||
padding: 0.25em !important;
|
||||
margin: 0.5em !important;
|
||||
}
|
||||
|
||||
.automation-list-box--body--item--tags {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
font-size: 0.75em;
|
||||
justify-content: left;
|
||||
align-items: flex-start;
|
||||
overflow: auto;
|
||||
max-height: 100%;
|
||||
gap: 0.25em;
|
||||
}
|
||||
|
||||
.automation-list-box--body--item--tags>span {
|
||||
border-color: var(--primary-accent);
|
||||
border-style: solid;
|
||||
border-width: 1px;
|
||||
border-radius: 0.5em;
|
||||
padding: 0.1em 0.5em;
|
||||
}
|
||||
|
||||
.automation-list-box--bottom {
|
||||
margin-top: 0.5em;
|
||||
|
||||
@@ -4,6 +4,7 @@ import { AutomationListBox } from "./AutomationListBox";
|
||||
import { createMockAuto } from "utils/mocks";
|
||||
import { Page } from "components/Page";
|
||||
import { CookiesProvider } from "react-cookie";
|
||||
import { makeTagDB } from "./TagDB";
|
||||
|
||||
export default {
|
||||
title: "App/AutomationList/Box",
|
||||
@@ -19,6 +20,7 @@ const Template: ComponentStory<typeof AutomationListBox> = (args) => {
|
||||
<CookiesProvider>
|
||||
<AutomationListBox
|
||||
{...args}
|
||||
tagsDB={makeTagDB(args.automations)}
|
||||
automations={args.automations}
|
||||
selected={selected}
|
||||
onSelectAutomation={(i) => {
|
||||
|
||||
@@ -1,31 +1,22 @@
|
||||
import { getTagList } from './AutomationListBox';
|
||||
import { createMockAuto } from 'utils/mocks';
|
||||
import { getTagList } from "./AutomationListBox";
|
||||
import { createMockAuto } from "utils/mocks";
|
||||
|
||||
// const makeDummy = (id: string, tags: Record<string, string>) => ({
|
||||
// condition: [],
|
||||
// metadata: {
|
||||
// id,
|
||||
// alias: '',
|
||||
// description: '',
|
||||
// mode: 'single',
|
||||
// },
|
||||
// tags,
|
||||
// sequence: [],
|
||||
// trigger: [],
|
||||
// })
|
||||
test("getTagList", () => {
|
||||
expect(
|
||||
getTagList([
|
||||
createMockAuto(),
|
||||
createMockAuto(),
|
||||
createMockAuto(),
|
||||
createMockAuto(),
|
||||
])
|
||||
).toStrictEqual([]);
|
||||
|
||||
test('getTagList', () => {
|
||||
expect(getTagList([
|
||||
createMockAuto(),
|
||||
createMockAuto(),
|
||||
createMockAuto(),
|
||||
createMockAuto(),
|
||||
])).toStrictEqual([])
|
||||
|
||||
expect(getTagList([
|
||||
createMockAuto({ "Room": "Kitchen", "Area": "Oven" }),
|
||||
createMockAuto({ "Room": "Attic" }),
|
||||
createMockAuto({ "Room": "Office" }),
|
||||
createMockAuto({ "Area": "Balcony" }),
|
||||
])).toStrictEqual(["Room", "Area"])
|
||||
})
|
||||
expect(
|
||||
getTagList([
|
||||
createMockAuto({ Room: "Kitchen", Area: "Oven" }),
|
||||
createMockAuto({ Room: "Attic" }),
|
||||
createMockAuto({ Room: "Office" }),
|
||||
createMockAuto({ Area: "Balcony" }),
|
||||
])
|
||||
).toStrictEqual(["Room", "Area"]);
|
||||
});
|
||||
@@ -9,12 +9,13 @@ import { AutomationListBoxGroup } from "./AutomationListBoxGroup";
|
||||
import { useCookies } from "react-cookie";
|
||||
import { TagDB } from "components/AutomationList/TagDB";
|
||||
|
||||
export type Props = {
|
||||
export type AutomationListBoxProps = {
|
||||
automations: AutomationData[];
|
||||
selected: number;
|
||||
onSelectAutomation: (i: number) => void;
|
||||
onRemove: (i: number) => void;
|
||||
onAdd: () => void;
|
||||
onUpdate: (a: AutomationData, i: number) => void;
|
||||
tagsDB: TagDB;
|
||||
};
|
||||
|
||||
@@ -52,13 +53,14 @@ const useAutomationListBoxState = () => {
|
||||
};
|
||||
};
|
||||
|
||||
export const AutomationListBox: FC<Props> = ({
|
||||
export const AutomationListBox: FC<AutomationListBoxProps> = ({
|
||||
automations,
|
||||
selected,
|
||||
onSelectAutomation,
|
||||
onAdd,
|
||||
onRemove,
|
||||
tagsDB,
|
||||
onUpdate,
|
||||
}) => {
|
||||
const tags = getTagList(automations);
|
||||
const { searchText, setSearchText, selectedTagIdx, setSelectedTagIdx } =
|
||||
@@ -95,6 +97,7 @@ export const AutomationListBox: FC<Props> = ({
|
||||
grouping={grouping}
|
||||
selectedAutomationIdx={selected}
|
||||
tagsDB={tagsDB}
|
||||
onSave={onUpdate}
|
||||
/>
|
||||
</div>
|
||||
<div className="automation-list-box--bottom">
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
.automation-list-box--body--item:hover, .automation-list-box--body--item.selected {
|
||||
outline-color: var(--primary-accent);
|
||||
outline-style: solid;
|
||||
outline-width: 1px;
|
||||
background-color: var(--secondary);
|
||||
}
|
||||
|
||||
.automation-list-box--body--item:hover>.automation-list-box--body--item--tags>span {
|
||||
border-color: var(--primary);
|
||||
}
|
||||
|
||||
.automation-list-box--body--item--tags--add:hover {
|
||||
border-color: var(--primary);
|
||||
color: var(--primary-accent);
|
||||
background-color: var(--secondary);
|
||||
}
|
||||
|
||||
.automation-list-box--body--item {
|
||||
padding-left: 1em;
|
||||
cursor: pointer;
|
||||
display: flex;
|
||||
gap: 1em;
|
||||
}
|
||||
|
||||
.automation-list-box--body--item::before {
|
||||
content: "⊚ ";
|
||||
}
|
||||
|
||||
.automation-list-box--body--item--buttons {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
height: 100%;
|
||||
gap: 0.25em;
|
||||
margin: 0.5em
|
||||
}
|
||||
|
||||
.automation-list-box--body--item--buttons>button {
|
||||
padding: 0.25em;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.automation-list-box--body--item--buttons .save {
|
||||
color: var(--green-light)
|
||||
}
|
||||
|
||||
.automation-list-box--body--item--buttons .save:hover {
|
||||
color: var(--green)
|
||||
}
|
||||
@@ -1,10 +1,13 @@
|
||||
import "./AutomationListBoxGroup.css";
|
||||
|
||||
import { TrashIcon } from "components/Icons";
|
||||
import { MetadataBox } from "./AutomationMetadataBox";
|
||||
import { AutomationData } from "types/automations";
|
||||
import { AutomationGrouping } from "./automationGrouper";
|
||||
import { FC, useState } from "react";
|
||||
import { FC, useEffect, useState } from "react";
|
||||
import { ButtonIcon } from "components/Icons/ButtonIcons";
|
||||
import { TagDB } from "./TagDB";
|
||||
import Save from "@mui/icons-material/Save";
|
||||
|
||||
export type AutomationListBoxEvents = {
|
||||
onSelectAutomation: (i: number) => void;
|
||||
@@ -26,6 +29,7 @@ export type AutomationListBoxGroupProps = {
|
||||
autos: Array<[AutomationData, number]>;
|
||||
selectedAutomationIdx: number;
|
||||
tagsDB: TagDB;
|
||||
onSave: (a: AutomationData, i: number) => void;
|
||||
};
|
||||
export const AutomationListBoxGroup: FC<AutomationListBoxGroupProps> = ({
|
||||
events,
|
||||
@@ -33,6 +37,7 @@ export const AutomationListBoxGroup: FC<AutomationListBoxGroupProps> = ({
|
||||
autos,
|
||||
selectedAutomationIdx,
|
||||
tagsDB,
|
||||
onSave,
|
||||
}) => {
|
||||
if (grouping.top.length === 1) {
|
||||
return (
|
||||
@@ -45,7 +50,8 @@ export const AutomationListBoxGroup: FC<AutomationListBoxGroupProps> = ({
|
||||
},
|
||||
events,
|
||||
selectedAutomationIdx,
|
||||
tagsDB
|
||||
tagsDB,
|
||||
onSave
|
||||
)}
|
||||
</>
|
||||
);
|
||||
@@ -63,6 +69,7 @@ export const AutomationListBoxGroup: FC<AutomationListBoxGroupProps> = ({
|
||||
events={events}
|
||||
selectedAutomationIdx={selectedAutomationIdx}
|
||||
tagsDB={tagsDB}
|
||||
onSave={onSave}
|
||||
/>
|
||||
))}
|
||||
</>
|
||||
@@ -75,7 +82,8 @@ export const convertGroupsToItems = (
|
||||
{ grouping, currentNode }: AutomationListBoxGroups,
|
||||
events: AutomationListBoxEvents,
|
||||
selectedAutomationIdx: number,
|
||||
tagsDB: TagDB
|
||||
tagsDB: TagDB,
|
||||
onSave: (a: AutomationData, i: number) => void
|
||||
) => {
|
||||
const automations = grouping.getAutomations(currentNode);
|
||||
if (automations.length > 0) {
|
||||
@@ -86,6 +94,7 @@ export const convertGroupsToItems = (
|
||||
auto={autos[autoIndex]}
|
||||
isSelected={selectedAutomationIdx === autos[autoIndex][1]}
|
||||
tagsDB={tagsDB}
|
||||
onSave={(a) => onSave(a, autoIndex)}
|
||||
/>
|
||||
));
|
||||
}
|
||||
@@ -102,6 +111,7 @@ export const convertGroupsToItems = (
|
||||
events={events}
|
||||
selectedAutomationIdx={selectedAutomationIdx}
|
||||
tagsDB={tagsDB}
|
||||
onSave={onSave}
|
||||
/>
|
||||
));
|
||||
}
|
||||
@@ -114,7 +124,8 @@ export const AutomationListBoxGroupItem: FC<{
|
||||
autos: Array<[AutomationData, number]>;
|
||||
selectedAutomationIdx: number;
|
||||
tagsDB: TagDB;
|
||||
}> = ({ autos, groups, events, selectedAutomationIdx, tagsDB }) => {
|
||||
onSave: (a: AutomationData, i: number) => void;
|
||||
}> = ({ autos, groups, events, selectedAutomationIdx, tagsDB, onSave }) => {
|
||||
const groupData = groups.grouping.getData(groups.currentNode);
|
||||
const automations = groups.grouping.getAutomations(groups.currentNode);
|
||||
const [open, setOpen] = useState(false);
|
||||
@@ -145,7 +156,8 @@ export const AutomationListBoxGroupItem: FC<{
|
||||
groups,
|
||||
events,
|
||||
selectedAutomationIdx,
|
||||
tagsDB
|
||||
tagsDB,
|
||||
onSave
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
@@ -156,28 +168,73 @@ export const AutomationListBoxItem: FC<{
|
||||
isSelected: boolean;
|
||||
events: AutomationListBoxEvents;
|
||||
tagsDB: TagDB;
|
||||
onSave: (a: AutomationData) => void;
|
||||
}> = ({
|
||||
events: { onRemove, onSelectAutomation },
|
||||
auto: [auto, autoIndex],
|
||||
isSelected,
|
||||
tagsDB,
|
||||
onSave,
|
||||
}) => {
|
||||
// state
|
||||
const [{ tags, isModified }, setState] = useState({
|
||||
isModified: false,
|
||||
tags: Object.entries(auto.tags),
|
||||
});
|
||||
|
||||
// effects
|
||||
useEffect(() => {
|
||||
setState({
|
||||
isModified: false,
|
||||
tags: Object.entries(auto.tags),
|
||||
});
|
||||
}, [auto]);
|
||||
|
||||
// alias
|
||||
const setTags = (t: [string, string][]) =>
|
||||
setState({
|
||||
isModified: true,
|
||||
tags: t,
|
||||
});
|
||||
// sub elements
|
||||
let title = "BadAuto<<Missing Metadata>>";
|
||||
if (auto.metadata) {
|
||||
title = `Name = ${auto.metadata.alias}\nID = ${auto.metadata.id}\nDescription = ${auto.metadata.description}`;
|
||||
}
|
||||
|
||||
// render
|
||||
return (
|
||||
<div
|
||||
key={autoIndex}
|
||||
className={[
|
||||
"automation-list-box--body--item",
|
||||
isSelected ? "selected" : "",
|
||||
isModified ? "modded" : "",
|
||||
].join(" ")}
|
||||
title={title}
|
||||
onClick={() => onSelectAutomation(autoIndex)}
|
||||
>
|
||||
<MetadataBox metadata={auto.metadata} tags={auto.tags} tagsDB={tagsDB} />
|
||||
<ButtonIcon onClick={() => onRemove(autoIndex)} icon={<TrashIcon />} />
|
||||
<MetadataBox
|
||||
metadata={auto.metadata}
|
||||
tags={tags}
|
||||
tagsDB={tagsDB}
|
||||
onUpdate={setTags}
|
||||
/>
|
||||
<div className="automation-list-box--body--item--buttons">
|
||||
{isModified && (
|
||||
<ButtonIcon
|
||||
className="save"
|
||||
icon={<Save />}
|
||||
onClick={() =>
|
||||
onSave({
|
||||
...auto,
|
||||
tags: Object.fromEntries(tags),
|
||||
})
|
||||
}
|
||||
/>
|
||||
)}
|
||||
<ButtonIcon onClick={() => onRemove(autoIndex)} icon={<TrashIcon />} />
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
@@ -1,3 +1,39 @@
|
||||
.automation-list-box--body--item--title {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
padding-left: 0.25em;
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.automation-list-box--body--item--title>b {
|
||||
font-size: 1em;
|
||||
}
|
||||
|
||||
.automation-list-box--body--item--title>span, .automation-list-box--body--item--title>b>span {
|
||||
font-size: 0.75em;
|
||||
}
|
||||
|
||||
|
||||
.automation-list-box--body--item--tags {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
font-size: 0.75em;
|
||||
justify-content: left;
|
||||
align-items: flex-start;
|
||||
overflow: auto;
|
||||
max-height: 100%;
|
||||
gap: 0.25em;
|
||||
}
|
||||
|
||||
.automation-list-box--body--item--tags>span {
|
||||
border-color: var(--primary-accent);
|
||||
border-style: solid;
|
||||
border-width: 1px;
|
||||
border-radius: 0.5em;
|
||||
padding: 0.1em 0.5em;
|
||||
}
|
||||
|
||||
.automation-list-box--body--item--tags--item {
|
||||
color: white;
|
||||
border-color: white;
|
||||
|
||||
@@ -4,24 +4,37 @@ import { FC, useState } from "react";
|
||||
import { AutomationMetadata } from "types/automations";
|
||||
import { InputAutoComplete } from "components/Inputs/InputAutoComplete";
|
||||
import { TagDB } from "./TagDB";
|
||||
import { cleanUpUndefined } from "components/NodeEditor/OptionManager/OptionManager";
|
||||
|
||||
export const MetadataBox: FC<{
|
||||
metadata: AutomationMetadata;
|
||||
tags: Record<string, string>;
|
||||
onUpdate: (t: [string, string][]) => void;
|
||||
tags: [string, string][];
|
||||
tagsDB: TagDB;
|
||||
}> = (auto) => {
|
||||
const [tags, setTags] = useState(auto.tags);
|
||||
const tagOptions = auto.tagsDB.getTagNames(Object.keys(tags));
|
||||
}> = ({ tags, onUpdate, tagsDB, metadata }) => {
|
||||
// state
|
||||
const [newTag, setNewTag] = useState<
|
||||
| {
|
||||
on: false;
|
||||
}
|
||||
| {
|
||||
on: true;
|
||||
name: string;
|
||||
value: string;
|
||||
}
|
||||
>({ on: false });
|
||||
// alias
|
||||
const tagOptions = tagsDB.getTagNames(tags.map((t) => t[0]));
|
||||
|
||||
// render
|
||||
let title = <span>{"BadAuto<<Missing Metadata>>"}</span>;
|
||||
if (auto.metadata) {
|
||||
if (metadata) {
|
||||
title = (
|
||||
<>
|
||||
<b>
|
||||
{String(auto.metadata.alias ?? "").slice(0, 15)}{" "}
|
||||
<span>({String(auto.metadata.id).slice(0, 5)})</span>
|
||||
{String(metadata.alias ?? "").slice(0, 15)}{" "}
|
||||
<span>({String(metadata.id).slice(0, 5)})</span>
|
||||
</b>
|
||||
<span>{String(auto.metadata.description ?? "").slice(0, 25)}</span>
|
||||
<span>{String(metadata.description ?? "").slice(0, 25)}</span>
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -29,23 +42,56 @@ export const MetadataBox: FC<{
|
||||
<div className="automation-list-box--body--item--title">
|
||||
{title}
|
||||
<div className="automation-list-box--body--item--tags">
|
||||
{Object.keys(tags).map((tagName) => (
|
||||
{tags.map(([tagName, tagValue], tagIndex) => (
|
||||
<MetadataBoxTag
|
||||
options={[tagOptions, auto.tagsDB.getTagValues(tagName)]}
|
||||
key={tagName}
|
||||
value={[tagName, tags[tagName]]}
|
||||
options={[tagOptions, tagsDB.getTagValues(tagName)]}
|
||||
key={tagIndex}
|
||||
value={[tagName, tagValue]}
|
||||
onChange={([newName, newValue]) =>
|
||||
setTags(
|
||||
cleanUpUndefined({
|
||||
...tags,
|
||||
[tagName]: undefined,
|
||||
[newName]: newValue,
|
||||
})
|
||||
)
|
||||
onUpdate([
|
||||
...tags.slice(0, tagIndex),
|
||||
[newName, newValue],
|
||||
...tags.slice(tagIndex + 1),
|
||||
])
|
||||
}
|
||||
/>
|
||||
))}
|
||||
<span className="automation-list-box--body--item--tags--add">+</span>
|
||||
{newTag.on && (
|
||||
<MetadataBoxTag
|
||||
options={[tagOptions, tagsDB.getTagValues(newTag.name)]}
|
||||
key="new"
|
||||
value={[newTag.name, newTag.value]}
|
||||
initialState={[true, true]}
|
||||
onChange={([name, value]) => {
|
||||
if (name.trim() !== "" && value.trim() !== "") {
|
||||
setNewTag({
|
||||
on: false,
|
||||
});
|
||||
onUpdate([...tags, [name, value]]);
|
||||
} else {
|
||||
setNewTag({
|
||||
on: true,
|
||||
name,
|
||||
value,
|
||||
});
|
||||
}
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
{!newTag.on && (
|
||||
<span
|
||||
className="automation-list-box--body--item--tags--add"
|
||||
onClick={() =>
|
||||
setNewTag({
|
||||
on: true,
|
||||
name: "",
|
||||
value: "",
|
||||
})
|
||||
}
|
||||
>
|
||||
+
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
@@ -55,8 +101,11 @@ export const MetadataBoxTag: FC<{
|
||||
value: [string, string];
|
||||
onChange: (t: [string, string]) => void;
|
||||
options: [string[], string[]];
|
||||
initialState?: [boolean, boolean];
|
||||
}> = (props) => {
|
||||
const [[editMode1, editMode2], setEditMode] = useState([false, false]);
|
||||
const [[editMode1, editMode2], setEditMode] = useState(
|
||||
props.initialState ? props.initialState : [false, false]
|
||||
);
|
||||
const toggle1 = () => setEditMode([!editMode1, editMode2]);
|
||||
const toggle2 = () => setEditMode([editMode1, !editMode2]);
|
||||
return (
|
||||
|
||||
@@ -2,23 +2,26 @@ import { AutomationData } from "types/automations";
|
||||
|
||||
export type TagDB = ReturnType<typeof makeTagDB>;
|
||||
export const makeTagDB = (automations: AutomationData[]) => {
|
||||
const allTags: Record<string, Set<string>> = {};
|
||||
automations.forEach(({ tags }) =>
|
||||
Object.keys(tags).forEach(tagName => {
|
||||
const tagValue = tags[tagName];
|
||||
if (!allTags[tagName]) {
|
||||
allTags[tagName] = new Set()
|
||||
}
|
||||
allTags[tagName].add(tagValue);
|
||||
})
|
||||
);
|
||||
const allTagNames = Object.keys(allTags);
|
||||
return {
|
||||
getTagNames(myTags: string[]): string[] {
|
||||
return allTagNames.filter(n => !myTags.includes(n)).sort()
|
||||
},
|
||||
getTagValues(tagName: string): string[] {
|
||||
return allTags[tagName] ? Array.from(allTags[tagName].values()).sort() : [];
|
||||
}
|
||||
}
|
||||
}
|
||||
const allTags: Record<string, Set<string>> = {};
|
||||
automations.forEach(({ tags }) =>
|
||||
Object.keys(tags).forEach((tagName) => {
|
||||
const tagValue = tags[tagName];
|
||||
if (!allTags[tagName]) {
|
||||
allTags[tagName] = new Set();
|
||||
}
|
||||
allTags[tagName].add(tagValue);
|
||||
})
|
||||
);
|
||||
const allTagNames = Object.keys(allTags);
|
||||
return {
|
||||
getTagNames(myTags: string[]): string[] {
|
||||
console.log(myTags, allTagNames);
|
||||
return allTagNames.filter((n) => !myTags.includes(n)).sort();
|
||||
},
|
||||
getTagValues(tagName: string): string[] {
|
||||
return allTags[tagName]
|
||||
? Array.from(allTags[tagName].values()).sort()
|
||||
: [];
|
||||
},
|
||||
};
|
||||
};
|
||||
@@ -1,7 +1,7 @@
|
||||
import "./index.css";
|
||||
import "./index.mobile.css";
|
||||
import { AutomationEditor } from "components/AutomationEditor";
|
||||
import { FC, ReactNode, useState } from "react";
|
||||
import { FC, ReactNode, useState, useRef, useEffect } from "react";
|
||||
import { AutomationData } from "types/automations";
|
||||
import { defaultAutomation } from "utils/defaults";
|
||||
import { ButtonIcon } from "components/Icons/ButtonIcons";
|
||||
@@ -15,6 +15,7 @@ import CircularProgress from "@mui/material/CircularProgress";
|
||||
import { useCookies } from "react-cookie";
|
||||
import { useHA } from "haService";
|
||||
import { ArrowBack } from "@mui/icons-material";
|
||||
import { useSnackbar } from "notistack";
|
||||
|
||||
interface AutomationListParams {
|
||||
automations: AutomationData[];
|
||||
@@ -60,12 +61,21 @@ export const AutomationList: FC<AutomationListParams> = ({
|
||||
children,
|
||||
}) => {
|
||||
// state
|
||||
const snackbr = useSnackbar();
|
||||
const { hideList, setHideList, current, setCurrent } =
|
||||
useAutomationListState();
|
||||
const { isMobile } = useWindowSize();
|
||||
const firstRender = useRef(true);
|
||||
// alias
|
||||
const currentAuto = automations.length > 0 ? automations[current] : null;
|
||||
const tagDB = makeTagDB(automations);
|
||||
// effect
|
||||
useEffect(() => {
|
||||
if (firstRender.current) {
|
||||
snackbr.enqueueSnackbar("Saved.", { variant: "info" });
|
||||
}
|
||||
firstRender.current = true;
|
||||
}, [automations]);
|
||||
// render
|
||||
return (
|
||||
<div
|
||||
@@ -78,6 +88,7 @@ export const AutomationList: FC<AutomationListParams> = ({
|
||||
>
|
||||
<AutomationListBox
|
||||
automations={automations}
|
||||
onUpdate={(a, i) => onUpdate(i, a)}
|
||||
onAdd={() => {
|
||||
onAdd(defaultAutomation(String(Date.now())));
|
||||
setCurrent(automations.length);
|
||||
|
||||
Reference in new issue
Block a user