Skip to content

Commit 9680dc7

Browse files
authored
Merge pull request #1728 from StoDevX/sis-disclaimer
Add disclaimers to SIS' Balances view
2 parents 236fc08 + 7c4fa8d commit 9680dc7

File tree

4 files changed

+90
-48
lines changed

4 files changed

+90
-48
lines changed

source/flux/init.js

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,10 @@ import {
1111
setLoginCredentials,
1212
validateLoginCredentials,
1313
loadFeedbackStatus,
14+
loadAcknowledgement,
1415
} from './parts/settings'
1516
import {updateBalances, updateCourses} from './parts/sis'
1617

17-
function homescreen(store) {
18-
store.dispatch(loadHomescreenOrder())
19-
}
20-
21-
function feedbackOptOutStatus(store) {
22-
store.dispatch(loadFeedbackStatus())
23-
}
24-
2518
function loginCredentials(store) {
2619
loadLoginCredentials().then(({username, password} = {}) => {
2720
if (!username || !password) return
@@ -36,14 +29,6 @@ async function validateOlafCredentials(store) {
3629
store.dispatch(validateLoginCredentials(username, password))
3730
}
3831

39-
function loadBalances(store) {
40-
store.dispatch(updateBalances(false))
41-
}
42-
43-
function loadCourses(store) {
44-
store.dispatch(updateCourses(false))
45-
}
46-
4732
function netInfoIsConnected(store) {
4833
function updateConnectionStatus(isConnected) {
4934
store.dispatch(updateOnlineStatus(isConnected))
@@ -58,15 +43,16 @@ export async function init(store: {dispatch: any}) {
5843
// and those that do.
5944

6045
// kick off the parts that don't care about network
61-
homescreen(store)
62-
feedbackOptOutStatus(store)
46+
store.dispatch(loadHomescreenOrder())
47+
store.dispatch(loadFeedbackStatus())
48+
store.dispatch(loadAcknowledgement())
6349
loginCredentials(store)
6450

6551
// wait for our first connection check to happen
6652
await netInfoIsConnected(store)
6753

6854
// then go do the network stuff
6955
validateOlafCredentials(store)
70-
loadBalances(store)
71-
loadCourses(store)
56+
store.dispatch(updateBalances(false))
57+
store.dispatch(updateCourses(false))
7258
}

source/flux/parts/settings.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,12 @@ import {
99
clearLoginCredentials,
1010
} from '../../lib/login'
1111

12-
import {setAnalyticsOptOut, getAnalyticsOptOut} from '../../lib/storage'
12+
import {
13+
setAnalyticsOptOut,
14+
getAnalyticsOptOut,
15+
getAcknowledgementStatus,
16+
setAcknowledgementStatus,
17+
} from '../../lib/storage'
1318

1419
import {updateBalances} from './sis'
1520

@@ -25,6 +30,7 @@ export const CREDENTIALS_VALIDATE_FAILURE =
2530
'settings/CREDENTIALS_VALIDATE_FAILURE'
2631
export const SET_FEEDBACK = 'settings/SET_FEEDBACK'
2732
export const CHANGE_THEME = 'settings/CHANGE_THEME'
33+
export const SIS_ALERT_SEEN = 'settings/SIS_ALERT_SEEN'
2834

2935
export async function setFeedbackStatus(feedbackEnabled: boolean) {
3036
await setAnalyticsOptOut(feedbackEnabled)
@@ -35,6 +41,15 @@ export function loadFeedbackStatus() {
3541
return {type: SET_FEEDBACK, payload: getAnalyticsOptOut()}
3642
}
3743

44+
export function loadAcknowledgement() {
45+
return {type: SIS_ALERT_SEEN, payload: getAcknowledgementStatus()}
46+
}
47+
48+
export async function hasSeenAcknowledgement() {
49+
await setAcknowledgementStatus(true)
50+
return {type: SIS_ALERT_SEEN, payload: true}
51+
}
52+
3853
export async function setLoginCredentials(username: string, password: string) {
3954
await saveLoginCredentials(username, password)
4055
return {type: SET_LOGIN_CREDENTIALS, payload: {username, password}}
@@ -155,6 +170,7 @@ const initialSettingsState: SettingsState = {
155170

156171
credentials: initialCredentialsState,
157172
feedbackDisabled: false,
173+
unofficiallyAcknowledged: false,
158174
}
159175

160176
export function settings(
@@ -176,6 +192,9 @@ export function settings(
176192
case SET_FEEDBACK:
177193
return {...state, feedbackDisabled: payload}
178194

195+
case SIS_ALERT_SEEN:
196+
return {...state, unofficiallyAcknowledged: payload}
197+
179198
default:
180199
return state
181200
}

source/lib/storage.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,14 @@ export function getHomescreenOrder(): Promise<string[]> {
3535
return getItem(homescreenOrderKey)
3636
}
3737

38+
const acknowledgementStatusKey = 'settings:ackd'
39+
export function setAcknowledgementStatus(status: boolean) {
40+
return setItem(acknowledgementStatusKey, status)
41+
}
42+
export function getAcknowledgementStatus(): Promise<?boolean> {
43+
return getItem(acknowledgementStatusKey)
44+
}
45+
3846
/// MARK: Credentials
3947

4048
const tokenValidKey = 'credentials:valid'

source/views/sis/balances.js

Lines changed: 56 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
1-
/**
2-
* @flow
3-
* All About Olaf
4-
* Balances page
5-
*/
1+
// @flow
62

73
import 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'
912
import {TabBarIcon} from '../components/tabbar-icon'
1013
import {connect} from 'react-redux'
1114
import {Cell, TableView, Section} from 'react-native-tableview-simple'
1215
import type {LoginStateType} from '../../flux/parts/settings'
1316

17+
import {hasSeenAcknowledgement} from '../../flux/parts/settings'
1418
import {updateBalances} from '../../flux/parts/sis'
1519

1620
import delay from 'delay'
@@ -19,24 +23,34 @@ import * as c from '../components/colors'
1923

2024
import 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

174203
let cellMargin = 10
175204
let cellSidePadding = 10

0 commit comments

Comments
 (0)