makes period reminder functional
This commit is contained in:
+15
-12
@@ -8,13 +8,11 @@ import cycleModule from './cycle'
|
|||||||
|
|
||||||
export default function setupNotifications(navigate) {
|
export default function setupNotifications(navigate) {
|
||||||
Notification.configure({
|
Notification.configure({
|
||||||
onNotification: () => {
|
onNotification: (notification) => {
|
||||||
const todayDateString = LocalDate.now().toString()
|
if (notification.id === '1') {
|
||||||
const cycleDay = getOrCreateCycleDay(todayDateString)
|
const todayDateString = LocalDate.now().toString()
|
||||||
if (this.id === '1') {
|
const cycleDay = getOrCreateCycleDay(todayDateString)
|
||||||
navigate('TemperatureEditView', { cycleDay })
|
navigate('TemperatureEditView', { cycleDay })
|
||||||
} else if (this.id === '2') {
|
|
||||||
navigate('Home')
|
|
||||||
} else {
|
} else {
|
||||||
navigate('Home')
|
navigate('Home')
|
||||||
}
|
}
|
||||||
@@ -22,7 +20,7 @@ export default function setupNotifications(navigate) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
tempReminderObservable(reminder => {
|
tempReminderObservable(reminder => {
|
||||||
Notification.cancelAllLocalNotifications({id: '1'})
|
Notification.cancelLocalNotifications({id: '1'})
|
||||||
if (reminder.enabled) {
|
if (reminder.enabled) {
|
||||||
const [hours, minutes] = reminder.time.split(':')
|
const [hours, minutes] = reminder.time.split(':')
|
||||||
let target = new Moment()
|
let target = new Moment()
|
||||||
@@ -45,20 +43,25 @@ export default function setupNotifications(navigate) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
periodReminderObservable(reminder => {
|
periodReminderObservable(reminder => {
|
||||||
|
Notification.cancelLocalNotifications({id: '2'})
|
||||||
if (reminder.enabled) {
|
if (reminder.enabled) {
|
||||||
const bleedingPrediction = cycleModule().getPredictedMenses()
|
const bleedingPrediction = cycleModule().getPredictedMenses()
|
||||||
if (bleedingPrediction.length > 0) {
|
if (bleedingPrediction.length > 0) {
|
||||||
const bleedingStart = LocalDate.parse(bleedingPrediction[0][0])
|
const bleedingStart = Moment(bleedingPrediction[0][0], "YYYY-MM-DD")
|
||||||
const reminderDate = bleedingStart.minusDays(3)
|
// 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
|
// period is likely to start in 3 to 3 + (length of prediction - 1) days
|
||||||
const daysToEndOfPrediction = bleedingPrediction[0].length + 2
|
const daysToEndOfPrediction = bleedingPrediction[0].length + 2
|
||||||
|
|
||||||
Notification.localNotificationSchedule({
|
Notification.localNotificationSchedule({
|
||||||
id: '2',
|
id: '2',
|
||||||
message: labels.periodReminder.notification(daysToEndOfPrediction),
|
message: labels.periodReminder.notification(daysToEndOfPrediction),
|
||||||
date: reminderDate,
|
date: reminderDate.toDate(),
|
||||||
vibrate: false,
|
vibrate: false
|
||||||
onNotification: navigate('Home')
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user