React: clean up App component

This commit is contained in:
DC
2016-07-22 21:55:27 -07:00
parent 734b0731a1
commit 9df51aec49

View File

@@ -49,19 +49,18 @@ module.exports = class App extends React.Component {
var vdom = ( var vdom = (
<div className={'app ' + cls.join(' ')}> <div className={'app ' + cls.join(' ')}>
<Header state={state} /> <Header state={state} />
{getErrorPopover(state)} {this.getErrorPopover()}
<div key='content' className='content'>{getView(state)}</div> <div key='content' className='content'>{this.getView()}</div>
{getModal(state)} {this.getModal()}
</div> </div>
) )
return vdom return vdom
} }
}
function getErrorPopover (state) { getErrorPopover () {
var now = new Date().getTime() var now = new Date().getTime()
var recentErrors = state.errors.filter((x) => now - x.time < 5000) var recentErrors = this.state.errors.filter((x) => now - x.time < 5000)
var hasErrors = recentErrors.length > 0 var hasErrors = recentErrors.length > 0
var errorElems = recentErrors.map(function (error, i) { var errorElems = recentErrors.map(function (error, i) {
@@ -74,9 +73,10 @@ function getErrorPopover (state) {
{errorElems} {errorElems}
</div> </div>
) )
} }
function getModal (state) { getModal () {
var state = this.state
if (!state.modal) return if (!state.modal) return
var ModalContents = Modals[state.modal.id] var ModalContents = Modals[state.modal.id]
return ( return (
@@ -87,9 +87,11 @@ function getModal (state) {
</div> </div>
</div> </div>
) )
} }
function getView (state) { getView () {
var state = this.state
var View = Views[state.location.url()] var View = Views[state.location.url()]
return (<View state={state} />) return (<View state={state} />)
}
} }