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

Re-add delete all button

parent f52401d0
No related branches found
No related tags found
No related merge requests found
......@@ -269,17 +269,33 @@ function setUpFertilityStatusFunc() {
function dateIsInPeriOrPostPhase(dateString) {
return (
dateString >= cycleStatus.phases.periOvulatory.start.date &&
dateString <= cycleStatus.phases.postOvulatory.start.date
dateString >= cycleStatus.phases.periOvulatory.start.date
)
}
function precededByAnotherTempValue(dateString) {
return Object.keys(cycleStatus.phases).some(phaseName => {
return cycleStatus.phases[phaseName].cycleDays.some(day => {
return day.temperature && day.date < dateString
return (
// we are only interested in days that have a preceding
// 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) {
......@@ -292,20 +308,17 @@ function setUpFertilityStatusFunc() {
const tempShift = cycleStatus.temperatureShift
if (
tempShift &&
tempShift.firstHighMeasurementDay.date === dateString
) {
ret.drawFhmLine = true
}
if (tempShift) {
if (tempShift.firstHighMeasurementDay.date === dateString) {
ret.drawFhmLine = true
}
if (
tempShift &&
cycleDay &&
(cycleDay.temperature || precededByAnotherTempValue(dateString)) &&
dateIsInPeriOrPostPhase(dateString)
) {
ret.drawLtlAt = normalizeToScale(tempShift.ltl)
if (
dateIsInPeriOrPostPhase(dateString) &&
isInTempMeasuringPhase(cycleDay, dateString)
) {
ret.drawLtlAt = normalizeToScale(tempShift.ltl)
}
}
return ret
......
......@@ -7,7 +7,7 @@ import {
import { LocalDate } from 'js-joda'
import styles from '../styles/index'
import cycleModule from '../lib/cycle'
import { getOrCreateCycleDay, bleedingDaysSortedByDate, fillWithDummyData } from '../db'
import { getOrCreateCycleDay, bleedingDaysSortedByDate, fillWithDummyData, deleteAll } from '../db'
const getCycleDayNumber = cycleModule().getCycleDayNumber
......@@ -73,6 +73,12 @@ export default class Home extends Component {
title="fill with example data">
</Button>
</View>
<View style={styles.homeButton}>
<Button
onPress={() => deleteAll()}
title="delete everything">
</Button>
</View>
</View>
</View>
)
......
......@@ -117,6 +117,12 @@ function fillWithDummyData() {
})
}
function deleteAll() {
db.write(() => {
db.deleteAll()
})
}
function getPreviousTemperature(cycleDay) {
cycleDay.wrappedDate = LocalDate.parse(cycleDay.date)
const winner = temperatureDaysSortedByDate.find(day => {
......@@ -134,6 +140,7 @@ export {
temperatureDaysSortedByDate,
cycleDaysSortedByDate,
fillWithDummyData,
deleteAll,
getPreviousTemperature,
getCycleDay
}
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