Skip to content
Snippets Groups Projects
Commit 407fa834 authored by BloodyMarie's avatar BloodyMarie Committed by bl00dymarie
Browse files

Make temp reminder work for android & ios

parent 16d2afaf
No related branches found
No related tags found
No related merge requests found
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()
})
......
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