auto jump into new automation in mobile mode
This commit is contained in:
1 parent
c6c1efddae
commit
eaec599109
2 files changed
+95
-74
No files matched your search
@@ -3,20 +3,19 @@ import "./index.mobile.css";
|
|||||||
import { AutomationEditor } from "components/AutomationEditor";
|
import { AutomationEditor } from "components/AutomationEditor";
|
||||||
import { FC, ReactNode, useState } from "react";
|
import { FC, ReactNode, useState } from "react";
|
||||||
import { AutomationData } from "types/automations";
|
import { AutomationData } from "types/automations";
|
||||||
import { defaultAutomation } from 'utils/defaults';
|
import { defaultAutomation } from "utils/defaults";
|
||||||
import { ArrowIcon } from "components/Icons";
|
import { ArrowIcon } from "components/Icons";
|
||||||
import { ButtonIcon } from "components/Icons/ButtonIcons";
|
import { ButtonIcon } from "components/Icons/ButtonIcons";
|
||||||
import { ApiService } from "apiService/core";
|
import { ApiService } from "apiService/core";
|
||||||
import { AutomationListBox } from "./AutomationListBox";
|
import { AutomationListBox } from "./AutomationListBox";
|
||||||
import { DAGAutomationFlowDims } from 'components/DAGFlow/types';
|
import { DAGAutomationFlowDims } from "components/DAGFlow/types";
|
||||||
import useWindowSize from "utils/useWindowSize";
|
import useWindowSize from "utils/useWindowSize";
|
||||||
import { makeTagDB } from "./TagDB";
|
import { makeTagDB } from "./TagDB";
|
||||||
import LinearProgress from "@mui/material/LinearProgress";
|
import LinearProgress from "@mui/material/LinearProgress";
|
||||||
import CircularProgress from "@mui/material/CircularProgress";
|
import CircularProgress from "@mui/material/CircularProgress";
|
||||||
import { useCookies } from 'react-cookie';
|
import { useCookies } from "react-cookie";
|
||||||
import { useHA } from "haService";
|
import { useHA } from "haService";
|
||||||
|
|
||||||
|
|
||||||
interface AutomationListParams {
|
interface AutomationListParams {
|
||||||
automations: AutomationData[];
|
automations: AutomationData[];
|
||||||
onUpdate: (i: number, auto: AutomationData) => void;
|
onUpdate: (i: number, auto: AutomationData) => void;
|
||||||
@@ -31,12 +30,12 @@ export const useAutomationListState = () => {
|
|||||||
cookies,
|
cookies,
|
||||||
setCookies,
|
setCookies,
|
||||||
// eslint-disable-next-line
|
// eslint-disable-next-line
|
||||||
_
|
_,
|
||||||
] = useCookies(['alCurrent']);
|
] = useCookies(["alCurrent"]);
|
||||||
let initialCurrent = 0;
|
let initialCurrent = 0;
|
||||||
try {
|
try {
|
||||||
initialCurrent = Number(cookies.alCurrent ?? '0');
|
initialCurrent = Number(cookies.alCurrent ?? "0");
|
||||||
} catch (_) { }
|
} catch (_) {}
|
||||||
|
|
||||||
const [hideList, setHideList] = useState(false);
|
const [hideList, setHideList] = useState(false);
|
||||||
const [current, setCurrent] = useState(initialCurrent);
|
const [current, setCurrent] = useState(initialCurrent);
|
||||||
@@ -46,11 +45,11 @@ export const useAutomationListState = () => {
|
|||||||
setHideList,
|
setHideList,
|
||||||
current,
|
current,
|
||||||
setCurrent(i: number) {
|
setCurrent(i: number) {
|
||||||
setCurrent(i)
|
setCurrent(i);
|
||||||
setCookies('alCurrent', String(i))
|
setCookies("alCurrent", String(i));
|
||||||
}
|
},
|
||||||
}
|
};
|
||||||
}
|
};
|
||||||
|
|
||||||
export const AutomationList: FC<AutomationListParams> = ({
|
export const AutomationList: FC<AutomationListParams> = ({
|
||||||
automations,
|
automations,
|
||||||
@@ -61,49 +60,65 @@ export const AutomationList: FC<AutomationListParams> = ({
|
|||||||
children,
|
children,
|
||||||
}) => {
|
}) => {
|
||||||
// state
|
// state
|
||||||
const { hideList, setHideList, current, setCurrent } = useAutomationListState();
|
const { hideList, setHideList, current, setCurrent } =
|
||||||
|
useAutomationListState();
|
||||||
const { isMobile } = useWindowSize();
|
const { isMobile } = useWindowSize();
|
||||||
// alias
|
// alias
|
||||||
const currentAuto = automations.length > 0 ? automations[current] : null;
|
const currentAuto = automations.length > 0 ? automations[current] : null;
|
||||||
const tagDB = makeTagDB(automations);
|
const tagDB = makeTagDB(automations);
|
||||||
// render
|
// render
|
||||||
return <div className={["automation-list--root", isMobile ? 'mobile' : ''].join(' ')}>
|
return (
|
||||||
<div className={["automation-list--list", hideList ? "hide" : "show"].join(' ')}>
|
<div
|
||||||
<AutomationListBox
|
className={["automation-list--root", isMobile ? "mobile" : ""].join(" ")}
|
||||||
automations={automations}
|
>
|
||||||
onAdd={() => {
|
<div
|
||||||
onAdd(defaultAutomation(String(Date.now())));
|
className={["automation-list--list", hideList ? "hide" : "show"].join(
|
||||||
setCurrent(automations.length)
|
" "
|
||||||
}}
|
)}
|
||||||
onSelectAutomation={i => {
|
>
|
||||||
setCurrent(i);
|
<AutomationListBox
|
||||||
if (isMobile) {
|
automations={automations}
|
||||||
setHideList(true)
|
onAdd={() => {
|
||||||
}
|
onAdd(defaultAutomation(String(Date.now())));
|
||||||
}}
|
setCurrent(automations.length);
|
||||||
selected={current}
|
if (isMobile) {
|
||||||
onRemove={onRemove}
|
setHideList(true);
|
||||||
/>
|
}
|
||||||
<ButtonIcon
|
}}
|
||||||
onClick={() => setHideList(!hideList)}
|
onSelectAutomation={(i) => {
|
||||||
className="automation-list--list-hide"
|
setCurrent(i);
|
||||||
Icon={ArrowIcon}
|
if (isMobile) {
|
||||||
/>
|
setHideList(true);
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
selected={current}
|
||||||
|
onRemove={onRemove}
|
||||||
|
/>
|
||||||
|
<ButtonIcon
|
||||||
|
onClick={() => setHideList(!hideList)}
|
||||||
|
className="automation-list--list-hide"
|
||||||
|
Icon={ArrowIcon}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div className="automation-list--viewer">
|
||||||
|
{currentAuto ? (
|
||||||
|
<AutomationEditor
|
||||||
|
automation={currentAuto}
|
||||||
|
onUpdate={(a) => onUpdate(current, a)}
|
||||||
|
dims={{
|
||||||
|
...dims,
|
||||||
|
flipped: isMobile,
|
||||||
|
}}
|
||||||
|
tagDB={tagDB}
|
||||||
|
/>
|
||||||
|
) : (
|
||||||
|
<></>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
{children}
|
||||||
</div>
|
</div>
|
||||||
<div className="automation-list--viewer">
|
);
|
||||||
{currentAuto ? <AutomationEditor
|
};
|
||||||
automation={currentAuto}
|
|
||||||
onUpdate={a => onUpdate(current, a)}
|
|
||||||
dims={{
|
|
||||||
...dims,
|
|
||||||
flipped: isMobile
|
|
||||||
}}
|
|
||||||
tagDB={tagDB}
|
|
||||||
/> : <></>}
|
|
||||||
</div>
|
|
||||||
{children}
|
|
||||||
</div>
|
|
||||||
}
|
|
||||||
|
|
||||||
interface ConnectedAutomationListParams {
|
interface ConnectedAutomationListParams {
|
||||||
dims: DAGAutomationFlowDims;
|
dims: DAGAutomationFlowDims;
|
||||||
@@ -111,40 +126,44 @@ interface ConnectedAutomationListParams {
|
|||||||
}
|
}
|
||||||
export const ConnectedAutomationList: FC<ConnectedAutomationListParams> = ({
|
export const ConnectedAutomationList: FC<ConnectedAutomationListParams> = ({
|
||||||
api: {
|
api: {
|
||||||
state: {
|
state: { automations },
|
||||||
automations,
|
|
||||||
},
|
|
||||||
...methods
|
...methods
|
||||||
},
|
},
|
||||||
dims
|
dims,
|
||||||
}) => {
|
}) => {
|
||||||
const { reloadAutomations } = useHA();
|
const { reloadAutomations } = useHA();
|
||||||
const removeAutomation = async (args: any) => {
|
const removeAutomation = async (args: any) => {
|
||||||
const resp = await methods.removeAutomation(args)
|
const resp = await methods.removeAutomation(args);
|
||||||
await reloadAutomations();
|
await reloadAutomations();
|
||||||
return resp
|
return resp;
|
||||||
}
|
};
|
||||||
const updateAutomation = async (args: any) => {
|
const updateAutomation = async (args: any) => {
|
||||||
const resp = await methods.updateAutomation(args)
|
const resp = await methods.updateAutomation(args);
|
||||||
await reloadAutomations();
|
await reloadAutomations();
|
||||||
return resp
|
return resp;
|
||||||
}
|
};
|
||||||
if (!automations.ready) {
|
if (!automations.ready) {
|
||||||
return <div className="automation-list--root loading">
|
return (
|
||||||
<LinearProgress />
|
<div className="automation-list--root loading">
|
||||||
<div className="automation-list--circle-loader">
|
<LinearProgress />
|
||||||
<CircularProgress />
|
<div className="automation-list--circle-loader">
|
||||||
|
<CircularProgress />
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
);
|
||||||
}
|
}
|
||||||
if (!automations.ok) {
|
if (!automations.ok) {
|
||||||
return <span>Error {automations.error}</span>
|
return <span>Error {automations.error}</span>;
|
||||||
}
|
}
|
||||||
return <AutomationList
|
return (
|
||||||
dims={dims}
|
<AutomationList
|
||||||
automations={automations.data.data}
|
dims={dims}
|
||||||
onAdd={auto => updateAutomation({ auto, index: automations.data.totalItems + 1 })}
|
automations={automations.data.data}
|
||||||
onRemove={index => removeAutomation({ index })}
|
onAdd={(auto) =>
|
||||||
onUpdate={(index, auto) => updateAutomation({ index, auto })}
|
updateAutomation({ auto, index: automations.data.totalItems + 1 })
|
||||||
/>
|
}
|
||||||
}
|
onRemove={(index) => removeAutomation({ index })}
|
||||||
|
onUpdate={(index, auto) => updateAutomation({ index, auto })}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
};
|
||||||
@@ -98,6 +98,8 @@ export const getDescriptionFromAutomationNode = <N extends AutomationNodeTypes>(
|
|||||||
return node.value_template;
|
return node.value_template;
|
||||||
case "device":
|
case "device":
|
||||||
return getDescriptionForDeviceType(node, namer, true);
|
return getDescriptionForDeviceType(node, namer, true);
|
||||||
|
case "trigger":
|
||||||
|
return node.id;
|
||||||
default:
|
default:
|
||||||
return JSON.stringify(node);
|
return JSON.stringify(node);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user