Skip to content

Commit 9d85215

Browse files
committed
extract building hours stateful list from the index file
1 parent 445d934 commit 9d85215

File tree

2 files changed

+107
-107
lines changed

2 files changed

+107
-107
lines changed
Lines changed: 1 addition & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -1,110 +1,4 @@
11
// @flow
2-
/**
3-
* All About Olaf
4-
* Building Hours view. This component loads data from either GitHub or
5-
* the local copy as a fallback, and renders the list of buildings.
6-
*/
7-
8-
import React from 'react'
9-
import {NoticeView} from '../components/notice'
10-
import {tracker} from '../../analytics'
11-
import bugsnag from '../../bugsnag'
12-
import {BuildingHoursList} from './list'
13-
14-
import type momentT from 'moment'
15-
import type {TopLevelViewPropsType} from '../types'
16-
import type {BuildingType} from './types'
17-
import {data as fallbackBuildingHours} from '../../../docs/building-hours'
18-
import groupBy from 'lodash/groupBy'
19-
20-
import moment from 'moment-timezone'
21-
const CENTRAL_TZ = 'America/Winnipeg'
222

3+
export {BuildingHoursView} from './stateful-list'
234
export {BuildingHoursDetailView} from './detail'
24-
25-
const githubBaseUrl = 'https://stodevx.github.io/AAO-React-Native'
26-
27-
const groupBuildings = (buildings: BuildingType[]) =>
28-
groupBy(buildings, b => b.category || 'Other')
29-
30-
export class BuildingHoursView extends React.Component {
31-
static navigationOptions = {
32-
title: 'Building Hours',
33-
headerBackTitle: 'Hours',
34-
}
35-
36-
state: {
37-
error: ?Error,
38-
loading: boolean,
39-
now: momentT,
40-
buildings: {[key: string]: BuildingType[]},
41-
intervalId: number,
42-
} = {
43-
error: null,
44-
loading: true,
45-
// now: moment.tz('Wed 7:25pm', 'ddd h:mma', null, CENTRAL_TZ),
46-
now: moment.tz(CENTRAL_TZ),
47-
buildings: groupBuildings(fallbackBuildingHours),
48-
intervalId: 0,
49-
}
50-
51-
componentWillMount() {
52-
this.fetchData()
53-
54-
// This updates the screen every ten seconds, so that the building
55-
// info statuses are updated without needing to leave and come back.
56-
this.setState({intervalId: setInterval(this.updateTime, 10000)})
57-
}
58-
59-
componentWillUnmount() {
60-
clearTimeout(this.state.intervalId)
61-
}
62-
63-
props: TopLevelViewPropsType
64-
65-
updateTime = () => {
66-
this.setState({now: moment.tz(CENTRAL_TZ)})
67-
}
68-
69-
fetchData = async () => {
70-
this.setState({loading: true})
71-
72-
let buildings: BuildingType[] = []
73-
try {
74-
let container = await fetchJson(`${githubBaseUrl}/building-hours.json`)
75-
let data = container.data
76-
buildings = data
77-
} catch (err) {
78-
tracker.trackException(err.message)
79-
bugsnag.notify(err)
80-
console.warn(err)
81-
buildings = fallbackBuildingHours
82-
}
83-
84-
if (process.env.NODE_ENV === 'development') {
85-
buildings = fallbackBuildingHours
86-
}
87-
88-
this.setState({
89-
loading: false,
90-
buildings: groupBuildings(buildings),
91-
now: moment.tz(CENTRAL_TZ),
92-
})
93-
}
94-
95-
render() {
96-
if (this.state.error) {
97-
return <NoticeView text={'Error: ' + this.state.error.message} />
98-
}
99-
100-
return (
101-
<BuildingHoursList
102-
navigation={this.props.navigation}
103-
buildings={this.state.buildings}
104-
now={this.state.now}
105-
onRefresh={this.fetchData}
106-
loading={this.state.loading}
107-
/>
108-
)
109-
}
110-
}
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
/**
2+
* @flow
3+
*
4+
* Building Hours view. This component loads data from either GitHub or
5+
* the local copy as a fallback, and renders the list of buildings.
6+
*/
7+
8+
import React from 'react'
9+
import {NoticeView} from '../components/notice'
10+
import {tracker} from '../../analytics'
11+
import bugsnag from '../../bugsnag'
12+
import {BuildingHoursList} from './list'
13+
14+
import moment from 'moment-timezone'
15+
import type {TopLevelViewPropsType} from '../types'
16+
import type {BuildingType} from './types'
17+
import {data as fallbackBuildingHours} from '../../../docs/building-hours'
18+
import groupBy from 'lodash/groupBy'
19+
20+
const CENTRAL_TZ = 'America/Winnipeg'
21+
const githubBaseUrl = 'https://stodevx.github.io/AAO-React-Native'
22+
23+
const groupBuildings = (buildings: BuildingType[]) =>
24+
groupBy(buildings, b => b.category || 'Other')
25+
26+
export class BuildingHoursView extends React.Component {
27+
static navigationOptions = {
28+
title: 'Building Hours',
29+
headerBackTitle: 'Hours',
30+
}
31+
32+
state: {
33+
error: ?Error,
34+
loading: boolean,
35+
now: moment,
36+
buildings: {[key: string]: BuildingType[]},
37+
intervalId: number,
38+
} = {
39+
error: null,
40+
loading: true,
41+
// now: moment.tz('Wed 7:25pm', 'ddd h:mma', null, CENTRAL_TZ),
42+
now: moment.tz(CENTRAL_TZ),
43+
buildings: groupBuildings(fallbackBuildingHours),
44+
intervalId: 0,
45+
}
46+
47+
componentWillMount() {
48+
this.fetchData()
49+
50+
// This updates the screen every ten seconds, so that the building
51+
// info statuses are updated without needing to leave and come back.
52+
this.setState({intervalId: setInterval(this.updateTime, 10000)})
53+
}
54+
55+
componentWillUnmount() {
56+
clearTimeout(this.state.intervalId)
57+
}
58+
59+
props: TopLevelViewPropsType
60+
61+
updateTime = () => {
62+
this.setState({now: moment.tz(CENTRAL_TZ)})
63+
}
64+
65+
fetchData = async () => {
66+
this.setState({loading: true})
67+
68+
let buildings: BuildingType[] = []
69+
try {
70+
let container = await fetchJson(`${githubBaseUrl}/building-hours.json`)
71+
let data = container.data
72+
buildings = data
73+
} catch (err) {
74+
tracker.trackException(err.message)
75+
bugsnag.notify(err)
76+
console.warn(err)
77+
buildings = fallbackBuildingHours
78+
}
79+
80+
if (process.env.NODE_ENV === 'development') {
81+
buildings = fallbackBuildingHours
82+
}
83+
84+
this.setState({
85+
loading: false,
86+
buildings: groupBuildings(buildings),
87+
now: moment.tz(CENTRAL_TZ),
88+
})
89+
}
90+
91+
render() {
92+
if (this.state.error) {
93+
return <NoticeView text={'Error: ' + this.state.error.message} />
94+
}
95+
96+
return (
97+
<BuildingHoursList
98+
navigation={this.props.navigation}
99+
buildings={this.state.buildings}
100+
now={this.state.now}
101+
onRefresh={this.fetchData}
102+
loading={this.state.loading}
103+
/>
104+
)
105+
}
106+
}

0 commit comments

Comments
 (0)