Skip to content
Snippets Groups Projects
Commit 94f148ed authored by Julia Friesel's avatar Julia Friesel
Browse files

Merge branch 'master' into 11-make-getcycleday-module

parents 0f92f3f8 949c0511
No related branches found
No related tags found
No related merge requests found
import { createStackNavigator } from 'react-navigation'
import Home from './home'
import TemperatureList from './list'
import Temperature from './temperature'
import Calendar from './calendar'
import DayView from './day-view'
import Bleeding from './bleeding'
......@@ -11,8 +12,9 @@ YellowBox.ignoreWarnings(['Warning: isMounted(...) is deprecated'])
export default createStackNavigator({
home: { screen: Home },
temperatureList: { screen: TemperatureList },
temperature: { screen: Temperature },
calendar: { screen: Calendar },
dayView: { screen: DayView },
bleeding: { screen: Bleeding }
})
\ No newline at end of file
})
......@@ -17,22 +17,21 @@ const getCycleDayNumber = cycleDayModule()
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 },
......@@ -50,13 +49,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
......
......@@ -28,24 +28,38 @@ export default class DayView extends Component {
render() {
const navigate = this.props.navigation.navigate
const day = this.cycleDay
const bleedingValue = day.bleeding && day.bleeding.value
const cycleDay = this.cycleDay
const bleedingValue = cycleDay.bleeding && cycleDay.bleeding.value
let bleedingLabel
if (typeof bleedingValue === 'number') {
bleedingLabel = `Bleeding: ${labels[bleedingValue]}`
if (cycleDay.bleeding.exclude) bleedingLabel += " (Excluded)"
} 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 (
<View style={styles.container}>
<Text style={styles.welcome}>{formatDateForViewHeader(day.date)}</Text>
<Text>Cycle day {getCycleDayNumber(day.date)}</Text>
<Text style={styles.welcome}>{formatDateForViewHeader(cycleDay.date)}</Text>
<Text>Cycle day {getCycleDayNumber(cycleDay.date)}</Text>
<Text style={styles.welcome}>{bleedingLabel}</Text>
<Text style={styles.welcome}>{temperatureLabel}</Text>
<Button
onPress={() => navigate('bleeding', { cycleDay: day })}
onPress={() => navigate('bleeding', { cycleDay })}
title="Edit bleeding">
</Button>
<Button
onPress={() => navigate('temperature', { cycleDay })}
title="Edit temperature">
</Button>
</View >
)
}
......
import Realm from 'realm'
import { LocalDate } from 'js-joda'
const TemperatureSchema = {
name: 'Temperature',
......@@ -42,16 +44,12 @@ const db = new Realm({
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 temperatureDaysSortedByDate = db.objects('CycleDay').filtered('temperature != null').sorted('date', true)
function saveTemperature(date, temperature) {
function saveTemperature(cycleDay, temperature) {
db.write(() => {
const doc = {
date,
temperature
}
db.create('CycleDay', doc)
cycleDay.temperature = temperature
})
}
......@@ -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 {
cycleDaysSortedbyTempValueView,
saveTemperature,
saveBleeding,
getOrCreateCycleDay,
bleedingDaysSortedByDate,
getCycleDaysSortedByDateView,
deleteAll
}
\ No newline at end of file
deleteAll,
getPreviousTemperature
}
......@@ -4,10 +4,10 @@ import {
Button,
Text
} from 'react-native'
import { LocalDate } from 'js-joda'
import styles from './styles'
import cycleDayModule from './get-cycle-day-number'
import { bleedingDaysSortedByDate, deleteAll } from './db'
import { LocalDate } from 'js-joda'
import { getOrCreateCycleDay, bleedingDaysSortedByDate, deleteAll } from './db'
const getCycleDayNumber = cycleDayModule()
......@@ -28,13 +28,20 @@ export default class Home extends Component {
bleedingDaysSortedByDate.removeAllListeners()
}
passTodayToDayView() {
const todayDateString = LocalDate.now().toString()
const cycleDay = getOrCreateCycleDay(todayDateString)
const navigate = this.props.navigation.navigate
navigate('dayView', { cycleDay })
}
render() {
const navigate = this.props.navigation.navigate
return (
<View style={styles.container}>
<Text style={styles.welcome}>{this.state.welcomeText}</Text>
<Button
onPress={() => navigate('temperatureList')}
onPress={() => this.passTodayToDayView()}
title="Edit symptoms for today">
</Button>
<Button
......@@ -58,4 +65,4 @@ function determineWelcomeText(cycleDayNumber) {
function setStateWithCurrentWelcomeText() {
this.setState({ welcomeText: determineWelcomeText(getCycleDayNumber(this.todayDateString)) })
}
\ No newline at end of file
}
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>
)
}
}
Source diff could not be displayed: it is too large. Options to address this: view the blob.
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>
)
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment