makes period reminder functional

This commit is contained in:
tina
2018-09-25 16:55:13 +02:00
parent 80bec57f69
commit 7101619318
+15 -12
View File
@@ -8,13 +8,11 @@ import cycleModule from './cycle'
export default function setupNotifications(navigate) {
Notification.configure({
onNotification: () => {
const todayDateString = LocalDate.now().toString()
const cycleDay = getOrCreateCycleDay(todayDateString)
if (this.id === '1') {
onNotification: (notification) => {
if (notification.id === '1') {
const todayDateString = LocalDate.now().toString()
const cycleDay = getOrCreateCycleDay(todayDateString)
navigate('TemperatureEditView', { cycleDay })
} else if (this.id === '2') {
navigate('Home')
} else {
navigate('Home')
}
@@ -22,7 +20,7 @@ export default function setupNotifications(navigate) {
})
tempReminderObservable(reminder => {
Notification.cancelAllLocalNotifications({id: '1'})
Notification.cancelLocalNotifications({id: '1'})
if (reminder.enabled) {
const [hours, minutes] = reminder.time.split(':')
let target = new Moment()
@@ -45,20 +43,25 @@ export default function setupNotifications(navigate) {
})
periodReminderObservable(reminder => {
Notification.cancelLocalNotifications({id: '2'})
if (reminder.enabled) {
const bleedingPrediction = cycleModule().getPredictedMenses()
if (bleedingPrediction.length > 0) {
const bleedingStart = LocalDate.parse(bleedingPrediction[0][0])
const reminderDate = bleedingStart.minusDays(3)
const bleedingStart = Moment(bleedingPrediction[0][0], "YYYY-MM-DD")
// 3 days before and at 6 am
const reminderDate = bleedingStart
.subtract(3, 'days')
.hours(6)
.minutes(0)
.seconds(0)
// period is likely to start in 3 to 3 + (length of prediction - 1) days
const daysToEndOfPrediction = bleedingPrediction[0].length + 2
Notification.localNotificationSchedule({
id: '2',
message: labels.periodReminder.notification(daysToEndOfPrediction),
date: reminderDate,
vibrate: false,
onNotification: navigate('Home')
date: reminderDate.toDate(),
vibrate: false
})
}
}