fix: resume traffic data streaming on recovery from prior API errors

This commit is contained in:
Haishan 2018-10-21 16:47:00 +08:00
parent 10b80254dd
commit ca5d887fd8
2 changed files with 16 additions and 4 deletions

View file

@ -7,8 +7,8 @@ import s0 from 'c/TrafficNow.module.scss';
class TrafficNow extends Component {
state = {
upStr: '',
downStr: ''
upStr: '0 B/s',
downStr: '0 B/s'
};
componentDidMount() {

View file

@ -2,14 +2,17 @@
import * as configsAPI from 'a/configs';
import { openModal } from 'd/modals';
import * as trafficAPI from 'a/traffic';
const CompletedFetchConfigs = 'configs/CompletedFetchConfigs';
const OptimisticUpdateConfigs = 'proxies/OptimisticUpdateConfigs';
// const CompletedRequestDelayForProxy = 'proxies/CompletedRequestDelayForProxy';
export const getConfigs = s => s.configs;
// maybe we should put this flag in the redux store
// but since is not related a UI element and only make sense to this chunk
// of code, I'm going to leave it here
let successfullyFetchedConfigsBefore = false;
export function fetchConfigs() {
return async (dispatch, getState) => {
let res;
@ -37,6 +40,15 @@ export function fetchConfigs() {
type: CompletedFetchConfigs,
payload
});
// side effect
if (successfullyFetchedConfigsBefore === false) {
successfullyFetchedConfigsBefore = true;
// normally user will land on the "traffic chart" page first
// calling this here will let the data start streaming
// the traffic chart should already subscribed to the streaming
trafficAPI.fetchData();
}
};
}