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
d5b19449
Commit
d5b19449
authored
5 years ago
by
Sofiya Tepikin
Browse files
Options
Downloads
Patches
Plain Diff
Moves out home helpers from the component
parent
0a86f384
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
components/helpers/home.js
+64
-0
64 additions, 0 deletions
components/helpers/home.js
components/home.js
+14
-65
14 additions, 65 deletions
components/home.js
with
78 additions
and
65 deletions
components/helpers/home.js
0 → 100644
+
64
−
0
View file @
d5b19449
import
{
ChronoUnit
,
LocalDate
}
from
'
js-joda
'
import
{
formatDateForShortText
}
from
'
./format-date
'
import
{
home
as
labels
,
bleedingPrediction
as
predictLabels
,
}
from
'
../../i18n/en/labels
'
function
getTimes
(
prediction
)
{
const
todayDate
=
LocalDate
.
now
()
const
predictedBleedingStart
=
LocalDate
.
parse
(
prediction
[
0
][
0
])
/* the range of predicted bleeding days can be either 3 or 5 */
const
predictedBleedingEnd
=
LocalDate
.
parse
(
prediction
[
0
][
prediction
[
0
].
length
-
1
])
const
daysToEnd
=
todayDate
.
until
(
predictedBleedingEnd
,
ChronoUnit
.
DAYS
)
return
{
todayDate
,
predictedBleedingStart
,
predictedBleedingEnd
,
daysToEnd
}
}
export
function
determinePredictionText
(
bleedingPrediction
)
{
if
(
!
bleedingPrediction
.
length
)
return
predictLabels
.
noPrediction
const
{
todayDate
,
predictedBleedingStart
,
predictedBleedingEnd
,
daysToEnd
}
=
getTimes
(
bleedingPrediction
)
if
(
todayDate
.
isBefore
(
predictedBleedingStart
))
{
return
predictLabels
.
predictionInFuture
(
todayDate
.
until
(
predictedBleedingStart
,
ChronoUnit
.
DAYS
),
todayDate
.
until
(
predictedBleedingEnd
,
ChronoUnit
.
DAYS
)
)
}
if
(
todayDate
.
isAfter
(
predictedBleedingEnd
))
{
return
predictLabels
.
predictionInPast
(
formatDateForShortText
(
predictedBleedingStart
),
formatDateForShortText
(
predictedBleedingEnd
)
)
}
if
(
daysToEnd
===
0
)
{
return
predictLabels
.
predictionStartedNoDaysLeft
}
else
if
(
daysToEnd
===
1
)
{
return
predictLabels
.
predictionStarted1DayLeft
}
else
{
return
predictLabels
.
predictionStartedXDaysLeft
(
daysToEnd
)
}
}
export
function
getBleedingPredictionRange
(
prediction
)
{
if
(
!
prediction
.
length
)
return
labels
.
unknown
const
{
todayDate
,
predictedBleedingStart
,
predictedBleedingEnd
,
daysToEnd
}
=
getTimes
(
prediction
)
if
(
todayDate
.
isBefore
(
predictedBleedingStart
))
{
return
`
${
todayDate
.
until
(
predictedBleedingStart
,
ChronoUnit
.
DAYS
)}
-
${
todayDate
.
until
(
predictedBleedingEnd
,
ChronoUnit
.
DAYS
)}
`
}
if
(
todayDate
.
isAfter
(
predictedBleedingEnd
))
{
return
labels
.
unknown
}
return
(
daysToEnd
===
0
?
'
0
'
:
`0 -
${
daysToEnd
}
`
)
}
This diff is collapsed.
Click to expand it.
components/home.js
+
14
−
65
View file @
d5b19449
import
{
ChronoUnit
,
LocalDate
}
from
'
js-joda
'
import
{
LocalDate
}
from
'
js-joda
'
import
React
,
{
Component
}
from
'
react
'
import
React
,
{
Component
}
from
'
react
'
import
{
ScrollView
,
View
}
from
'
react-native
'
import
{
ScrollView
,
View
}
from
'
react-native
'
import
{
connect
}
from
'
react-redux
'
import
{
connect
}
from
'
react-redux
'
import
{
navigate
}
from
'
../slices/navigation
'
import
{
navigate
}
from
'
../slices/navigation
'
import
{
setDate
}
from
'
../slices/date
'
import
{
getDate
,
setDate
}
from
'
../slices/date
'
import
DripHomeIcon
from
'
../assets/drip-home-icons
'
import
DripHomeIcon
from
'
../assets/drip-home-icons
'
...
@@ -12,15 +12,15 @@ import AppText from './app-text'
...
@@ -12,15 +12,15 @@ import AppText from './app-text'
import
IconText
from
'
./icon-text
'
import
IconText
from
'
./icon-text
'
import
HomeElement
from
'
./home-element
'
import
HomeElement
from
'
./home-element
'
import
{
import
{
home
as
labels
}
from
'
../i18n/en/labels
'
bleedingPrediction
as
predictLabels
,
home
as
labels
}
from
'
../i18n/en/labels
'
import
links
from
'
../i18n/en/links
'
import
links
from
'
../i18n/en/links
'
import
cycleModule
from
'
../lib/cycle
'
import
cycleModule
from
'
../lib/cycle
'
import
{
getFertilityStatusForDay
}
from
'
../lib/sympto-adapter
'
import
{
getFertilityStatusForDay
}
from
'
../lib/sympto-adapter
'
import
{
formatDateForShortText
}
from
'
./helpers/format-date
'
import
{
determinePredictionText
,
getBleedingPredictionRange
}
from
'
./helpers/home
'
import
styles
,
{
cycleDayColor
,
periodColor
,
secondaryColor
}
from
'
../styles
'
import
styles
,
{
cycleDayColor
,
periodColor
,
secondaryColor
}
from
'
../styles
'
...
@@ -125,6 +125,12 @@ class Home extends Component {
...
@@ -125,6 +125,12 @@ class Home extends Component {
}
}
}
}
const
mapStateToProps
=
(
state
)
=>
{
return
({
date
:
getDate
(
state
),
})
}
const
mapDispatchToProps
=
(
dispatch
)
=>
{
const
mapDispatchToProps
=
(
dispatch
)
=>
{
return
({
return
({
navigate
:
(
page
)
=>
dispatch
(
navigate
(
page
)),
navigate
:
(
page
)
=>
dispatch
(
navigate
(
page
)),
...
@@ -133,63 +139,6 @@ const mapDispatchToProps = (dispatch) => {
...
@@ -133,63 +139,6 @@ const mapDispatchToProps = (dispatch) => {
}
}
export
default
connect
(
export
default
connect
(
null
,
mapStateToProps
,
mapDispatchToProps
,
mapDispatchToProps
,
)(
Home
)
)(
Home
)
function
getTimes
(
prediction
)
{
const
todayDate
=
LocalDate
.
now
()
const
predictedBleedingStart
=
LocalDate
.
parse
(
prediction
[
0
][
0
])
/* the range of predicted bleeding days can be either 3 or 5 */
const
predictedBleedingEnd
=
LocalDate
.
parse
(
prediction
[
0
][
prediction
[
0
].
length
-
1
])
const
daysToEnd
=
todayDate
.
until
(
predictedBleedingEnd
,
ChronoUnit
.
DAYS
)
return
{
todayDate
,
predictedBleedingStart
,
predictedBleedingEnd
,
daysToEnd
}
}
function
determinePredictionText
(
bleedingPrediction
)
{
if
(
!
bleedingPrediction
.
length
)
return
predictLabels
.
noPrediction
const
{
todayDate
,
predictedBleedingStart
,
predictedBleedingEnd
,
daysToEnd
}
=
getTimes
(
bleedingPrediction
)
if
(
todayDate
.
isBefore
(
predictedBleedingStart
))
{
return
predictLabels
.
predictionInFuture
(
todayDate
.
until
(
predictedBleedingStart
,
ChronoUnit
.
DAYS
),
todayDate
.
until
(
predictedBleedingEnd
,
ChronoUnit
.
DAYS
)
)
}
if
(
todayDate
.
isAfter
(
predictedBleedingEnd
))
{
return
predictLabels
.
predictionInPast
(
formatDateForShortText
(
predictedBleedingStart
),
formatDateForShortText
(
predictedBleedingEnd
)
)
}
if
(
daysToEnd
===
0
)
{
return
predictLabels
.
predictionStartedNoDaysLeft
}
else
if
(
daysToEnd
===
1
)
{
return
predictLabels
.
predictionStarted1DayLeft
}
else
{
return
predictLabels
.
predictionStartedXDaysLeft
(
daysToEnd
)
}
}
function
getBleedingPredictionRange
(
prediction
)
{
if
(
!
prediction
.
length
)
return
labels
.
unknown
const
{
todayDate
,
predictedBleedingStart
,
predictedBleedingEnd
,
daysToEnd
}
=
getTimes
(
prediction
)
if
(
todayDate
.
isBefore
(
predictedBleedingStart
))
{
return
`
${
todayDate
.
until
(
predictedBleedingStart
,
ChronoUnit
.
DAYS
)}
-
${
todayDate
.
until
(
predictedBleedingEnd
,
ChronoUnit
.
DAYS
)}
`
}
if
(
todayDate
.
isAfter
(
predictedBleedingEnd
))
{
return
labels
.
unknown
}
return
(
daysToEnd
===
0
?
'
0
'
:
`0 -
${
daysToEnd
}
`
)
}
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