From cc9746a0acb3bd0d1ae938f3b66b6dd70c11e679 Mon Sep 17 00:00:00 2001 From: Julia Friesel <julia.friesel@gmail.com> Date: Tue, 12 Jun 2018 12:45:32 +0200 Subject: [PATCH] Remove cycleDay from state --- bleeding.js | 13 ++++++------- temperature.js | 13 ++++++------- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/bleeding.js b/bleeding.js index 359a94f8..01fc4ce7 100644 --- a/bleeding.js +++ b/bleeding.js @@ -15,22 +15,21 @@ import getCycleDay from './get-cycle-day' export default class Bleeding extends Component { constructor(props) { super(props) - const cycleDay = props.navigation.state.params.cycleDay - let bleedingValue = cycleDay.bleeding && cycleDay.bleeding.value + this.cycleDay = props.navigation.state.params.cycleDay + let bleedingValue = this.cycleDay.bleeding && this.cycleDay.bleeding.value if (! (typeof bleedingValue === 'number') ){ bleedingValue = -1 } this.state = { - cycleDay, currentValue: bleedingValue, - exclude: cycleDay.bleeding ? cycleDay.bleeding.exclude : false + exclude: this.cycleDay.bleeding ? this.cycleDay.bleeding.exclude : false } } // TODO display cycle day render() { const navigate = this.props.navigation.navigate - const day = this.state.cycleDay + const day = this.cycleDay const bleedingRadioProps = [ {label: labels[0], value: 0 }, {label: labels[1], value: 1 }, @@ -48,13 +47,13 @@ export default class Bleeding extends Component { formHorizontal={true} labelHorizontal={false} onPress={(itemValue) => { - this.setState({ currentValue: itemValue }) + this.setState({currentValue: itemValue}) }} /> <Text>Exclude</Text> <Switch onValueChange={(val) => { - this.setState({ exclude: val }) + this.setState({exclude: val}) }} value={this.state.exclude} /> <Button diff --git a/temperature.js b/temperature.js index 03491e6d..cbeed317 100644 --- a/temperature.js +++ b/temperature.js @@ -15,26 +15,25 @@ import getCycleDay from './get-cycle-day' export default class Temp extends Component { constructor(props) { super(props) - const cycleDay = props.navigation.state.params.cycleDay + this.cycleDay = props.navigation.state.params.cycleDay let initialValue - if(cycleDay.temperature) { - initialValue = cycleDay.temperature.value.toString() + if(this.cycleDay.temperature) { + initialValue = this.cycleDay.temperature.value.toString() } else { - const prevTemp = getPreviousTemperature(cycleDay) + const prevTemp = getPreviousTemperature(this.cycleDay) initialValue = prevTemp ? prevTemp.toString() : '' } this.state = { - cycleDay, currentValue: initialValue, - exclude: cycleDay.temperature ? cycleDay.temperature.exclude : false + exclude: this.cycleDay.temperature ? this.cycleDay.temperature.exclude : false } } render() { const navigate = this.props.navigation.navigate - const cycleDay = this.state.cycleDay + const cycleDay = this.cycleDay return ( <View style={styles.container}> <Text style={styles.welcome}>{formatDateForViewHeader(cycleDay.date)}</Text> -- GitLab