chore(ui): move moment poller to a dedicated component

This commit is contained in:
Łukasz Mierzwa
2020-06-16 18:43:29 +01:00
committed by Łukasz Mierzwa
parent 0bab7d3918
commit fdc6e1b789
4 changed files with 21 additions and 11 deletions
+7
View File
@@ -45,6 +45,12 @@ const FaviconBadge = React.lazy(() =>
}))
);
const MomentPolledTimer = React.lazy(() =>
import("Components/MomentPolledTimer").then((module) => ({
default: module.MomentPolledTimer,
}))
);
interface UIDefaults {
Refresh: number;
HideFiltersWhenIdle: boolean;
@@ -156,6 +162,7 @@ const App: FunctionComponent<AppProps> = ({ defaultFilters, uiDefaults }) => {
<React.Suspense fallback={null}>
<FaviconBadge alertStore={alertStore} />
<Fetcher alertStore={alertStore} settingsStore={settingsStore} />
<MomentPolledTimer />
</React.Suspense>
</ErrorBoundary>
));
@@ -0,0 +1,12 @@
import React, { useEffect } from "react";
import Moment from "react-moment";
export function MomentPolledTimer() {
useEffect(() => {
Moment.startPooledTimer();
return () => Moment.clearPooledTimer();
}, []);
return <span id="moment-polled-timer" />;
}
+2 -4
View File
@@ -4,8 +4,6 @@ import throttle from "lodash.throttle";
import qs from "qs";
import moment from "moment";
import { FetchGet } from "Common/Fetch";
const QueryStringEncodeOptions = {
@@ -280,7 +278,7 @@ class AlertStore {
setIdle() {
this.value = AlertStoreStatuses.Idle;
this.error = null;
this.lastUpdateAt = moment();
this.lastUpdateAt = new Date();
},
setFetching() {
this.value = AlertStoreStatuses.Fetching;
@@ -292,7 +290,7 @@ class AlertStore {
setFailure(err) {
this.value = AlertStoreStatuses.Failure;
this.error = err;
this.lastUpdateAt = moment();
this.lastUpdateAt = new Date();
},
pause() {
this.paused = true;
-7
View File
@@ -7,8 +7,6 @@ import "react-app-polyfill/stable";
import React from "react";
import ReactDOM from "react-dom";
import Moment from "react-moment";
import "mobx-react-lite/batchingForReactDom";
import {
@@ -21,11 +19,6 @@ import { App } from "./App";
SetupSentry(SettingsElement());
// global timer for updating timestamps to human readable offsets
// this needs to be run before any <Moment/> instance
// https://www.npmjs.com/package/react-moment#pooled-timer
Moment.startPooledTimer();
// https://wetainment.com/testing-indexjs/
export default ReactDOM.render(
<App