From 16d2afaf1ef2069d994f9d3f4dc2831018e33130 Mon Sep 17 00:00:00 2001 From: BloodyMarie Date: Sun, 10 Apr 2022 22:59:48 +0200 Subject: [PATCH 1/5] Fix: Target reminder with correct id --- lib/notifications.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/notifications.js b/lib/notifications.js index f58a767..2353d59 100644 --- a/lib/notifications.js +++ b/lib/notifications.js @@ -9,7 +9,7 @@ import nothingChanged from '../db/db-unchanged' export default function setupNotifications(navigate) { Notification.configure({ onNotification: (notification) => { - if (notification.id === '1') { + if (notification.data.id === '11' || notification.id === '1') { navigate('TemperatureEditView') } else { navigate('Home') @@ -18,7 +18,7 @@ export default function setupNotifications(navigate) { }) tempReminderObservable(reminder => { - Notification.cancelLocalNotifications({id: '1'}) + Notification.cancelLocalNotifications({id: '11'}) if (reminder.enabled) { const [hours, minutes] = reminder.time.split(':') let target = new Moment() @@ -32,6 +32,7 @@ export default function setupNotifications(navigate) { Notification.localNotificationSchedule({ id: '1', + userInfo: { id: '11' }, message: labels.tempReminder.notification, date: target.toDate(), vibrate: false, @@ -41,7 +42,7 @@ export default function setupNotifications(navigate) { }, false) periodReminderObservable(reminder => { - Notification.cancelLocalNotifications({id: '2'}) + Notification.cancelLocalNotifications({id: '22'}) if (reminder.enabled) setupPeriodReminder() }, false) @@ -71,6 +72,7 @@ function setupPeriodReminder() { Notification.localNotificationSchedule({ id: '2', + userInfo: { id: '22' }, message: labels.periodReminder.notification(daysToEndOfPrediction), date: reminderDate.toDate(), vibrate: false From 407fa834abee378b90ce0cba361491851aa19e10 Mon Sep 17 00:00:00 2001 From: BloodyMarie Date: Mon, 11 Apr 2022 20:15:00 +0200 Subject: [PATCH 2/5] Make temp reminder work for android & ios --- lib/notifications.js | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/notifications.js b/lib/notifications.js index 2353d59..76023c1 100644 --- a/lib/notifications.js +++ b/lib/notifications.js @@ -1,3 +1,4 @@ +import { Platform } from 'react-native' import {tempReminderObservable, periodReminderObservable} from '../local-storage' import Notification from 'react-native-push-notification' import Moment from 'moment' @@ -9,7 +10,10 @@ import nothingChanged from '../db/db-unchanged' export default function setupNotifications(navigate) { Notification.configure({ onNotification: (notification) => { - if (notification.data.id === '11' || notification.id === '1') { + if (Platform.OS === "ios" && notification.data && notification.data.id === '11') { + navigate('TemperatureEditView') + } + else if (Platform.OS === "android" && notification.id === '1') { navigate('TemperatureEditView') } else { navigate('Home') @@ -18,7 +22,11 @@ export default function setupNotifications(navigate) { }) tempReminderObservable(reminder => { + if (Platform.OS === "ios") { Notification.cancelLocalNotifications({id: '11'}) + } else { + Notification.cancelLocalNotifications({id: '1'}) + } if (reminder.enabled) { const [hours, minutes] = reminder.time.split(':') let target = new Moment() @@ -42,14 +50,22 @@ export default function setupNotifications(navigate) { }, false) periodReminderObservable(reminder => { + if (Platform.OS === "ios") { Notification.cancelLocalNotifications({id: '22'}) + } else { + Notification.cancelLocalNotifications({id: '2'}) + } if (reminder.enabled) setupPeriodReminder() }, false) getBleedingDaysSortedByDate().addListener((_, changes) => { // the listener fires on setup, so we check if there were actually any changes if (nothingChanged(changes)) return + if (Platform.OS === "ios") { + Notification.cancelLocalNotifications({id: '22'}) + } else { Notification.cancelLocalNotifications({id: '2'}) + } if (periodReminderObservable.value.enabled) setupPeriodReminder() }) From 992161e3ce8ddc43e4a8864c973ca0630b1c8f2f Mon Sep 17 00:00:00 2001 From: BloodyMarie Date: Fri, 15 Apr 2022 16:03:17 +0200 Subject: [PATCH 3/5] Implement review feedback --- lib/notifications.js | 23 ++++------------------- 1 file changed, 4 insertions(+), 19 deletions(-) diff --git a/lib/notifications.js b/lib/notifications.js index 76023c1..38cb3a4 100644 --- a/lib/notifications.js +++ b/lib/notifications.js @@ -1,4 +1,3 @@ -import { Platform } from 'react-native' import {tempReminderObservable, periodReminderObservable} from '../local-storage' import Notification from 'react-native-push-notification' import Moment from 'moment' @@ -10,10 +9,8 @@ import nothingChanged from '../db/db-unchanged' export default function setupNotifications(navigate) { Notification.configure({ onNotification: (notification) => { - if (Platform.OS === "ios" && notification.data && notification.data.id === '11') { - navigate('TemperatureEditView') - } - else if (Platform.OS === "android" && notification.id === '1') { + // https://github.com/zo0r/react-native-push-notification/issues/966#issuecomment-479069106 + if (notification.data?.id === '1' || notification.id === '1') { navigate('TemperatureEditView') } else { navigate('Home') @@ -22,11 +19,7 @@ export default function setupNotifications(navigate) { }) tempReminderObservable(reminder => { - if (Platform.OS === "ios") { - Notification.cancelLocalNotifications({id: '11'}) - } else { Notification.cancelLocalNotifications({id: '1'}) - } if (reminder.enabled) { const [hours, minutes] = reminder.time.split(':') let target = new Moment() @@ -40,7 +33,7 @@ export default function setupNotifications(navigate) { Notification.localNotificationSchedule({ id: '1', - userInfo: { id: '11' }, + userInfo: { id: '1' }, message: labels.tempReminder.notification, date: target.toDate(), vibrate: false, @@ -50,22 +43,14 @@ export default function setupNotifications(navigate) { }, false) periodReminderObservable(reminder => { - if (Platform.OS === "ios") { - Notification.cancelLocalNotifications({id: '22'}) - } else { Notification.cancelLocalNotifications({id: '2'}) - } if (reminder.enabled) setupPeriodReminder() }, false) getBleedingDaysSortedByDate().addListener((_, changes) => { // the listener fires on setup, so we check if there were actually any changes if (nothingChanged(changes)) return - if (Platform.OS === "ios") { - Notification.cancelLocalNotifications({id: '22'}) - } else { Notification.cancelLocalNotifications({id: '2'}) - } if (periodReminderObservable.value.enabled) setupPeriodReminder() }) @@ -88,7 +73,7 @@ function setupPeriodReminder() { Notification.localNotificationSchedule({ id: '2', - userInfo: { id: '22' }, + userInfo: { id: '2' }, message: labels.periodReminder.notification(daysToEndOfPrediction), date: reminderDate.toDate(), vibrate: false From 54bc836811c86913eac89c6f9bdfae4ca0aea421 Mon Sep 17 00:00:00 2001 From: bl00dymarie Date: Fri, 15 Apr 2022 14:05:41 +0000 Subject: [PATCH 4/5] fix indentation --- lib/notifications.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/notifications.js b/lib/notifications.js index 38cb3a4..8bffcc5 100644 --- a/lib/notifications.js +++ b/lib/notifications.js @@ -19,7 +19,7 @@ export default function setupNotifications(navigate) { }) tempReminderObservable(reminder => { - Notification.cancelLocalNotifications({id: '1'}) + Notification.cancelLocalNotifications({id: '1'}) if (reminder.enabled) { const [hours, minutes] = reminder.time.split(':') let target = new Moment() From a37607eae613ce8746b83f55dd2e6736120190da Mon Sep 17 00:00:00 2001 From: bl00dymarie Date: Fri, 15 Apr 2022 14:06:06 +0000 Subject: [PATCH 5/5] fix indentation --- lib/notifications.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/notifications.js b/lib/notifications.js index 8bffcc5..af762dc 100644 --- a/lib/notifications.js +++ b/lib/notifications.js @@ -43,7 +43,7 @@ export default function setupNotifications(navigate) { }, false) periodReminderObservable(reminder => { - Notification.cancelLocalNotifications({id: '2'}) + Notification.cancelLocalNotifications({id: '2'}) if (reminder.enabled) setupPeriodReminder() }, false)