1- /**
2- * @flow
3- * All About Olaf
4- * Balances page
5- */
1+ // @flow
62
73import React from 'react'
8- import { StyleSheet , ScrollView , View , Text , RefreshControl } from 'react-native'
4+ import {
5+ StyleSheet ,
6+ ScrollView ,
7+ View ,
8+ Text ,
9+ RefreshControl ,
10+ Alert ,
11+ } from 'react-native'
912import { TabBarIcon } from '../components/tabbar-icon'
1013import { connect } from 'react-redux'
1114import { Cell , TableView , Section } from 'react-native-tableview-simple'
1215import type { LoginStateType } from '../../flux/parts/settings'
1316
17+ import { hasSeenAcknowledgement } from '../../flux/parts/settings'
1418import { updateBalances } from '../../flux/parts/sis'
1519
1620import delay from 'delay'
@@ -19,24 +23,34 @@ import * as c from '../components/colors'
1923
2024import type { TopLevelViewPropsType } from '../types'
2125
22- class BalancesView extends React . Component {
26+ const DISCLAIMER = 'This data may be outdated or otherwise inaccurate.'
27+ const LONG_DISCLAIMER =
28+ 'This data may be inaccurate.\nBon Appétit is always right.\nThis app is unofficial.'
29+
30+ type Props = TopLevelViewPropsType & {
31+ flex : ?number ,
32+ ole : ?number ,
33+ print : ?number ,
34+ weeklyMeals : ?number ,
35+ dailyMeals : ?number ,
36+ loginState : LoginStateType ,
37+ message : ?string ,
38+ alertSeen : boolean ,
39+
40+ hasSeenAcknowledgement : ( ) => any ,
41+ updateBalances : boolean => any ,
42+ }
43+
44+ type State = {
45+ loading : boolean ,
46+ }
47+
48+ class BalancesView extends React . PureComponent < void , Props , State > {
2349 static navigationOptions = {
2450 tabBarLabel : 'Balances' ,
2551 tabBarIcon : TabBarIcon ( 'card' ) ,
2652 }
2753
28- props : TopLevelViewPropsType & {
29- flex : ?number ,
30- ole : ?number ,
31- print : ?number ,
32- weeklyMeals : ?number ,
33- dailyMeals : ?number ,
34- loginState : LoginStateType ,
35- message : ?string ,
36-
37- updateBalances : boolean => any ,
38- }
39-
4054 state = {
4155 loading : false ,
4256 }
@@ -47,27 +61,40 @@ class BalancesView extends React.Component {
4761 this. refresh ( )
4862 }
4963
64+ componentDidMount ( ) {
65+ if ( ! this . props . alertSeen ) {
66+ Alert . alert ( '' , LONG_DISCLAIMER , [
67+ { text : 'I Disagree' , onPress : this . goBack , style : 'cancel' } ,
68+ { text : 'Okay' , onPress : this . props . hasSeenAcknowledgement } ,
69+ ] )
70+ }
71+ }
72+
5073 refresh = async ( ) => {
5174 let start = Date . now ( )
52- this . setState ( { loading : true } )
75+ this . setState ( ( ) => ( { loading : true } ) )
5376
5477 await this . fetchData ( )
5578
5679 // wait 0.5 seconds – if we let it go at normal speed, it feels broken.
5780 let elapsed = Date . now ( ) - start
5881 await delay ( 500 - elapsed )
5982
60- this . setState ( { loading : false } )
83+ this . setState ( ( ) => ( { loading : false } ) )
6184 }
6285
6386 fetchData = async ( ) => {
64- await Promise . all ( [ this . props . updateBalances ( true ) ] )
87+ await this . props . updateBalances ( true )
6588 }
6689
6790 openSettings = ( ) => {
6891 this . props . navigation . navigate ( 'SettingsView' )
6992 }
7093
94+ goBack = ( ) => {
95+ this . props . navigation . goBack ( null )
96+ }
97+
7198 render ( ) {
7299 let { flex, ole, print, dailyMeals, weeklyMeals} = this . props
73100 let { loading} = this . state
@@ -83,7 +110,7 @@ class BalancesView extends React.Component {
83110 }
84111 >
85112 < TableView >
86- < Section header = "BALANCES" >
113+ < Section header = "BALANCES" footer = { DISCLAIMER } >
87114 < View style = { styles . balancesRow } >
88115 < FormattedValueCell
89116 label = "Flex"
@@ -109,7 +136,7 @@ class BalancesView extends React.Component {
109136 </ View >
110137 </ Section >
111138
112- < Section header = "MEAL PLAN" >
139+ < Section header = "MEAL PLAN" footer = { DISCLAIMER } >
113140 < View style = { styles . balancesRow } >
114141 < FormattedValueCell
115142 label = "Daily Meals Left"
@@ -150,26 +177,28 @@ class BalancesView extends React.Component {
150177 }
151178}
152179
153- function mapStateToProps ( state ) {
180+ function mapState ( state ) {
154181 return {
155182 flex : state . sis . balances . flex ,
156183 ole : state . sis . balances . ole ,
157184 print : state . sis . balances . print ,
158185 weeklyMeals : state . sis . balances . weekly ,
159186 dailyMeals : state . sis . balances . daily ,
160187 message : state . sis . balances . message ,
188+ alertSeen : state . settings . unofficiallyAcknowledged ,
161189
162190 loginState : state . settings . credentials . state ,
163191 }
164192}
165193
166- function mapDispatchToProps ( dispatch ) {
194+ function mapDispatch ( dispatch ) {
167195 return {
168196 updateBalances : force => dispatch ( updateBalances ( force ) ) ,
197+ hasSeenAcknowledgement : ( ) => dispatch ( hasSeenAcknowledgement ( ) ) ,
169198 }
170199}
171200
172- export default connect ( mapStateToProps , mapDispatchToProps ) ( BalancesView )
201+ export default connect ( mapState , mapDispatch ) ( BalancesView )
173202
174203let cellMargin = 10
175204let cellSidePadding = 10
0 commit comments