Re-add delete all button

This commit is contained in:
Julia Friesel
2018-07-23 12:59:40 +02:00
parent f52401d05d
commit 201a0d0ae1
3 changed files with 46 additions and 20 deletions
+32 -19
View File
@@ -269,17 +269,33 @@ function setUpFertilityStatusFunc() {
function dateIsInPeriOrPostPhase(dateString) { function dateIsInPeriOrPostPhase(dateString) {
return ( return (
dateString >= cycleStatus.phases.periOvulatory.start.date && dateString >= cycleStatus.phases.periOvulatory.start.date
dateString <= cycleStatus.phases.postOvulatory.start.date
) )
} }
function precededByAnotherTempValue(dateString) { function precededByAnotherTempValue(dateString) {
return Object.keys(cycleStatus.phases).some(phaseName => { return (
return cycleStatus.phases[phaseName].cycleDays.some(day => { // we are only interested in days that have a preceding
return day.temperature && day.date < dateString // temp
Object.keys(cycleStatus.phases).some(phaseName => {
return cycleStatus.phases[phaseName].cycleDays.some(day => {
return day.temperature && day.date < dateString
})
}) })
}) // and also a following temp, so we don't draw the line
// longer than necessary
&&
cycleStatus.phases.postOvulatory.cycleDays.some(day => {
return day.temperature && day.date > dateString
})
)
}
function isInTempMeasuringPhase(cycleDay, dateString) {
return (
cycleDay && cycleDay.temperature
|| precededByAnotherTempValue(dateString)
)
} }
return function(dateString, cycleDay) { return function(dateString, cycleDay) {
@@ -292,20 +308,17 @@ function setUpFertilityStatusFunc() {
const tempShift = cycleStatus.temperatureShift const tempShift = cycleStatus.temperatureShift
if ( if (tempShift) {
tempShift && if (tempShift.firstHighMeasurementDay.date === dateString) {
tempShift.firstHighMeasurementDay.date === dateString ret.drawFhmLine = true
) { }
ret.drawFhmLine = true
}
if ( if (
tempShift && dateIsInPeriOrPostPhase(dateString) &&
cycleDay && isInTempMeasuringPhase(cycleDay, dateString)
(cycleDay.temperature || precededByAnotherTempValue(dateString)) && ) {
dateIsInPeriOrPostPhase(dateString) ret.drawLtlAt = normalizeToScale(tempShift.ltl)
) { }
ret.drawLtlAt = normalizeToScale(tempShift.ltl)
} }
return ret return ret
+7 -1
View File
@@ -7,7 +7,7 @@ import {
import { LocalDate } from 'js-joda' import { LocalDate } from 'js-joda'
import styles from '../styles/index' import styles from '../styles/index'
import cycleModule from '../lib/cycle' import cycleModule from '../lib/cycle'
import { getOrCreateCycleDay, bleedingDaysSortedByDate, fillWithDummyData } from '../db' import { getOrCreateCycleDay, bleedingDaysSortedByDate, fillWithDummyData, deleteAll } from '../db'
const getCycleDayNumber = cycleModule().getCycleDayNumber const getCycleDayNumber = cycleModule().getCycleDayNumber
@@ -73,6 +73,12 @@ export default class Home extends Component {
title="fill with example data"> title="fill with example data">
</Button> </Button>
</View> </View>
<View style={styles.homeButton}>
<Button
onPress={() => deleteAll()}
title="delete everything">
</Button>
</View>
</View> </View>
</View> </View>
) )
+7
View File
@@ -117,6 +117,12 @@ function fillWithDummyData() {
}) })
} }
function deleteAll() {
db.write(() => {
db.deleteAll()
})
}
function getPreviousTemperature(cycleDay) { function getPreviousTemperature(cycleDay) {
cycleDay.wrappedDate = LocalDate.parse(cycleDay.date) cycleDay.wrappedDate = LocalDate.parse(cycleDay.date)
const winner = temperatureDaysSortedByDate.find(day => { const winner = temperatureDaysSortedByDate.find(day => {
@@ -134,6 +140,7 @@ export {
temperatureDaysSortedByDate, temperatureDaysSortedByDate,
cycleDaysSortedByDate, cycleDaysSortedByDate,
fillWithDummyData, fillWithDummyData,
deleteAll,
getPreviousTemperature, getPreviousTemperature,
getCycleDay getCycleDay
} }