Skip to content

Instantly share code, notes, and snippets.

@MoonTahoe
Created October 15, 2017 01:41
Show Gist options
  • Save MoonTahoe/dac0f71b7008bde5c7fe0b8ef6847a49 to your computer and use it in GitHub Desktop.
Save MoonTahoe/dac0f71b7008bde5c7fe0b8ef6847a49 to your computer and use it in GitHub Desktop.
import React, { Component } from 'react'
import storeFactory from './store'
import { loadLifts, changeLiftStatus } from './actions'
import './App.css'
const StatusCircle = ({status, selected=false, onSelect=f=>f}) =>
<div className={selected ? `${status} selected` : status} onClick={() => onSelect(status)}/>
const StatusIndicator = ({currentStatus, onStatusChange=f=>f}) =>
['open', 'hold', 'closed'].map(
(type, i) =>
<StatusCircle key={i}
status={type}
selected={type===currentStatus}
onSelect={onStatusChange} />
)
class App extends Component {
constructor() {
super()
this.store = storeFactory()
this.store.subscribe(() => this.forceUpdate())
}
componentWillMount() {
this.store.dispatch(loadLifts())
}
render() {
const { loading, lifts } = this.store.getState()
return (
<div className="App">
<header className="App-header">
<h1 className="App-title">Snowtooth Lift Status</h1>
</header>
{(loading) ?
<p className="App-intro">loading...</p>
: <p className="App-intro">{lifts.filter(l=>l.status==='open').length} lifts open</p>}
{(lifts.length) ?
<table border="1">
<thead>
<tr>
<th>lits name</th>
<th>current status</th>
</tr>
{lifts.map((lift, i) =>
<tr key={i}>
<td>{lift.name}</td>
<td>
<StatusIndicator key={i}
currentStatus={lift.status}
onStatusChange={newStatus => this.store.dispatch(changeLiftStatus(newStatus, lift.name))} />
</td>
</tr>
)}
</thead>
</table>
: null}
</div>
);
}
}
export default App
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment