2018-04-06 10:57:23 -06:00
|
|
|
import { Actions } from "../constants";
|
2018-04-06 14:12:06 -06:00
|
|
|
import { Middleware } from "redux";
|
2018-04-06 10:57:23 -06:00
|
|
|
import { MiddlewareConfig } from "./middlewares";
|
2018-08-01 07:12:15 -06:00
|
|
|
import { ResourceName } from "farmbot";
|
2018-04-06 14:12:06 -06:00
|
|
|
import { throttledLogRefresh } from "./refresh_logs";
|
2018-04-06 10:57:23 -06:00
|
|
|
|
|
|
|
const WEB_APP_CONFIG: ResourceName = "WebAppConfig";
|
|
|
|
|
2018-04-06 14:19:22 -06:00
|
|
|
/**
|
|
|
|
* Middleware function that listens for changes on the `WebAppConfig` resource.
|
|
|
|
* If the resource does change, it will trigger a throttled refresh of all log
|
|
|
|
* resources, downloading the filtered log list as required from the API. */
|
2018-08-08 08:44:12 -06:00
|
|
|
// tslint:disable-next-line:no-any
|
2018-04-06 14:12:06 -06:00
|
|
|
export const fn: Middleware = () => (dispatch) => (action: any) => {
|
2020-01-03 13:04:45 -07:00
|
|
|
const needsRefresh = action?.payload?.kind === WEB_APP_CONFIG
|
|
|
|
&& action.type === Actions.SAVE_RESOURCE_OK;
|
2018-04-06 10:57:23 -06:00
|
|
|
|
2018-04-06 14:12:06 -06:00
|
|
|
needsRefresh && throttledLogRefresh(dispatch);
|
2018-04-06 10:57:23 -06:00
|
|
|
|
|
|
|
return dispatch(action);
|
|
|
|
};
|
|
|
|
|
|
|
|
export const refilterLogsMiddleware: MiddlewareConfig = { fn, env: "*" };
|