added api setup

This commit is contained in:
ari committed 2021-12-30 12:37:30 -05:00
1 parent 787716ccba
commit 4a08956e1a
21 files changed
+12292 -12527

No files matched your search

+24
View File
@@ -0,0 +1,24 @@
import { useEffect } from 'react';
import { useDefaultApiState, makeReloadAutomations } from './util';
import { AutomationAPI } from './automations';
export type ApiService = ReturnType<typeof useAPIService>;
export const useAPIService = (
automationAPI: AutomationAPI
) => {
// state
const [state, setState] = useDefaultApiState();
const {reload, wrapCall} = makeReloadAutomations(automationAPI, state, setState);
// initial load of autos
useEffect(() => {
reload();
}, []);
return {
state,
removeAutomation: wrapCall(automationAPI.remove),
updateAutomation: wrapCall(automationAPI.update),
}
}