Skip to content
Snippets Groups Projects
Commit b90fda11 authored by Julia Friesel's avatar Julia Friesel
Browse files

First attempt at notifying at given time

parent 3a91b5ff
No related branches found
No related tags found
No related merge requests found
...@@ -10,6 +10,7 @@ import Chart from './chart/chart' ...@@ -10,6 +10,7 @@ import Chart from './chart/chart'
import Settings from './settings' import Settings from './settings'
import Stats from './stats' import Stats from './stats'
import {headerTitles as titles} from './labels' import {headerTitles as titles} from './labels'
import setupNotifications from '../lib/notifications'
const isSymptomView = name => Object.keys(symptomViews).indexOf(name) > -1 const isSymptomView = name => Object.keys(symptomViews).indexOf(name) > -1
...@@ -60,4 +61,6 @@ export default class App extends Component { ...@@ -60,4 +61,6 @@ export default class App extends Component {
</View> </View>
) )
} }
} }
\ No newline at end of file
setupNotifications()
\ No newline at end of file
...@@ -9,7 +9,6 @@ import { LocalDate } from 'js-joda' ...@@ -9,7 +9,6 @@ import { LocalDate } from 'js-joda'
import styles from '../styles/index' import styles from '../styles/index'
import cycleModule from '../lib/cycle' import cycleModule from '../lib/cycle'
import { getOrCreateCycleDay, bleedingDaysSortedByDate, fillWithDummyData, deleteAll } from '../db' import { getOrCreateCycleDay, bleedingDaysSortedByDate, fillWithDummyData, deleteAll } from '../db'
import {NotificationsAndroid} from 'react-native-notifications'
const getCycleDayNumber = cycleModule().getCycleDayNumber const getCycleDayNumber = cycleModule().getCycleDayNumber
......
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)
}
\ No newline at end of file
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