Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[IGNORE] Tom timer refresh #127

Closed
wants to merge 17 commits into from
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@
},
"proxy": {
"/bootstrap/": {
"target": "https://nxt3.staging.lizard.net/",
"target": "https://demo.lizard.net/",
"changeOrigin": true,
"ssl": false,
"secure": false,
Expand All @@ -165,7 +165,7 @@
}
},
"/api/v3/": {
"target": "https://nxt3.staging.lizard.net/",
"target": "https://demo.lizard.net/",
"changeOrigin": true,
"ssl": false,
"secure": false,
Expand Down
47 changes: 44 additions & 3 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,56 @@ import GridLayout from "./components/GridLayout";
import FullLayout from "./components/FullLayout";
import { connect } from "react-redux";
import { Route, withRouter } from "react-router-dom";
import { getConfiguredNow } from "./reducers";

import { fetchAlarms } from "./actions";
import { fetchAlarms, setDateTimeAction } from "./actions";
import styles from "./App.css";

class App extends Component {
componentWillMount() {
this.setDateTimeActionWithNow();
const that = this;
// update redux time every minute (60000 miliseconds) because redux only saves time on the minute accurate
setInterval(function() {
that.setDateTimeActionWithNow();
}, 60000);
}

componentDidMount() {
if (!this.props.iframeModeActive) {
this.props.fetchAlarms();
}
}

setDateTimeActionWithNow() {
const jsDateObject = new Date();
const utcMinutes = jsDateObject.getUTCMinutes();
const utcMinutesZeroPrefixed =
utcMinutes < 10 ? "0" + utcMinutes : utcMinutes;

const dateStr =
jsDateObject.getUTCFullYear() +
"-" +
(jsDateObject.getUTCMonth() + 1) +
"-" +
jsDateObject.getUTCDate();
const timeStr = jsDateObject.getUTCHours() + ":" + utcMinutesZeroPrefixed;

this.props.setDateTimeAction(dateStr, timeStr);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deze logica (die een jsDateObject omzet naar een string afgerond op minuten) zou beter op de reducer kunnen denk ik. Het is een constraint van de onze data store die daar bewaakt moet worden.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ja denk dat je gelijk hebt. Zolang de Date dan maar als parameter wordt meegegeven.
De regel "const jsDateObject = new Date();" moet dan uit deze functie. Dit om te voorkomen dat reducer statefull wordt.


componentDidUpdate(prevProps) {
if (
!prevProps.configuredNow ||
(prevProps.configuredNow && !this.props.configuredNow) ||
this.props.configuredNow.getTime() != prevProps.configuredNow.getTime()
) {
if (!this.props.iframeModeActive) {
this.props.fetchAlarms();
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Er moet een functie komen op de Redux store, die "now" oplevert; en dat is ofwel configuredNow als die er is, of de laatst geupdate setDateTime.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ja klopt. Deze bestaat ook namelijk de functie " getConfiguredNow(state)" zoals die in de reducer.js staat. Deze gebruiken we hier ook, namelijk zie de functie mapStateToProps hieronder. De functie hierboven bepaald dus niet welke 'now' gebruikt wordt, maar vergelijkt de huidige now met de voorgaande now en bepaald zo of een nieuwe render cycle nodig is. De naamgeving is misschien wel verwarrend.

}
}

render() {
return (
<div className={styles.App}>
Expand All @@ -26,13 +65,15 @@ class App extends Component {

function mapStateToProps(state) {
return {
iframeModeActive: state.iframeMode.active
iframeModeActive: state.iframeMode.active,
configuredNow: getConfiguredNow(state)
};
}

function mapDispatchToProps(dispatch) {
return {
fetchAlarms: () => fetchAlarms(dispatch)
fetchAlarms: () => fetchAlarms(dispatch),
setDateTimeAction: (date, time) => setDateTimeAction(dispatch)(date, time)
};
}

Expand Down
16 changes: 14 additions & 2 deletions src/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export const RECEIVE_BOOTSTRAP_SUCCESS = "RECEIVE_BOOTSTRAP_SUCCESS";
export const RECEIVE_BOOTSTRAP_ERROR = "RECEIVE_BOOTSTRAP_ERROR";

// SettingsActions
export const SET_DATE_TIME = "SET_DATE_TIME";
export const SET_DATE = "SET_DATE";
export const SET_TIME = "SET_TIME";
export const RESET_DATETIME = "RESET_DATETIME";
Expand Down Expand Up @@ -71,7 +72,6 @@ export function fetchAlarms(dispatch) {

getRasterAlarms({ active: true, page_size: 1000 }).then(
alarms => {
console.log("[P] Received alarms:", alarms);
dispatch(receiveAlarmsAction(alarms, false));
},
error => {
Expand Down Expand Up @@ -142,7 +142,7 @@ export function fetchBootstrap(dispatch, sessionState) {

dispatch(fetchBootstrapAction());

getBootstrap("parramatta-dashboard").then(
getBootstrap("tdb_parra_vnrdsxt574").then(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

XXX

bootstrap => {
dispatch(receiveBootstrapSuccessAction(bootstrap));
},
Expand Down Expand Up @@ -202,6 +202,18 @@ const receiveRasterEventsAction = (uuid, geomKey, start, end, events) => {
};
};

export const setDateTimeAction = function(dispatch) {
return (date, time) => {
dispatch({
type: SET_DATE_TIME,
data: {
date: date,
time: time
}
});
};
};

export const setDateAction = function(dispatch) {
return date =>
dispatch({
Expand Down
14 changes: 13 additions & 1 deletion src/components/FullStatistics.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { connect } from "react-redux";
import { Scrollbars } from "react-custom-scrollbars";
import { fetchAlarms } from "../actions";
import { IconActiveAlarmSVG, IconInactiveAlarmSVG } from "./Icons";
import { getConfiguredNow } from "../reducers";

import styles from "./FullStatistics.css";

Expand All @@ -12,6 +13,16 @@ class FullStatistics extends Component {
this.props.fetchAlarms();
}
}
componentDidUpdate(prevProps) {
if (
!prevProps.configuredNow ||
this.props.configuredNow.getTime() != prevProps.configuredNow.getTime()
) {
if (!this.props.iframeModeActive) {
this.props.fetchAlarms();
}
}
}
getDatetimeString(utcRep) {
if (utcRep === null) {
return null;
Expand Down Expand Up @@ -98,7 +109,8 @@ class FullStatistics extends Component {
const mapStateToProps = (state, ownProps) => {
return {
alarms: state.alarms,
iframeModeActive: state.iframeMode.active
iframeModeActive: state.iframeMode.active,
configuredNow: getConfiguredNow(state)
};
};

Expand Down
34 changes: 23 additions & 11 deletions src/components/GridLayout.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ class GridLayout extends Component {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wijzigingen deze file zijn allemaal alleen syntax wijzigingen.
Meestal gedaan door linter.
Soms door mij gedaan om logging te kunnen toevoegen.

<main style={{ height: height - 100 }}>
{settingsMenuId === 0 ? (
<div style={{padding: 20}}>
<div style={{ padding: 20 }}>
<h4 style={{ padding: 0, margin: 0 }}>
Date/time settings &nbsp;
<button onClick={this.props.resetDateTime}>Reset</button>
Expand All @@ -162,8 +162,9 @@ class GridLayout extends Component {
type="date"
name="date"
value={this.props.date}
onChange={event =>
this.props.changeDate(event.target.value)}
onChange={event => {
this.props.changeDate(event.target.value);
}}
/>
</div>
<div>
Expand All @@ -172,17 +173,23 @@ class GridLayout extends Component {
type="time"
name="time"
value={this.props.time}
onChange={event =>
this.props.changeTime(event.target.value)}
onChange={event => {
this.props.changeTime(event.target.value);
}}
/>
</div>
</div>
<br/>
<button className={styles.OKButton} onClick={() => this.setState({ settingsMenu: false })}>OK</button>
<br />
<button
className={styles.OKButton}
onClick={() => this.setState({ settingsMenu: false })}
>
OK
</button>
</div>
) : null}
{settingsMenuId === 1 ? (
<div style={{padding: 20}}>
<div style={{ padding: 20 }}>
<h4 style={{ padding: 0, margin: 0 }}>Map settings</h4>
<hr />
<div className={styles.MapSettings}>
Expand All @@ -204,13 +211,18 @@ class GridLayout extends Component {
Switch
</button>
</div>
<br/>
<button className={styles.OKButton} onClick={() => this.setState({ settingsMenu: false })}>OK</button>
<br />
<button
className={styles.OKButton}
onClick={() => this.setState({ settingsMenu: false })}
>
OK
</button>
</div>
) : null}

{settingsMenuId === 2 ? (
<div style={{padding: 20}}>
<div style={{ padding: 20 }}>
<h4 style={{ padding: 0, margin: 0 }}>Contact info</h4>
<hr />
<p>
Expand Down
Loading