diff --git a/.eslintrc b/.eslintrc index 9fa10f3..24f9ab5 100644 --- a/.eslintrc +++ b/.eslintrc @@ -47,6 +47,6 @@ "no-var": "error", "prefer-const": "error", "no-trailing-spaces": "error", - "react/prop-types": ["error", {"ignore": ["navigation"]}] + "react/prop-types": 0 } } \ No newline at end of file diff --git a/app.js b/app.js index 3a310a0..70c1a05 100644 --- a/app.js +++ b/app.js @@ -1,10 +1,8 @@ import { createStackNavigator } from 'react-navigation' import Home from './home' -import Temperature from './temperature' import Calendar from './calendar' -import DayView from './day-view' -import Bleeding from './bleeding' +import CycleDay from './cycle-day' // this is until react native fixes this bug, see https://github.com/facebook/react-native/issues/18868#issuecomment-382671739 import { YellowBox } from 'react-native' @@ -12,9 +10,6 @@ YellowBox.ignoreWarnings(['Warning: isMounted(...) is deprecated']) export default createStackNavigator({ home: { screen: Home }, - - temperature: { screen: Temperature }, calendar: { screen: Calendar }, - dayView: { screen: DayView }, - bleeding: { screen: Bleeding } + cycleDay: { screen: CycleDay } }) diff --git a/bleeding.js b/bleeding.js index 31dc8c6..4019e9c 100644 --- a/bleeding.js +++ b/bleeding.js @@ -8,16 +8,13 @@ import { import RadioForm from 'react-native-simple-radio-button' import styles from './styles' import { saveBleeding } from './db' -import { formatDateForViewHeader } from './format' import { bleeding as labels } from './labels' -import cycleDayModule from './get-cycle-day-number' - -const getCycleDayNumber = cycleDayModule() export default class Bleeding extends Component { constructor(props) { super(props) - this.cycleDay = props.navigation.state.params.cycleDay + this.cycleDay = props.cycleDay + this.showView = props.showView let bleedingValue = this.cycleDay.bleeding && this.cycleDay.bleeding.value if (! (typeof bleedingValue === 'number') ){ bleedingValue = -1 @@ -28,10 +25,7 @@ export default class Bleeding extends Component { } } - // TODO display cycle day render() { - const navigate = this.props.navigation.navigate - const day = this.cycleDay const bleedingRadioProps = [ {label: labels[0], value: 0 }, {label: labels[1], value: 1 }, @@ -40,8 +34,6 @@ export default class Bleeding extends Component { ] return ( - {formatDateForViewHeader(day.date)} - Cycle day {getCycleDayNumber(day.date)} Bleeding diff --git a/cycle-day.js b/cycle-day.js new file mode 100644 index 0000000..de5a577 --- /dev/null +++ b/cycle-day.js @@ -0,0 +1,45 @@ +import React, { Component } from 'react' +import { + View, + Text +} from 'react-native' +import cycleDayModule from './get-cycle-day-number' +import DayView from './cycle-day-overview' +import BleedingEditView from './bleeding' +import TemperatureEditView from './temperature' +import { formatDateForViewHeader } from './format' +import styles from './styles' + +const getCycleDayNumber = cycleDayModule() + +export default class Day extends Component { + constructor(props) { + super(props) + this.cycleDay = props.navigation.state.params.cycleDay + this.cycleDayNumber = getCycleDayNumber(this.cycleDay.date) + + this.state = { + visibleComponent: 'dayView', + } + + this.showView = view => { + this.setState({visibleComponent: view}) + } + } + + render() { + return ( + + {formatDateForViewHeader(this.cycleDay.date)} + { this.cycleDayNumber && Cycle day {this.cycleDayNumber} } + { + { dayView: , + bleedingEditView: , + temperatureEditView: + }[this.state.visibleComponent] + } + + + ) + } +} \ No newline at end of file diff --git a/home.js b/home.js index 9ae5917..81b2d13 100644 --- a/home.js +++ b/home.js @@ -32,7 +32,7 @@ export default class Home extends Component { const todayDateString = LocalDate.now().toString() const cycleDay = getOrCreateCycleDay(todayDateString) const navigate = this.props.navigation.navigate - navigate('dayView', { cycleDay }) + navigate('cycleDay', { cycleDay }) } render() { diff --git a/temperature.js b/temperature.js index 5e2f00a..786248b 100644 --- a/temperature.js +++ b/temperature.js @@ -7,17 +7,13 @@ import { Switch } from 'react-native' -import styles from './styles' import { saveTemperature, getPreviousTemperature } from './db' -import { formatDateForViewHeader } from './format' -import cycleDayModule from './get-cycle-day-number' - -const getCycleDayNumber = cycleDayModule() export default class Temp extends Component { constructor(props) { super(props) - this.cycleDay = props.navigation.state.params.cycleDay + this.cycleDay = props.cycleDay + this.showView = props.showView let initialValue if(this.cycleDay.temperature) { @@ -34,12 +30,9 @@ export default class Temp extends Component { } render() { - const navigate = this.props.navigation.navigate const cycleDay = this.cycleDay return ( - - {formatDateForViewHeader(cycleDay.date)} - Cycle day {getCycleDayNumber()} + Temperature @@ -75,7 +68,7 @@ export default class Temp extends Component { value: Number(this.state.currentValue), exclude: this.state.exclude }) - navigate('dayView', { cycleDay }) + this.showView('dayView') }} disabled={ this.state.currentValue === '' } title="Save">