Skip to content
Snippets Groups Projects
Commit 71016193 authored by tina's avatar tina
Browse files

makes period reminder functional

parent 80bec57f
No related branches found
No related tags found
No related merge requests found
......@@ -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
})
}
}
......
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