import { receiveWeekNumber, fetchWeekNumber } from './weekNumber';
import {
  requestNewRelicErrors,
  receiveNewRelicErrors,
  fetchNewRelicErrors,
} from './newRelicErrors';
import {
  requestBugsHistory,
  receiveBugsHistory,
  fetchBugsHistory,
} from './bugsHistory';

export {
  receiveWeekNumber,
  fetchWeekNumber,
  requestNewRelicErrors,
  receiveNewRelicErrors,
  fetchNewRelicErrors,
  requestBugsHistory,
  receiveBugsHistory,
  fetchBugsHistory,
};

export const refreshAll = () => dispatch => {
  dispatch(fetchWeekNumber());
  dispatch(fetchNewRelicErrors());
  dispatch(fetchBugsHistory());
};

let refresher;
export const autoRefreshStart = () => dispatch => {
  refresher = setInterval(() => {
    dispatch(refreshAll());
  }, 1000 * 60); // TODO: magic number -> config
};

export const autoRefreshStop = () => {
  clearInterval(refresher);
};

import { receiveWeekNumber, fetchWeekNumber } from './weekNumber';
import {
  requestNewRelicErrors,
  receiveNewRelicErrors,
  fetchNewRelicErrors,
} from './newRelicErrors';
import {
  requestBugsHistory,
  receiveBugsHistory,
  fetchBugsHistory,
} from './bugsHistory';

export {
  receiveWeekNumber,
  fetchWeekNumber,
  requestNewRelicErrors,
  receiveNewRelicErrors,
  fetchNewRelicErrors,
  requestBugsHistory,
  receiveBugsHistory,
  fetchBugsHistory,
};

export const refreshAll = () => dispatch => {
  dispatch(fetchWeekNumber());
  dispatch(fetchNewRelicErrors());
  dispatch(fetchBugsHistory());
};

let refresher;
export const autoRefreshStart = () => dispatch => {
  refresher = setInterval(() => {
    dispatch(refreshAll());
  }, 1000 * 60);
};

export const autoRefreshStop = () => {
  clearInterval(refresher);
};

Add auto refresh start/stop actions
Add auto refresh start/stop actions
