links the period reminder to bleeding days, meaning it gets updated when they change
This commit is contained in:
+12
-4
@@ -3,7 +3,7 @@ import Notification from 'react-native-push-notification'
|
|||||||
import { LocalDate } from 'js-joda'
|
import { LocalDate } from 'js-joda'
|
||||||
import Moment from 'moment'
|
import Moment from 'moment'
|
||||||
import { settings as labels } from '../components/labels'
|
import { settings as labels } from '../components/labels'
|
||||||
import { getOrCreateCycleDay } from '../db'
|
import { getOrCreateCycleDay, getBleedingDaysSortedByDate } from '../db'
|
||||||
import cycleModule from './cycle'
|
import cycleModule from './cycle'
|
||||||
|
|
||||||
export default function setupNotifications(navigate) {
|
export default function setupNotifications(navigate) {
|
||||||
@@ -44,7 +44,17 @@ export default function setupNotifications(navigate) {
|
|||||||
|
|
||||||
periodReminderObservable(reminder => {
|
periodReminderObservable(reminder => {
|
||||||
Notification.cancelLocalNotifications({id: '2'})
|
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()
|
const bleedingPrediction = cycleModule().getPredictedMenses()
|
||||||
if (bleedingPrediction.length > 0) {
|
if (bleedingPrediction.length > 0) {
|
||||||
const bleedingStart = Moment(bleedingPrediction[0][0], "YYYY-MM-DD")
|
const bleedingStart = Moment(bleedingPrediction[0][0], "YYYY-MM-DD")
|
||||||
@@ -64,6 +74,4 @@ export default function setupNotifications(navigate) {
|
|||||||
vibrate: false
|
vibrate: false
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user