Merge branch 'master' into 11-make-getcycleday-module
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
import { createStackNavigator } from 'react-navigation'
|
import { createStackNavigator } from 'react-navigation'
|
||||||
import Home from './home'
|
import Home from './home'
|
||||||
import TemperatureList from './list'
|
|
||||||
|
import Temperature from './temperature'
|
||||||
import Calendar from './calendar'
|
import Calendar from './calendar'
|
||||||
import DayView from './day-view'
|
import DayView from './day-view'
|
||||||
import Bleeding from './bleeding'
|
import Bleeding from './bleeding'
|
||||||
@@ -11,8 +12,9 @@ YellowBox.ignoreWarnings(['Warning: isMounted(...) is deprecated'])
|
|||||||
|
|
||||||
export default createStackNavigator({
|
export default createStackNavigator({
|
||||||
home: { screen: Home },
|
home: { screen: Home },
|
||||||
temperatureList: { screen: TemperatureList },
|
|
||||||
|
temperature: { screen: Temperature },
|
||||||
calendar: { screen: Calendar },
|
calendar: { screen: Calendar },
|
||||||
dayView: { screen: DayView },
|
dayView: { screen: DayView },
|
||||||
bleeding: { screen: Bleeding }
|
bleeding: { screen: Bleeding }
|
||||||
})
|
})
|
||||||
|
|||||||
+6
-7
@@ -17,22 +17,21 @@ const getCycleDayNumber = cycleDayModule()
|
|||||||
export default class Bleeding extends Component {
|
export default class Bleeding extends Component {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props)
|
super(props)
|
||||||
const cycleDay = props.navigation.state.params.cycleDay
|
this.cycleDay = props.navigation.state.params.cycleDay
|
||||||
let bleedingValue = cycleDay.bleeding && cycleDay.bleeding.value
|
let bleedingValue = this.cycleDay.bleeding && this.cycleDay.bleeding.value
|
||||||
if (! (typeof bleedingValue === 'number') ){
|
if (! (typeof bleedingValue === 'number') ){
|
||||||
bleedingValue = -1
|
bleedingValue = -1
|
||||||
}
|
}
|
||||||
this.state = {
|
this.state = {
|
||||||
cycleDay,
|
|
||||||
currentValue: bleedingValue,
|
currentValue: bleedingValue,
|
||||||
exclude: cycleDay.bleeding ? cycleDay.bleeding.exclude : false
|
exclude: this.cycleDay.bleeding ? this.cycleDay.bleeding.exclude : false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO display cycle day
|
// TODO display cycle day
|
||||||
render() {
|
render() {
|
||||||
const navigate = this.props.navigation.navigate
|
const navigate = this.props.navigation.navigate
|
||||||
const day = this.state.cycleDay
|
const day = this.cycleDay
|
||||||
const bleedingRadioProps = [
|
const bleedingRadioProps = [
|
||||||
{label: labels[0], value: 0 },
|
{label: labels[0], value: 0 },
|
||||||
{label: labels[1], value: 1 },
|
{label: labels[1], value: 1 },
|
||||||
@@ -50,13 +49,13 @@ export default class Bleeding extends Component {
|
|||||||
formHorizontal={true}
|
formHorizontal={true}
|
||||||
labelHorizontal={false}
|
labelHorizontal={false}
|
||||||
onPress={(itemValue) => {
|
onPress={(itemValue) => {
|
||||||
this.setState({ currentValue: itemValue })
|
this.setState({currentValue: itemValue})
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<Text>Exclude</Text>
|
<Text>Exclude</Text>
|
||||||
<Switch
|
<Switch
|
||||||
onValueChange={(val) => {
|
onValueChange={(val) => {
|
||||||
this.setState({ exclude: val })
|
this.setState({exclude: val})
|
||||||
}}
|
}}
|
||||||
value={this.state.exclude} />
|
value={this.state.exclude} />
|
||||||
<Button
|
<Button
|
||||||
|
|||||||
+20
-6
@@ -28,24 +28,38 @@ export default class DayView extends Component {
|
|||||||
|
|
||||||
render() {
|
render() {
|
||||||
const navigate = this.props.navigation.navigate
|
const navigate = this.props.navigation.navigate
|
||||||
const day = this.cycleDay
|
const cycleDay = this.cycleDay
|
||||||
const bleedingValue = day.bleeding && day.bleeding.value
|
const bleedingValue = cycleDay.bleeding && cycleDay.bleeding.value
|
||||||
let bleedingLabel
|
let bleedingLabel
|
||||||
if (typeof bleedingValue === 'number') {
|
if (typeof bleedingValue === 'number') {
|
||||||
bleedingLabel = `Bleeding: ${labels[bleedingValue]}`
|
bleedingLabel = `Bleeding: ${labels[bleedingValue]}`
|
||||||
|
if (cycleDay.bleeding.exclude) bleedingLabel += " (Excluded)"
|
||||||
} else {
|
} else {
|
||||||
bleedingLabel = ''
|
bleedingLabel = null
|
||||||
|
}
|
||||||
|
const temperatureValue = cycleDay.temperature && cycleDay.temperature.value
|
||||||
|
let temperatureLabel
|
||||||
|
if (typeof temperatureValue === 'number') {
|
||||||
|
temperatureLabel = `Temperature: ${temperatureValue}`
|
||||||
|
if (cycleDay.temperature.exclude) temperatureLabel += " (Excluded)"
|
||||||
|
} else {
|
||||||
|
temperatureLabel = null
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<View style={styles.container}>
|
<View style={styles.container}>
|
||||||
<Text style={styles.welcome}>{formatDateForViewHeader(day.date)}</Text>
|
<Text style={styles.welcome}>{formatDateForViewHeader(cycleDay.date)}</Text>
|
||||||
<Text>Cycle day {getCycleDayNumber(day.date)}</Text>
|
<Text>Cycle day {getCycleDayNumber(cycleDay.date)}</Text>
|
||||||
<Text style={styles.welcome}>{bleedingLabel}</Text>
|
<Text style={styles.welcome}>{bleedingLabel}</Text>
|
||||||
|
<Text style={styles.welcome}>{temperatureLabel}</Text>
|
||||||
<Button
|
<Button
|
||||||
onPress={() => navigate('bleeding', { cycleDay: day })}
|
onPress={() => navigate('bleeding', { cycleDay })}
|
||||||
title="Edit bleeding">
|
title="Edit bleeding">
|
||||||
</Button>
|
</Button>
|
||||||
|
<Button
|
||||||
|
onPress={() => navigate('temperature', { cycleDay })}
|
||||||
|
title="Edit temperature">
|
||||||
|
</Button>
|
||||||
</View >
|
</View >
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
import Realm from 'realm'
|
import Realm from 'realm'
|
||||||
|
import { LocalDate } from 'js-joda'
|
||||||
|
|
||||||
|
|
||||||
const TemperatureSchema = {
|
const TemperatureSchema = {
|
||||||
name: 'Temperature',
|
name: 'Temperature',
|
||||||
@@ -42,16 +44,12 @@ const db = new Realm({
|
|||||||
deleteRealmIfMigrationNeeded: true
|
deleteRealmIfMigrationNeeded: true
|
||||||
})
|
})
|
||||||
|
|
||||||
const cycleDaysSortedbyTempValueView = db.objects('CycleDay').filtered('temperature != null').sorted('temperature.value', true)
|
|
||||||
const bleedingDaysSortedByDate = db.objects('CycleDay').filtered('bleeding != null').sorted('date', true)
|
const bleedingDaysSortedByDate = db.objects('CycleDay').filtered('bleeding != null').sorted('date', true)
|
||||||
|
const temperatureDaysSortedByDate = db.objects('CycleDay').filtered('temperature != null').sorted('date', true)
|
||||||
|
|
||||||
function saveTemperature(date, temperature) {
|
function saveTemperature(cycleDay, temperature) {
|
||||||
db.write(() => {
|
db.write(() => {
|
||||||
const doc = {
|
cycleDay.temperature = temperature
|
||||||
date,
|
|
||||||
temperature
|
|
||||||
}
|
|
||||||
db.create('CycleDay', doc)
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -81,12 +79,22 @@ function deleteAll() {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getPreviousTemperature(cycleDay) {
|
||||||
|
cycleDay.wrappedDate = LocalDate.parse(cycleDay.date)
|
||||||
|
const winner = temperatureDaysSortedByDate.find(day => {
|
||||||
|
const wrappedDate = LocalDate.parse(day.date)
|
||||||
|
return wrappedDate.isBefore(cycleDay.wrappedDate)
|
||||||
|
})
|
||||||
|
if (!winner) return null
|
||||||
|
return winner.temperature.value
|
||||||
|
}
|
||||||
|
|
||||||
export {
|
export {
|
||||||
cycleDaysSortedbyTempValueView,
|
|
||||||
saveTemperature,
|
saveTemperature,
|
||||||
saveBleeding,
|
saveBleeding,
|
||||||
getOrCreateCycleDay,
|
getOrCreateCycleDay,
|
||||||
bleedingDaysSortedByDate,
|
bleedingDaysSortedByDate,
|
||||||
getCycleDaysSortedByDateView,
|
getCycleDaysSortedByDateView,
|
||||||
deleteAll
|
deleteAll,
|
||||||
}
|
getPreviousTemperature
|
||||||
|
}
|
||||||
|
|||||||
@@ -4,10 +4,10 @@ import {
|
|||||||
Button,
|
Button,
|
||||||
Text
|
Text
|
||||||
} from 'react-native'
|
} from 'react-native'
|
||||||
|
import { LocalDate } from 'js-joda'
|
||||||
import styles from './styles'
|
import styles from './styles'
|
||||||
import cycleDayModule from './get-cycle-day-number'
|
import cycleDayModule from './get-cycle-day-number'
|
||||||
import { bleedingDaysSortedByDate, deleteAll } from './db'
|
import { getOrCreateCycleDay, bleedingDaysSortedByDate, deleteAll } from './db'
|
||||||
import { LocalDate } from 'js-joda'
|
|
||||||
|
|
||||||
const getCycleDayNumber = cycleDayModule()
|
const getCycleDayNumber = cycleDayModule()
|
||||||
|
|
||||||
@@ -28,13 +28,20 @@ export default class Home extends Component {
|
|||||||
bleedingDaysSortedByDate.removeAllListeners()
|
bleedingDaysSortedByDate.removeAllListeners()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
passTodayToDayView() {
|
||||||
|
const todayDateString = LocalDate.now().toString()
|
||||||
|
const cycleDay = getOrCreateCycleDay(todayDateString)
|
||||||
|
const navigate = this.props.navigation.navigate
|
||||||
|
navigate('dayView', { cycleDay })
|
||||||
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const navigate = this.props.navigation.navigate
|
const navigate = this.props.navigation.navigate
|
||||||
return (
|
return (
|
||||||
<View style={styles.container}>
|
<View style={styles.container}>
|
||||||
<Text style={styles.welcome}>{this.state.welcomeText}</Text>
|
<Text style={styles.welcome}>{this.state.welcomeText}</Text>
|
||||||
<Button
|
<Button
|
||||||
onPress={() => navigate('temperatureList')}
|
onPress={() => this.passTodayToDayView()}
|
||||||
title="Edit symptoms for today">
|
title="Edit symptoms for today">
|
||||||
</Button>
|
</Button>
|
||||||
<Button
|
<Button
|
||||||
@@ -58,4 +65,4 @@ function determineWelcomeText(cycleDayNumber) {
|
|||||||
|
|
||||||
function setStateWithCurrentWelcomeText() {
|
function setStateWithCurrentWelcomeText() {
|
||||||
this.setState({ welcomeText: determineWelcomeText(getCycleDayNumber(this.todayDateString)) })
|
this.setState({ welcomeText: determineWelcomeText(getCycleDayNumber(this.todayDateString)) })
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,60 +0,0 @@
|
|||||||
import React, { Component } from 'react'
|
|
||||||
import {
|
|
||||||
View,
|
|
||||||
Text,
|
|
||||||
Button,
|
|
||||||
TextInput,
|
|
||||||
FlatList,
|
|
||||||
Keyboard
|
|
||||||
} from 'react-native'
|
|
||||||
|
|
||||||
import * as styles from './styles'
|
|
||||||
import { cycleDaysSortedbyTempValueView, saveTemperature } from './db'
|
|
||||||
|
|
||||||
export default class Temp extends Component {
|
|
||||||
constructor(props) {
|
|
||||||
super(props)
|
|
||||||
this.state = {
|
|
||||||
currentValue: '',
|
|
||||||
rerenderToggle: false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
render() {
|
|
||||||
return (
|
|
||||||
<View style={styles.container}>
|
|
||||||
<TextInput
|
|
||||||
placeholder="Enter your temperature"
|
|
||||||
onChangeText={(val) => {
|
|
||||||
this.setState({currentValue: val})
|
|
||||||
}}
|
|
||||||
keyboardType='numeric'
|
|
||||||
value = {this.state.currentValue}
|
|
||||||
/>
|
|
||||||
<Button
|
|
||||||
onPress={() => {
|
|
||||||
console.log(Number(this.state.currentValue))
|
|
||||||
saveTemperature(
|
|
||||||
new Date(),
|
|
||||||
{
|
|
||||||
value: Number(this.state.currentValue),
|
|
||||||
exclude: false
|
|
||||||
}
|
|
||||||
)
|
|
||||||
this.setState({currentValue: ''})
|
|
||||||
// FlatList only reacts to primitive value changes,
|
|
||||||
// this boolean toggle makes sure the list updates
|
|
||||||
this.setState({ reRender: !this.state.rerenderToggle})
|
|
||||||
Keyboard.dismiss()
|
|
||||||
}}
|
|
||||||
title="Save"
|
|
||||||
/>
|
|
||||||
<FlatList
|
|
||||||
data = { cycleDaysSortedbyTempValueView }
|
|
||||||
renderItem={({item}) => <Text>{item.temperature.value}</Text>}
|
|
||||||
extraData = { this.state }
|
|
||||||
/>
|
|
||||||
</View>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Generated
+1561
-1561
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,86 @@
|
|||||||
|
import React, { Component } from 'react'
|
||||||
|
import {
|
||||||
|
View,
|
||||||
|
Text,
|
||||||
|
Button,
|
||||||
|
TextInput,
|
||||||
|
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
|
||||||
|
let initialValue
|
||||||
|
|
||||||
|
if(this.cycleDay.temperature) {
|
||||||
|
initialValue = this.cycleDay.temperature.value.toString()
|
||||||
|
} else {
|
||||||
|
const prevTemp = getPreviousTemperature(this.cycleDay)
|
||||||
|
initialValue = prevTemp ? prevTemp.toString() : ''
|
||||||
|
}
|
||||||
|
|
||||||
|
this.state = {
|
||||||
|
currentValue: initialValue,
|
||||||
|
exclude: this.cycleDay.temperature ? this.cycleDay.temperature.exclude : false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
render() {
|
||||||
|
const navigate = this.props.navigation.navigate
|
||||||
|
const cycleDay = this.cycleDay
|
||||||
|
return (
|
||||||
|
<View style={styles.container}>
|
||||||
|
<Text style={styles.welcome}>{formatDateForViewHeader(cycleDay.date)}</Text>
|
||||||
|
<Text>Cycle day {getCycleDayNumber()}</Text>
|
||||||
|
<Text>Temperature</Text>
|
||||||
|
<TextInput
|
||||||
|
placeholder="Enter temperature"
|
||||||
|
onChangeText={(val) => {
|
||||||
|
this.setState({currentValue: val})
|
||||||
|
}}
|
||||||
|
keyboardType='numeric'
|
||||||
|
value = {this.state.currentValue}
|
||||||
|
/>
|
||||||
|
<Text>Exclude</Text>
|
||||||
|
<Switch
|
||||||
|
onValueChange = {(val) => {
|
||||||
|
this.setState({ exclude: val })
|
||||||
|
}}
|
||||||
|
value = { this.state.exclude }
|
||||||
|
/>
|
||||||
|
<Button
|
||||||
|
onPress={() => {
|
||||||
|
navigate('dayView', { cycleDay })
|
||||||
|
}}
|
||||||
|
title="Cancel">
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
onPress={() => {
|
||||||
|
saveTemperature(cycleDay)
|
||||||
|
navigate('dayView', { cycleDay })
|
||||||
|
}}
|
||||||
|
title="Delete entry">
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
onPress={() => {
|
||||||
|
saveTemperature(cycleDay, {
|
||||||
|
value: Number(this.state.currentValue),
|
||||||
|
exclude: this.state.exclude
|
||||||
|
})
|
||||||
|
navigate('dayView', { cycleDay })
|
||||||
|
}}
|
||||||
|
disabled={ this.state.currentValue === '' }
|
||||||
|
title="Save">
|
||||||
|
</Button>
|
||||||
|
</View>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user