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
a56ee7df
Commit
a56ee7df
authored
6 years ago
by
Julia Friesel
Browse files
Options
Downloads
Patches
Plain Diff
Fix case for no previous bleeding day. Use new getCycleDay API
parent
5b406848
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
bleeding.js
+2
-2
2 additions, 2 deletions
bleeding.js
day-view.js
+2
-2
2 additions, 2 deletions
day-view.js
get-cycle-day-number.js
+5
-11
5 additions, 11 deletions
get-cycle-day-number.js
home.js
+23
-8
23 additions, 8 deletions
home.js
with
32 additions
and
23 deletions
bleeding.js
+
2
−
2
View file @
a56ee7df
...
@@ -11,9 +11,9 @@ import { saveBleeding } from './db'
...
@@ -11,9 +11,9 @@ import { saveBleeding } from './db'
import
{
formatDateForViewHeader
}
from
'
./format
'
import
{
formatDateForViewHeader
}
from
'
./format
'
import
{
bleeding
as
labels
}
from
'
./labels
'
import
{
bleeding
as
labels
}
from
'
./labels
'
import
cycleDayModule
from
'
./get-cycle-day-number
'
import
cycleDayModule
from
'
./get-cycle-day-number
'
import
{
getCycle
DaysSortedByDate
View
}
from
'
./db
'
import
{
bleeding
DaysSortedByDate
}
from
'
./db
'
const
getCycleDay
=
cycleDayModule
(
getCycle
DaysSortedByDate
View
()
)
const
getCycleDay
=
cycleDayModule
(
bleeding
DaysSortedByDate
)
export
default
class
Bleeding
extends
Component
{
export
default
class
Bleeding
extends
Component
{
constructor
(
props
)
{
constructor
(
props
)
{
...
...
This diff is collapsed.
Click to expand it.
day-view.js
+
2
−
2
View file @
a56ee7df
...
@@ -8,9 +8,9 @@ import styles from './styles'
...
@@ -8,9 +8,9 @@ import styles from './styles'
import
{
formatDateForViewHeader
}
from
'
./format
'
import
{
formatDateForViewHeader
}
from
'
./format
'
import
{
bleeding
as
labels
}
from
'
./labels
'
import
{
bleeding
as
labels
}
from
'
./labels
'
import
cycleDayModule
from
'
./get-cycle-day-number
'
import
cycleDayModule
from
'
./get-cycle-day-number
'
import
{
getCycle
DaysSortedByDate
View
}
from
'
./db
'
import
{
bleeding
DaysSortedByDate
}
from
'
./db
'
const
getCycleDay
=
cycleDayModule
(
getCycle
DaysSortedByDate
View
()
)
const
getCycleDay
=
cycleDayModule
(
bleeding
DaysSortedByDate
)
export
default
class
DayView
extends
Component
{
export
default
class
DayView
extends
Component
{
constructor
(
props
)
{
constructor
(
props
)
{
...
...
This diff is collapsed.
Click to expand it.
get-cycle-day-number.js
+
5
−
11
View file @
a56ee7df
...
@@ -4,15 +4,10 @@ const LocalDate = joda.LocalDate
...
@@ -4,15 +4,10 @@ const LocalDate = joda.LocalDate
export
default
function
config
(
bleedingDaysSortedByDateView
,
opts
)
{
export
default
function
config
(
bleedingDaysSortedByDateView
,
opts
)
{
opts
=
opts
||
{
opts
=
opts
||
{
// at the very minimum, a cycle can be a bleeding day
// followed by a non-bleeding day, thus a length of 2
maxBreakInBleeding
:
1
maxBreakInBleeding
:
1
}
}
return
function
getCycleDayNumber
(
targetDateString
)
{
return
function
getCycleDayNumber
(
targetDateString
)
{
// sort the cycle days in descending order so we travel into
// the past as we iterate over the array
// also, to retrieve the number, we only need the cycle days before the target day
const
targetDate
=
LocalDate
.
parse
(
targetDateString
)
const
targetDate
=
LocalDate
.
parse
(
targetDateString
)
const
withWrappedDates
=
bleedingDaysSortedByDateView
const
withWrappedDates
=
bleedingDaysSortedByDateView
.
filter
(
day
=>
!
day
.
bleeding
.
exclude
)
.
filter
(
day
=>
!
day
.
bleeding
.
exclude
)
...
@@ -20,16 +15,15 @@ export default function config(bleedingDaysSortedByDateView, opts) {
...
@@ -20,16 +15,15 @@ export default function config(bleedingDaysSortedByDateView, opts) {
day
.
wrappedDate
=
LocalDate
.
parse
(
day
.
date
)
day
.
wrappedDate
=
LocalDate
.
parse
(
day
.
date
)
return
day
return
day
})
})
// TODO write test for what if there is no first day before?? aka no firstbleedingdaybeforeindex
const
firstBleedingDayBeforeTargetDayIndex
=
withWrappedDates
.
findIndex
(
day
=>
day
.
wrappedDate
.
isBefore
(
targetDate
))
const
firstBleedingDayBeforeTargetDayIndex
=
withWrappedDates
.
findIndex
(
day
=>
day
.
wrappedDate
.
isBefore
(
targetDate
))
const
cycleDays
=
withWrappedDates
.
slice
(
firstBleedingDayBeforeTargetDayIndex
)
if
(
firstBleedingDayBeforeTargetDayIndex
<
0
)
return
null
const
previousBleedingDays
=
withWrappedDates
.
slice
(
firstBleedingDayBeforeTargetDayIndex
)
const
lastPeriodStart
=
cycle
Days
.
find
((
day
,
i
)
=>
{
const
lastPeriodStart
=
previousBleeding
Days
.
find
((
day
,
i
)
=>
{
return
thereIsNoPreviousBleedingDayWithinTheThreshold
(
day
,
cycle
Days
.
slice
(
i
+
1
),
opts
.
maxBreakInBleeding
)
return
thereIsNoPreviousBleedingDayWithinTheThreshold
(
day
,
previousBleeding
Days
.
slice
(
i
+
1
),
opts
.
maxBreakInBleeding
)
})
})
if
(
!
lastPeriodStart
)
return
null
const
diffInDays
=
lastPeriodStart
.
wrappedDate
.
until
(
targetDate
,
joda
.
ChronoUnit
.
DAYS
)
const
diffInDays
=
lastPeriodStart
.
wrappedDate
.
until
(
targetDate
,
joda
.
ChronoUnit
.
DAYS
)
// cycle starts at day 1
// cycle starts at day 1
...
...
This diff is collapsed.
Click to expand it.
home.js
+
23
−
8
View file @
a56ee7df
...
@@ -6,22 +6,27 @@ import {
...
@@ -6,22 +6,27 @@ import {
}
from
'
react-native
'
}
from
'
react-native
'
import
styles
from
'
./styles
'
import
styles
from
'
./styles
'
import
cycleDayModule
from
'
./get-cycle-day-number
'
import
cycleDayModule
from
'
./get-cycle-day-number
'
import
{
getCycle
DaysSortedByDate
View
,
deleteAll
}
from
'
./db
'
import
{
bleeding
DaysSortedByDate
,
deleteAll
}
from
'
./db
'
import
{
LocalDate
}
from
'
js-joda
'
import
{
LocalDate
}
from
'
js-joda
'
const
cycleDaysSortedByDateView
=
getCycleDaysSortedByDateView
()
const
getCycleDayNumber
=
cycleDayModule
(
bleedingDaysSortedByDate
)
const
getCycleDayNumber
=
cycleDayModule
(
cycleDaysSortedByDateView
)
const
now
=
new
Date
()
const
cycleDayNumber
=
getCycleDayNumber
(
LocalDate
.
of
(
now
.
getFullYear
(),
now
.
getMonth
()
+
1
,
now
.
getDate
()))
const
welcomeTextWithCycleDay
=
`Welcome! Today is day
${
cycleDayNumber
}
of your current cycle`
const
welcomeText
=
`Welcome! We don't have enough information to know what your current cycle day is`
export
default
class
Home
extends
Component
{
export
default
class
Home
extends
Component
{
constructor
(
props
)
{
constructor
(
props
)
{
super
(
props
)
super
(
props
)
const
now
=
new
Date
()
this
.
todayDateString
=
LocalDate
.
of
(
now
.
getFullYear
(),
now
.
getMonth
()
+
1
,
now
.
getDate
()).
toString
()
const
cycleDayNumber
=
getCycleDayNumber
(
this
.
todayDateString
)
this
.
state
=
{
this
.
state
=
{
welcomeText
:
cycleDayNumber
?
w
elcomeText
WithC
ycleDay
:
welcomeText
welcomeText
:
determineW
elcomeText
(
c
ycleDay
Number
)
}
}
bleedingDaysSortedByDate
.
addListener
(
setStateWithCurrentWelcomeText
.
bind
(
this
))
}
componentWillUnmount
()
{
bleedingDaysSortedByDate
.
removeListener
(
setStateWithCurrentWelcomeText
)
}
}
render
()
{
render
()
{
...
@@ -45,3 +50,13 @@ export default class Home extends Component {
...
@@ -45,3 +50,13 @@ export default class Home extends Component {
)
)
}
}
}
}
function
determineWelcomeText
(
cycleDayNumber
)
{
const
welcomeTextWithCycleDay
=
`Welcome! Today is day
${
cycleDayNumber
}
of your current cycle`
const
welcomeText
=
`Welcome! We don't have enough information to know what your current cycle day is`
return
cycleDayNumber
?
welcomeTextWithCycleDay
:
welcomeText
}
function
setStateWithCurrentWelcomeText
()
{
this
.
setState
({
welcomeText
:
determineWelcomeText
(
getCycleDayNumber
(
this
.
todayDateString
))
})
}
\ 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