From ca5d887fd8092fc1dd4f11ea18bb1f6904a6e223 Mon Sep 17 00:00:00 2001 From: Haishan Date: Sun, 21 Oct 2018 16:47:00 +0800 Subject: [PATCH] fix: resume traffic data streaming on recovery from prior API errors --- src/components/TrafficNow.js | 4 ++-- src/ducks/configs.js | 16 ++++++++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/components/TrafficNow.js b/src/components/TrafficNow.js index ed1e575..3721aca 100644 --- a/src/components/TrafficNow.js +++ b/src/components/TrafficNow.js @@ -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() { diff --git a/src/ducks/configs.js b/src/ducks/configs.js index a36aa65..2e7ca82 100644 --- a/src/ducks/configs.js +++ b/src/ducks/configs.js @@ -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(); + } }; }