Replace action button footer in remaining symptom views

This commit is contained in:
Julia Friesel
2018-08-20 13:44:05 +02:00
parent d897c3b89f
commit 8629fd5369
10 changed files with 375 additions and 394 deletions
+9 -25
View File
@@ -1,5 +1,5 @@
import React, { Component } from 'react' import React, { Component } from 'react'
import { View, BackHandler, ScrollView } from 'react-native' import { View, BackHandler } from 'react-native'
import Header from './components/header' import Header from './components/header'
import Menu from './components/menu' import Menu from './components/menu'
import Home from './components/home' import Home from './components/home'
@@ -9,11 +9,11 @@ import symptomViews from './components/cycle-day/symptoms'
import Chart from './components/chart/chart' import Chart from './components/chart/chart'
import Settings from './components/settings' import Settings from './components/settings'
import Stats from './components/stats' import Stats from './components/stats'
import styles from './styles'
// this is until react native fixes this bugg, see // this is until react native fixes this bugg, see
// https://github.com/facebook/react-native/issues/18868#issuecomment-382671739 // https://github.com/facebook/react-native/issues/18868#issuecomment-382671739
import { YellowBox } from 'react-native' import { YellowBox } from 'react-native'
import ActionButtonFooter from './components/cycle-day/symptoms/action-button-footer';
YellowBox.ignoreWarnings(['Warning: isMounted(...) is deprecated']) YellowBox.ignoreWarnings(['Warning: isMounted(...) is deprecated'])
const isSymptomView = name => Object.keys(symptomViews).indexOf(name) > -1 const isSymptomView = name => Object.keys(symptomViews).indexOf(name) > -1
@@ -46,38 +46,22 @@ export default class App extends Component {
this.setState({currentPage: pageName, currentProps: props}) this.setState({currentPage: pageName, currentProps: props})
} }
setActionButtonState(actionButtonInfo) {
this.setState({actionButtonInfo})
}
unsetActionButtonState() {
this.setState({actionButtonInfo: null})
}
render() { render() {
const page = { const page = {
Home, Calendar, CycleDay, Chart, Settings, Stats, ...symptomViews Home, Calendar, CycleDay, Chart, Settings, Stats, ...symptomViews
}[this.state.currentPage] }[this.state.currentPage]
return ( return (
<View style={{height: '100%', justifyContent: 'space-between' }}> <View style={styles.menuOnBottom}>
<View>
{this.state.currentPage != 'CycleDay' && <Header title={this.state.currentPage}/>} {this.state.currentPage != 'CycleDay' && <Header title={this.state.currentPage} />}
<ScrollView>
{React.createElement(page, { {React.createElement(page, {
navigate: this.navigate.bind(this), navigate: this.navigate.bind(this),
setActionButtonState: this.setActionButtonState.bind(this),
unsetActionButtonState: this.unsetActionButtonState.bind(this),
...this.state.currentProps ...this.state.currentProps
})} })}
</ScrollView>
</View> {!isSymptomView(this.state.currentPage) &&
{isSymptomView(this.state.currentPage) && this.state.actionButtonInfo ? <Menu navigate={this.navigate.bind(this)} />
<ActionButtonFooter
{...this.state.actionButtonInfo}
navigate={this.navigate.bind(this)}
/>
:
<Menu navigate={this.navigate.bind(this)}/>
} }
</View> </View>
) )
+11 -13
View File
@@ -8,6 +8,7 @@ import RadioForm from 'react-native-simple-radio-button'
import styles from '../../../styles' import styles from '../../../styles'
import { saveSymptom } from '../../../db' import { saveSymptom } from '../../../db'
import { bleeding as labels } from '../labels/labels' import { bleeding as labels } from '../labels/labels'
import ActionButtonFooter from './action-button-footer'
export default class Bleeding extends Component { export default class Bleeding extends Component {
constructor(props) { constructor(props) {
@@ -32,8 +33,8 @@ export default class Bleeding extends Component {
{ label: labels[3], value: 3 }, { label: labels[3], value: 3 },
] ]
return ( return (
<View style={styles.menuOnBottom}>
<View> <View>
<View style={styles.symptomEditView}>
<Text style={styles.symptomDayView}>Bleeding</Text> <Text style={styles.symptomDayView}>Bleeding</Text>
<View style={styles.radioButtonRow}> <View style={styles.radioButtonRow}>
<RadioForm <RadioForm
@@ -57,21 +58,18 @@ export default class Bleeding extends Component {
/> />
</View> </View>
</View> </View>
<View style={styles.actionButtonRow}> <ActionButtonFooter
{this.makeActionButtons( symptom='bleeding'
{ cycleDay={this.props.cycleDay}
symptom: 'bleeding', saveAction={() => {
cycleDay: this.cycleDay, saveSymptom('bleeding', this.props.cycleDay, {
saveAction: () => {
saveSymptom('bleeding', this.cycleDay, {
value: this.state.currentValue, value: this.state.currentValue,
exclude: this.state.exclude exclude: this.state.exclude
}) })
}, }}
saveDisabled: this.state.currentValue === -1 saveDisabled={this.state.currentValue === -1}
} navigate={this.props.navigate}
)} />
</View>
</View> </View>
) )
} }
+17 -17
View File
@@ -12,6 +12,7 @@ import {
cervixFirmness as firmnessLabels, cervixFirmness as firmnessLabels,
cervixPosition as positionLabels cervixPosition as positionLabels
} from '../labels/labels' } from '../labels/labels'
import ActionButtonFooter from './action-button-footer'
export default class Cervix extends Component { export default class Cervix extends Component {
constructor(props) { constructor(props) {
@@ -45,10 +46,11 @@ export default class Cervix extends Component {
const cervixPositionRadioProps = [ const cervixPositionRadioProps = [
{label: positionLabels[0], value: 0 }, {label: positionLabels[0], value: 0 },
{label: positionLabels[1], value: 1 }, {label: positionLabels[1], value: 1 },
{label: positionLabels[2], value: 2 } { label: positionLabels[2], value: 2 }
] ]
return( return (
<View style={ styles.symptomEditView }> <View style={styles.menuOnBottom}>
<View>
<Text style={styles.symptomDayView}>Cervix</Text> <Text style={styles.symptomDayView}>Cervix</Text>
<Text style={styles.symptomDayView}>Opening</Text> <Text style={styles.symptomDayView}>Opening</Text>
<View style={styles.radioButtonRow}> <View style={styles.radioButtonRow}>
@@ -59,7 +61,7 @@ export default class Cervix extends Component {
labelHorizontal={false} labelHorizontal={false}
labelStyle={styles.radioButton} labelStyle={styles.radioButton}
onPress={(itemValue) => { onPress={(itemValue) => {
this.setState({opening: itemValue}) this.setState({ opening: itemValue })
}} }}
/> />
</View> </View>
@@ -72,7 +74,7 @@ export default class Cervix extends Component {
labelHorizontal={false} labelHorizontal={false}
labelStyle={styles.radioButton} labelStyle={styles.radioButton}
onPress={(itemValue) => { onPress={(itemValue) => {
this.setState({firmness: itemValue}) this.setState({ firmness: itemValue })
}} }}
/> />
</View> </View>
@@ -85,7 +87,7 @@ export default class Cervix extends Component {
labelHorizontal={false} labelHorizontal={false}
labelStyle={styles.radioButton} labelStyle={styles.radioButton}
onPress={(itemValue) => { onPress={(itemValue) => {
this.setState({position: itemValue}) this.setState({ position: itemValue })
}} }}
/> />
</View> </View>
@@ -98,23 +100,21 @@ export default class Cervix extends Component {
value={this.state.exclude} value={this.state.exclude}
/> />
</View> </View>
<View style={styles.actionButtonRow}> </View>
{this.makeActionButtons( <ActionButtonFooter
{ symptom='cervix'
symptom: 'cervix', cycleDay={this.cycleDay}
cycleDay: this.cycleDay, saveAction={() => {
saveAction: () => {
saveSymptom('cervix', this.cycleDay, { saveSymptom('cervix', this.cycleDay, {
opening: this.state.opening, opening: this.state.opening,
firmness: this.state.firmness, firmness: this.state.firmness,
position: this.state.position, position: this.state.position,
exclude: this.state.exclude exclude: this.state.exclude
}) })
}, }}
saveDisabled: this.state.opening === -1 || this.state.firmness === -1 saveDisabled={this.state.opening === -1 || this.state.firmness === -1}
} navigate={this.props.navigate}
)} />
</View>
</View> </View>
) )
} }
+12 -12
View File
@@ -7,6 +7,7 @@ import RadioForm from 'react-native-simple-radio-button'
import styles from '../../../styles' import styles from '../../../styles'
import { saveSymptom } from '../../../db' import { saveSymptom } from '../../../db'
import { intensity as labels } from '../labels/labels' import { intensity as labels } from '../labels/labels'
import ActionButtonFooter from './action-button-footer'
export default class Desire extends Component { export default class Desire extends Component {
constructor(props) { constructor(props) {
@@ -27,7 +28,8 @@ export default class Desire extends Component {
{ label: labels[2], value: 2 } { label: labels[2], value: 2 }
] ]
return ( return (
<View style={styles.symptomEditView}> <View style={styles.menuOnBottom}>
<View>
<Text style={styles.symptomDayView}>Desire</Text> <Text style={styles.symptomDayView}>Desire</Text>
<View style={styles.radioButtonRow}> <View style={styles.radioButtonRow}>
<RadioForm <RadioForm
@@ -41,18 +43,16 @@ export default class Desire extends Component {
}} }}
/> />
</View> </View>
<View style={styles.actionButtonRow}>
{this.makeActionButtons(
{
symptom: 'desire',
cycleDay: this.cycleDay,
saveAction: () => {
saveSymptom('desire', this.cycleDay, { value: this.state.currentValue })
},
saveDisabled: this.state.currentValue === -1
}
)}
</View> </View>
<ActionButtonFooter
symptom='desire'
cycleDay={this.cycleDay}
saveAction={() => {
saveSymptom('desire', this.cycleDay, { value: this.state.currentValue })
}}
saveDisabled={this.state.currentValue === -1}
navigate={this.props.navigate}
/>
</View> </View>
) )
} }
+22 -25
View File
@@ -12,6 +12,7 @@ import {
mucusTexture as textureLabels mucusTexture as textureLabels
} from '../labels/labels' } from '../labels/labels'
import computeSensiplanValue from '../../../lib/sensiplan-mucus' import computeSensiplanValue from '../../../lib/sensiplan-mucus'
import ActionButtonFooter from './action-button-footer'
export default class Mucus extends Component { export default class Mucus extends Component {
@@ -31,23 +32,23 @@ export default class Mucus extends Component {
} }
}) })
/* eslint-enable react/no-direct-mutation-state */ /* eslint-enable react/no-direct-mutation-state */
} }
render() { render() {
const mucusFeelingRadioProps = [ const mucusFeelingRadioProps = [
{label: feelingLabels[0], value: 0 }, { label: feelingLabels[0], value: 0 },
{label: feelingLabels[1], value: 1 }, { label: feelingLabels[1], value: 1 },
{label: feelingLabels[2], value: 2 }, { label: feelingLabels[2], value: 2 },
{label: feelingLabels[3], value: 3 } { label: feelingLabels[3], value: 3 }
] ]
const mucusTextureRadioProps = [ const mucusTextureRadioProps = [
{label: textureLabels[0], value: 0 }, { label: textureLabels[0], value: 0 },
{label: textureLabels[1], value: 1 }, { label: textureLabels[1], value: 1 },
{label: textureLabels[2], value: 2 } { label: textureLabels[2], value: 2 }
] ]
return( return (
<View style={ styles.symptomEditView }> <View style={styles.menuOnBottom}>
<View>
<Text style={styles.symptomDayView}>Mucus</Text> <Text style={styles.symptomDayView}>Mucus</Text>
<Text style={styles.symptomDayView}>Feeling</Text> <Text style={styles.symptomDayView}>Feeling</Text>
<View style={styles.radioButtonRow}> <View style={styles.radioButtonRow}>
@@ -58,7 +59,7 @@ export default class Mucus extends Component {
labelHorizontal={false} labelHorizontal={false}
labelStyle={styles.radioButton} labelStyle={styles.radioButton}
onPress={(itemValue) => { onPress={(itemValue) => {
this.setState({feeling: itemValue }) this.setState({ feeling: itemValue })
}} }}
/> />
</View> </View>
@@ -71,7 +72,7 @@ export default class Mucus extends Component {
labelHorizontal={false} labelHorizontal={false}
labelStyle={styles.radioButton} labelStyle={styles.radioButton}
onPress={(itemValue) => { onPress={(itemValue) => {
this.setState({texture: itemValue }) this.setState({ texture: itemValue })
}} }}
/> />
</View> </View>
@@ -84,25 +85,21 @@ export default class Mucus extends Component {
value={this.state.exclude} value={this.state.exclude}
/> />
</View> </View>
</View>
<View style={styles.actionButtonRow}> <ActionButtonFooter
{this.makeActionButtons( symptom='mucus'
{ cycleDay={this.cycleDay}
symptom: 'mucus', saveAction={() => {
cycleDay: this.cycleDay,
saveAction: () => {
saveSymptom('mucus', this.cycleDay, { saveSymptom('mucus', this.cycleDay, {
feeling: this.state.feeling, feeling: this.state.feeling,
texture: this.state.texture, texture: this.state.texture,
value: computeSensiplanValue(this.state.feeling, this.state.texture), value: computeSensiplanValue(this.state.feeling, this.state.texture),
exclude: this.state.exclude exclude: this.state.exclude
}) })
}, }}
saveDisabled: this.state.feeling === -1 || this.state.texture === -1 saveDisabled={this.state.feeling === -1 || this.state.texture === -1}
} navigate={this.props.navigate}
)} />
</View>
</View> </View>
) )
} }
+10 -10
View File
@@ -7,6 +7,7 @@ import {
import styles from '../../../styles' import styles from '../../../styles'
import { saveSymptom } from '../../../db' import { saveSymptom } from '../../../db'
import ActionButtonFooter from './action-button-footer'
export default class Temp extends Component { export default class Temp extends Component {
constructor(props) { constructor(props) {
@@ -22,7 +23,7 @@ export default class Temp extends Component {
render() { render() {
return ( return (
<View style={styles.symptomEditView}> <View style={styles.menuOnBottom}>
<View style={styles.symptomViewRow}> <View style={styles.symptomViewRow}>
<Text style={styles.symptomDayView}>Note</Text> <Text style={styles.symptomDayView}>Note</Text>
<TextInput <TextInput
@@ -34,18 +35,17 @@ export default class Temp extends Component {
value={this.state.currentValue} value={this.state.currentValue}
/> />
</View> </View>
<View style={styles.actionButtonRow}> <ActionButtonFooter
{this.makeActionButtons({ symptom='note'
symptom: 'note', cycleDay={this.cycleDay}
cycleDay: this.cycleDay, saveAction={() => {
saveAction: () => {
saveSymptom('note', this.cycleDay, { saveSymptom('note', this.cycleDay, {
value: this.state.currentValue value: this.state.currentValue
}) })
}, }}
saveDisabled: !this.state.currentValue saveDisabled={!this.state.currentValue}
})} navigate={this.props.navigate}
</View> />
</View> </View>
) )
} }
+22 -22
View File
@@ -11,6 +11,7 @@ import {
sexActivity as activityLabels, sexActivity as activityLabels,
contraceptives as contraceptiveLabels contraceptives as contraceptiveLabels
} from '../labels/labels' } from '../labels/labels'
import ActionButtonFooter from './action-button-footer'
export default class Sex extends Component { export default class Sex extends Component {
constructor(props) { constructor(props) {
@@ -30,21 +31,22 @@ export default class Sex extends Component {
render() { render() {
return ( return (
<View style={styles.symptomEditView}> <View style={styles.menuOnBottom}>
<View>
<Text style={styles.symptomDayView}>SEX</Text> <Text style={styles.symptomDayView}>SEX</Text>
<View style={styles.symptomViewRowInline}> <View style={styles.symptomViewRowInline}>
<Text style={styles.symptomDayView}>{activityLabels.solo}</Text> <Text style={styles.symptomDayView}>{activityLabels.solo}</Text>
<CheckBox <CheckBox
value={this.state.solo} value={this.state.solo}
onValueChange={(val) => { onValueChange={(val) => {
this.setState({solo: val}) this.setState({ solo: val })
}} }}
/> />
<Text style={styles.symptomDayView}>{activityLabels.partner}</Text> <Text style={styles.symptomDayView}>{activityLabels.partner}</Text>
<CheckBox <CheckBox
value={this.state.partner} value={this.state.partner}
onValueChange={(val) => { onValueChange={(val) => {
this.setState({partner: val}) this.setState({ partner: val })
}} }}
/> />
</View> </View>
@@ -56,7 +58,7 @@ export default class Sex extends Component {
<CheckBox <CheckBox
value={this.state.condom} value={this.state.condom}
onValueChange={(val) => { onValueChange={(val) => {
this.setState({condom: val}) this.setState({ condom: val })
}} }}
/> />
<Text style={styles.symptomDayView}> <Text style={styles.symptomDayView}>
@@ -65,7 +67,7 @@ export default class Sex extends Component {
<CheckBox <CheckBox
value={this.state.pill} value={this.state.pill}
onValueChange={(val) => { onValueChange={(val) => {
this.setState({pill: val}) this.setState({ pill: val })
}} }}
/> />
</View> </View>
@@ -76,7 +78,7 @@ export default class Sex extends Component {
<CheckBox <CheckBox
value={this.state.iud} value={this.state.iud}
onValueChange={(val) => { onValueChange={(val) => {
this.setState({iud: val}) this.setState({ iud: val })
}} }}
/> />
<Text style={styles.symptomDayView}> <Text style={styles.symptomDayView}>
@@ -85,7 +87,7 @@ export default class Sex extends Component {
<CheckBox <CheckBox
value={this.state.patch} value={this.state.patch}
onValueChange={(val) => { onValueChange={(val) => {
this.setState({patch: val}) this.setState({ patch: val })
}} }}
/> />
</View> </View>
@@ -96,7 +98,7 @@ export default class Sex extends Component {
<CheckBox <CheckBox
value={this.state.ring} value={this.state.ring}
onValueChange={(val) => { onValueChange={(val) => {
this.setState({ring: val}) this.setState({ ring: val })
}} }}
/> />
<Text style={styles.symptomDayView}> <Text style={styles.symptomDayView}>
@@ -105,7 +107,7 @@ export default class Sex extends Component {
<CheckBox <CheckBox
value={this.state.implant} value={this.state.implant}
onValueChange={(val) => { onValueChange={(val) => {
this.setState({implant: val}) this.setState({ implant: val })
}} }}
/> />
</View> </View>
@@ -123,33 +125,31 @@ export default class Sex extends Component {
}} }}
/> />
</View> </View>
{ this.state.other && {this.state.other &&
<TextInput <TextInput
autoFocus={this.state.focusTextArea} autoFocus={this.state.focusTextArea}
multiline={true} multiline={true}
placeholder="Enter" placeholder="Enter"
value={this.state.note} value={this.state.note}
onChangeText={(val) => { onChangeText={(val) => {
this.setState({note: val}) this.setState({ note: val })
}} }}
/> />
} }
<View style={styles.actionButtonRow}> </View>
{this.props.makeActionButtons( <ActionButtonFooter
{ symptom='sex'
symptom: 'sex', cycleDay={this.cycleDay}
cycleDay: this.cycleDay, saveAction={() => {
saveAction: () => {
const copyOfState = Object.assign({}, this.state) const copyOfState = Object.assign({}, this.state)
if (!copyOfState.other) { if (!copyOfState.other) {
copyOfState.note = null copyOfState.note = null
} }
saveSymptom('sex', this.cycleDay, copyOfState) saveSymptom('sex', this.cycleDay, copyOfState)
}, }}
saveDisabled: Object.values(this.state).every(value => !value) saveDisabled={Object.values(this.state).every(value => !value)}
} navigate={this.props.navigate}
)} />
</View>
</View> </View>
) )
} }
+18 -19
View File
@@ -11,6 +11,7 @@ import DateTimePicker from 'react-native-modal-datetime-picker-nevo'
import { getPreviousTemperature, saveSymptom } from '../../../db' import { getPreviousTemperature, saveSymptom } from '../../../db'
import styles from '../../../styles' import styles from '../../../styles'
import { LocalTime, ChronoUnit } from 'js-joda' import { LocalTime, ChronoUnit } from 'js-joda'
import ActionButtonFooter from './action-button-footer'
const MINUTES = ChronoUnit.MINUTES const MINUTES = ChronoUnit.MINUTES
@@ -37,29 +38,12 @@ export default class Temp extends Component {
time: this.time || LocalTime.now().truncatedTo(MINUTES).toString(), time: this.time || LocalTime.now().truncatedTo(MINUTES).toString(),
isTimePickerVisible: false isTimePickerVisible: false
} }
props.setActionButtonState({
symptom : 'temperature',
cycleDay: props.cycleDay,
saveAction: () => {
const dataToSave = {
value: Number(this.state.currentValue),
exclude: this.state.exclude,
time: this.state.time
}
saveSymptom('temperature', props.cycleDay, dataToSave)
},
saveDisabled: this.state.currentValue === '' || isInvalidTime(this.state.time)
})
}
componentWillUnmount() {
this.props.unsetActionButtonState()
} }
render() { render() {
return ( return (
<View style={styles.symptomEditView}> <View style={styles.menuOnBottom}>
<View>
<View style={styles.symptomViewRowInline}> <View style={styles.symptomViewRowInline}>
<Text style={styles.symptomDayView}>Temperature (°C)</Text> <Text style={styles.symptomDayView}>Temperature (°C)</Text>
<TextInput <TextInput
@@ -104,6 +88,21 @@ export default class Temp extends Component {
/> />
</View> </View>
</View> </View>
<ActionButtonFooter
symptom='temperature'
cycleDay={this.cycleDay}
saveAction={() => {
const dataToSave = {
value: Number(this.state.currentValue),
exclude: this.state.exclude,
time: this.state.time
}
saveSymptom('temperature', this.props.cycleDay, dataToSave)
}}
saveDisabled={this.state.currentValue === '' || isInvalidTime(this.state.time)}
navigate={this.props.navigate}
/>
</View>
) )
} }
} }
-1
View File
@@ -5,7 +5,6 @@ import {
ScrollView ScrollView
} from 'react-native' } from 'react-native'
import { LocalDate, ChronoUnit } from 'js-joda' import { LocalDate, ChronoUnit } from 'js-joda'
import Header from './header'
import styles from '../styles/index' import styles from '../styles/index'
import cycleModule from '../lib/cycle' import cycleModule from '../lib/cycle'
import getCycleInfo from '../lib/cycle-length' import getCycleInfo from '../lib/cycle-length'
+4
View File
@@ -83,6 +83,10 @@ export default StyleSheet.create({
symptomDataText: { symptomDataText: {
fontSize: 12 fontSize: 12
}, },
menuOnBottom: {
flex: 1,
justifyContent: 'space-between'
},
symptomEditRow: { symptomEditRow: {
justifyContent: 'space-between', justifyContent: 'space-between',
marginBottom: 10, marginBottom: 10,