diff --git a/components/app.js b/components/app.js index dbd3cfb..91b21a3 100644 --- a/components/app.js +++ b/components/app.js @@ -10,6 +10,7 @@ import Chart from './chart/chart' import Settings from './settings' import Stats from './stats' import {headerTitles as titles} from './labels' +import setupNotifications from '../lib/notifications' const isSymptomView = name => Object.keys(symptomViews).indexOf(name) > -1 @@ -60,4 +61,6 @@ export default class App extends Component { ) } -} \ No newline at end of file +} + +setupNotifications() \ No newline at end of file diff --git a/components/home.js b/components/home.js index d43521b..2962492 100644 --- a/components/home.js +++ b/components/home.js @@ -9,7 +9,6 @@ import { LocalDate } from 'js-joda' import styles from '../styles/index' import cycleModule from '../lib/cycle' import { getOrCreateCycleDay, bleedingDaysSortedByDate, fillWithDummyData, deleteAll } from '../db' -import {NotificationsAndroid} from 'react-native-notifications' const getCycleDayNumber = cycleModule().getCycleDayNumber diff --git a/lib/notifications.js b/lib/notifications.js new file mode 100644 index 0000000..033d4ad --- /dev/null +++ b/lib/notifications.js @@ -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) +} \ No newline at end of file