Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
Drip
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
backup
Drip
Commits
09a71a39
Commit
09a71a39
authored
6 years ago
by
tina
Browse files
Options
Downloads
Patches
Plain Diff
links the period reminder to bleeding days, meaning it gets updated when they change
parent
71016193
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
lib/notifications.js
+29
-21
29 additions, 21 deletions
lib/notifications.js
with
29 additions
and
21 deletions
lib/notifications.js
+
29
−
21
View file @
09a71a39
...
...
@@ -3,7 +3,7 @@ import Notification from 'react-native-push-notification'
import
{
LocalDate
}
from
'
js-joda
'
import
Moment
from
'
moment
'
import
{
settings
as
labels
}
from
'
../components/labels
'
import
{
getOrCreateCycleDay
}
from
'
../db
'
import
{
getOrCreateCycleDay
,
getBleedingDaysSortedByDate
}
from
'
../db
'
import
cycleModule
from
'
./cycle
'
export
default
function
setupNotifications
(
navigate
)
{
...
...
@@ -44,26 +44,34 @@ export default function setupNotifications(navigate) {
periodReminderObservable
(
reminder
=>
{
Notification
.
cancelLocalNotifications
({
id
:
'
2
'
})
if
(
reminder
.
enabled
)
{
const
bleedingPrediction
=
cycleModule
().
getPredictedMenses
()
if
(
bleedingPrediction
.
length
>
0
)
{
const
bleedingStart
=
Moment
(
bleedingPrediction
[
0
][
0
],
"
YYYY-MM-DD
"
)
// 3 days before and at 6 am
const
reminderDate
=
bleedingStart
.
subtract
(
3
,
'
days
'
)
.
hours
(
6
)
.
minutes
(
0
)
.
seconds
(
0
)
// period is likely to start in 3 to 3 + (length of prediction - 1) days
const
daysToEndOfPrediction
=
bleedingPrediction
[
0
].
length
+
2
if
(
reminder
.
enabled
)
setupPeriodReminder
()
})
Notification
.
localNotificationSchedule
({
id
:
'
2
'
,
message
:
labels
.
periodReminder
.
notification
(
daysToEndOfPrediction
),
date
:
reminderDate
.
toDate
(),
vibrate
:
false
})
}
}
getBleedingDaysSortedByDate
().
addListener
(()
=>
{
Notification
.
cancelLocalNotifications
({
id
:
'
2
'
})
if
(
periodReminderObservable
.
value
.
enabled
)
setupPeriodReminder
()
})
}
function
setupPeriodReminder
()
{
const
bleedingPrediction
=
cycleModule
().
getPredictedMenses
()
if
(
bleedingPrediction
.
length
>
0
)
{
const
bleedingStart
=
Moment
(
bleedingPrediction
[
0
][
0
],
"
YYYY-MM-DD
"
)
// 3 days before and at 6 am
const
reminderDate
=
bleedingStart
.
subtract
(
3
,
'
days
'
)
.
hours
(
6
)
.
minutes
(
0
)
.
seconds
(
0
)
// period is likely to start in 3 to 3 + (length of prediction - 1) days
const
daysToEndOfPrediction
=
bleedingPrediction
[
0
].
length
+
2
Notification
.
localNotificationSchedule
({
id
:
'
2
'
,
message
:
labels
.
periodReminder
.
notification
(
daysToEndOfPrediction
),
date
:
reminderDate
.
toDate
(),
vibrate
:
false
})
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment