links the period reminder to bleeding days, meaning it gets updated when they change

This commit is contained in:
tina
2018-09-26 12:15:09 +02:00
parent 7101619318
commit 09a71a391e
+12 -4
View File
@@ -3,7 +3,7 @@ import Notification from 'react-native-push-notification'
import { LocalDate } from 'js-joda'
import Moment from 'moment'
import { settings as labels } from '../components/labels'
import { getOrCreateCycleDay } from '../db'
import { getOrCreateCycleDay, getBleedingDaysSortedByDate } from '../db'
import cycleModule from './cycle'
export default function setupNotifications(navigate) {
@@ -44,7 +44,17 @@ export default function setupNotifications(navigate) {
periodReminderObservable(reminder => {
Notification.cancelLocalNotifications({id: '2'})
if (reminder.enabled) {
if (reminder.enabled) setupPeriodReminder()
})
getBleedingDaysSortedByDate().addListener(() => {
Notification.cancelLocalNotifications({id: '2'})
if (periodReminderObservable.value.enabled) setupPeriodReminder()
})
}
function setupPeriodReminder() {
const bleedingPrediction = cycleModule().getPredictedMenses()
if (bleedingPrediction.length > 0) {
const bleedingStart = Moment(bleedingPrediction[0][0], "YYYY-MM-DD")
@@ -64,6 +74,4 @@ export default function setupNotifications(navigate) {
vibrate: false
})
}
}
})
}