-
Notifications
You must be signed in to change notification settings - Fork 0
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
Changes from 16 commits
8d3bf42
48460f0
659de33
2db9c6d
299c9b4
1fe8455
a7aeaf7
503cb2d
39c5251
9d4be3c
adb3b20
9f0170e
924eb01
7b1132c
86a9dcc
a4f4209
9f82010
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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); | ||
} | ||
|
||
componentDidUpdate(prevProps) { | ||
if ( | ||
!prevProps.configuredNow || | ||
(prevProps.configuredNow && !this.props.configuredNow) || | ||
this.props.configuredNow.getTime() != prevProps.configuredNow.getTime() | ||
) { | ||
if (!this.props.iframeModeActive) { | ||
this.props.fetchAlarms(); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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}> | ||
|
@@ -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) | ||
}; | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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"; | ||
|
@@ -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 => { | ||
|
@@ -142,7 +142,7 @@ export function fetchBootstrap(dispatch, sessionState) { | |
|
||
dispatch(fetchBootstrapAction()); | ||
|
||
getBootstrap("parramatta-dashboard").then( | ||
getBootstrap("tdb_parra_vnrdsxt574").then( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. XXX |
||
bootstrap => { | ||
dispatch(receiveBootstrapSuccessAction(bootstrap)); | ||
}, | ||
|
@@ -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({ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -149,7 +149,7 @@ class GridLayout extends Component { | |
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wijzigingen deze file zijn allemaal alleen syntax wijzigingen. |
||
<main style={{ height: height - 100 }}> | ||
{settingsMenuId === 0 ? ( | ||
<div style={{padding: 20}}> | ||
<div style={{ padding: 20 }}> | ||
<h4 style={{ padding: 0, margin: 0 }}> | ||
Date/time settings | ||
<button onClick={this.props.resetDateTime}>Reset</button> | ||
|
@@ -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> | ||
|
@@ -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}> | ||
|
@@ -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> | ||
|
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.