cleaned up styling for editor

This commit is contained in:
ari committed 2022-05-13 17:26:44 -04:00
1 parent bfc95db6f6
commit 4cfc429980
25 files changed
+532 -230

No files matched your search

+29 -2
View File
@@ -1,7 +1,9 @@
import { AutomationNode, AutomationNodeSubtype, AutomationNodeTypes } from "types/automations";
import { AutomationNode, AutomationNodeMapping, AutomationNodeSubtype, AutomationNodeTypes } from "types/automations";
import { AutomationTrigger } from 'types/automations/triggers';
export const getNodeType = (node: AutomationNode): AutomationNodeTypes => {
console.log({ node })
if ('condition' in node) {
return 'condition'
} else if ('platform' in node) {
@@ -51,4 +53,29 @@ export const getSubTypeList = <T extends AutomationNodeTypes>(nodeType: T): Auto
default:
return [];
}
}
}
export const makeDefault = (nodeType: keyof AutomationNodeMapping): AutomationNode => {
switch (nodeType) {
case 'action':
return {
'data': {},
'service': '',
'target': {},
}
case 'condition':
return {
condition: 'and',
conditions: []
}
default:
return {
platform: 'device',
device_id: '',
domain: '',
type: '',
subtype: '',
} as AutomationTrigger
}
}
+23
View File
@@ -0,0 +1,23 @@
import { useRef, useEffect } from 'react';
export const useDelayEffect = (cb: () => void, deps: any[], timeout: number) => {
const fcn = useDelayedFunction(cb, timeout);
useEffect(() => {
fcn()
}, [deps])
}
export const useDelayedFunction = <FcnParams extends any[]>(
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)
}
}