First attempt at notifying at given time

This commit is contained in:
Julia Friesel
2018-08-27 12:37:48 +02:00
parent 3a91b5ffa4
commit b90fda113d
3 changed files with 31 additions and 2 deletions
+27
View File
@@ -0,0 +1,27 @@
import {tempReminderObservable} from '../local-storage'
import { LocalTime, ChronoUnit } from 'js-joda'
import {NotificationsAndroid} from 'react-native-notifications'
let stopCheckingTheTime = () => {}
export default function setupNotifications() {
tempReminderObservable(reminder => {
stopCheckingTheTime()
if (reminder.enabled) {
stopCheckingTheTime = notifyAt(reminder.time)
}
})
}
function notifyAt(time) {
const id = setInterval(() => {
const now = LocalTime.now().truncatedTo(ChronoUnit.MINUTES).toString()
if (now === time) {
NotificationsAndroid.localNotification({
title: 'yo',
body: 'much notification'
})
}
}, 60 * 1000)
return () => clearInterval(id)
}