feat(web): detect, clips, snapshots toggles

This commit is contained in:
Paul Armstrong
2021-02-17 20:53:57 -08:00
committed by Blake Blackshear
parent e399790442
commit b6ba6459fb
18 changed files with 500 additions and 92 deletions

View File

@@ -40,14 +40,19 @@ function reducer(state, { type, payload, meta }) {
}
}
export const ApiProvider = ({ children }) => {
export function ApiProvider({ children }) {
const [state, dispatch] = useReducer(reducer, initialState);
return (
<Api.Provider value={{ state, dispatch }}>
<MqttProvider>{children}</MqttProvider>
<MqttWithConfig>{children}</MqttWithConfig>
</Api.Provider>
);
};
}
function MqttWithConfig({ children }) {
const { data, status } = useConfig();
return status === FetchStatus.LOADED ? <MqttProvider config={data}>{children}</MqttProvider> : children;
}
function shouldFetch(state, url, fetchId = null) {
if ((fetchId && url in state.queries && state.queries[url].fetchId !== fetchId) || !(url in state.queries)) {