summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorHaishan <[email protected]>2018-10-21 16:47:00 +0800
committerHaishan <[email protected]>2018-10-21 16:47:00 +0800
commitca5d887fd8092fc1dd4f11ea18bb1f6904a6e223 (patch)
tree9077193cd725244e67d67c864dbcab620734966c /src
parent10b80254ddafd3756b8d74b00eeba38d7e08bb6a (diff)
fix: resume traffic data streaming on recovery from prior API errors
Diffstat (limited to 'src')
-rw-r--r--src/components/TrafficNow.js4
-rw-r--r--src/ducks/configs.js16
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();
+ }
};
}