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

Merge branch '91-clean-up-line-length-warnings' into 'master'

Resolve "clean up line length warnings"

Closes #91

See merge request bloodyhealth/drip!43
parents 01d40a6d 364daee4
No related branches found
No related tags found
No related merge requests found
import React, { Component } from 'react' import React, { Component } from 'react'
import { View } from 'react-native' import { View } from 'react-native'
import { Calendar } from 'react-native-calendars' import { Calendar } from 'react-native-calendars'
import * as styles from '../styles/index' import * as styles from '../styles'
import { getOrCreateCycleDay, bleedingDaysSortedByDate } from '../db' import { getOrCreateCycleDay, bleedingDaysSortedByDate } from '../db'
export default class CalendarView extends Component { export default class CalendarView extends Component {
constructor(props) { constructor(props) {
super(props) super(props)
this.state = { bleedingDaysInCalFormat: getBleedingDaysInCalFormat(bleedingDaysSortedByDate) } this.state = {
bleedingDaysInCalFormat: toCalFormat(bleedingDaysSortedByDate)
}
this.setStateWithCalendarFormattedDays = (function (CalendarComponent) { this.setStateWithCalFormattedDays = (function (CalendarComponent) {
return function() { return function() {
CalendarComponent.setState({ CalendarComponent.setState({
bleedingDaysInCalFormat: getBleedingDaysInCalFormat(bleedingDaysSortedByDate) bleedingDaysInCalFormat: toCalFormat(bleedingDaysSortedByDate)
}) })
} }
})(this) })(this)
bleedingDaysSortedByDate.addListener(this.setStateWithCalendarFormattedDays) bleedingDaysSortedByDate.addListener(this.setStateWithCalFormattedDays)
} }
componentWillUnmount() { componentWillUnmount() {
bleedingDaysSortedByDate.removeListener(this.setStateWithCalendarFormattedDays) bleedingDaysSortedByDate.removeListener(this.setStateWithCalFormattedDays)
} }
passDateToDayView(result) { passDateToDayView(result) {
...@@ -43,10 +45,14 @@ export default class CalendarView extends Component { ...@@ -43,10 +45,14 @@ export default class CalendarView extends Component {
} }
} }
function getBleedingDaysInCalFormat(bleedingDaysSortedByDate) { function toCalFormat(bleedingDaysSortedByDate) {
const shadesOfRed = ['#ffbaba', '#ff7b7b', '#ff5252', '#ff0000'] const shadesOfRed = ['#ffbaba', '#ff7b7b', '#ff5252', '#ff0000']
return bleedingDaysSortedByDate.reduce((acc, day) => { return bleedingDaysSortedByDate.reduce((acc, day) => {
acc[day.date] = { startingDay: true, endingDay: true, color: shadesOfRed[day.bleeding.value] } acc[day.date] = {
startingDay: true,
endingDay: true,
color: shadesOfRed[day.bleeding.value]
}
return acc return acc
}, {}) }, {})
} }
\ No newline at end of file
...@@ -115,7 +115,9 @@ export default class CycleChart extends Component { ...@@ -115,7 +115,9 @@ export default class CycleChart extends Component {
fill={styles.mucusIconShades[cycleDay.mucus.value]} fill={styles.mucusIconShades[cycleDay.mucus.value]}
/> : null} /> : null}
{y ? this.drawDotAndLines(y, cycleDay.temperature.exclude, index) : null} {y ?
this.drawDotAndLines(y, cycleDay.temperature.exclude, index)
: null}
</G> </G>
) )
} }
......
...@@ -5,24 +5,26 @@ import { ...@@ -5,24 +5,26 @@ import {
} from 'react-native' } from 'react-native'
import { saveSymptom } from '../../db' import { saveSymptom } from '../../db'
const dayView = 'DayView'
export default function (showView) { export default function (showView) {
return function ({ symptom, cycleDay, saveAction, saveDisabled}) { return function ({ symptom, cycleDay, saveAction, saveDisabled}) {
const buttons = [ const buttons = [
{ {
title: 'Cancel', title: 'Cancel',
action: () => showView('dayView') action: () => showView(dayView)
}, },
{ {
title: 'Delete', title: 'Delete',
action: () => { action: () => {
saveSymptom(symptom, cycleDay) saveSymptom(symptom, cycleDay)
showView('dayView') showView(dayView)
} }
}, { }, {
title: 'Save', title: 'Save',
action: () => { action: () => {
saveAction() saveAction()
showView('dayView') showView(dayView)
}, },
disabledCondition: saveDisabled disabledCondition: saveDisabled
} }
......
...@@ -29,7 +29,7 @@ export default class DayView extends Component { ...@@ -29,7 +29,7 @@ export default class DayView extends Component {
cycleDayNumber: getCycleDayNumber(this.cycleDay.date), cycleDayNumber: getCycleDayNumber(this.cycleDay.date),
} }
this.setStateWithCurrentCycleDayNumber = (function (DayViewComponent) { this.setStateWithCycleDayNumber = (function (DayViewComponent) {
return function () { return function () {
DayViewComponent.setState({ DayViewComponent.setState({
cycleDayNumber: getCycleDayNumber(DayViewComponent.cycleDay.date) cycleDayNumber: getCycleDayNumber(DayViewComponent.cycleDay.date)
...@@ -37,11 +37,11 @@ export default class DayView extends Component { ...@@ -37,11 +37,11 @@ export default class DayView extends Component {
} }
})(this) })(this)
bleedingDaysSortedByDate.addListener(this.setStateWithCurrentCycleDayNumber) bleedingDaysSortedByDate.addListener(this.setStateWithCycleDayNumber)
} }
componentWillUnmount() { componentWillUnmount() {
bleedingDaysSortedByDate.removeListener(this.setStateWithCurrentCycleDayNumber) bleedingDaysSortedByDate.removeListener(this.setStateWithCycleDayNumber)
} }
render() { render() {
...@@ -52,7 +52,7 @@ export default class DayView extends Component { ...@@ -52,7 +52,7 @@ export default class DayView extends Component {
<Text style={styles.symptomDayView}>Bleeding</Text> <Text style={styles.symptomDayView}>Bleeding</Text>
<View style={styles.symptomEditButton}> <View style={styles.symptomEditButton}>
<Button <Button
onPress={() => this.showView('bleedingEditView')} onPress={() => this.showView('BleedingEditView')}
title={getLabel('bleeding', cycleDay.bleeding)}> title={getLabel('bleeding', cycleDay.bleeding)}>
</Button> </Button>
</View> </View>
...@@ -61,7 +61,7 @@ export default class DayView extends Component { ...@@ -61,7 +61,7 @@ export default class DayView extends Component {
<Text style={styles.symptomDayView}>Temperature</Text> <Text style={styles.symptomDayView}>Temperature</Text>
<View style={styles.symptomEditButton}> <View style={styles.symptomEditButton}>
<Button <Button
onPress={() => this.showView('temperatureEditView')} onPress={() => this.showView('TemperatureEditView')}
title={getLabel('temperature', cycleDay.temperature)}> title={getLabel('temperature', cycleDay.temperature)}>
</Button> </Button>
</View> </View>
...@@ -70,7 +70,7 @@ export default class DayView extends Component { ...@@ -70,7 +70,7 @@ export default class DayView extends Component {
<Text style={styles.symptomDayView}>Mucus</Text> <Text style={styles.symptomDayView}>Mucus</Text>
<View style={styles.symptomEditButton}> <View style={styles.symptomEditButton}>
<Button <Button
onPress={() => this.showView('mucusEditView')} onPress={() => this.showView('MucusEditView')}
title={getLabel('mucus', cycleDay.mucus)}> title={getLabel('mucus', cycleDay.mucus)}>
</Button> </Button>
</View> </View>
...@@ -79,7 +79,7 @@ export default class DayView extends Component { ...@@ -79,7 +79,7 @@ export default class DayView extends Component {
<Text style={styles.symptomDayView}>Cervix</Text> <Text style={styles.symptomDayView}>Cervix</Text>
<View style={styles.symptomEditButton}> <View style={styles.symptomEditButton}>
<Button <Button
onPress={() => this.showView('cervixEditView')} onPress={() => this.showView('CervixEditView')}
title={getLabel('cervix', cycleDay.cervix)}> title={getLabel('cervix', cycleDay.cervix)}>
</Button> </Button>
</View> </View>
...@@ -88,7 +88,7 @@ export default class DayView extends Component { ...@@ -88,7 +88,7 @@ export default class DayView extends Component {
<Text style={styles.symptomDayView}>Note</Text> <Text style={styles.symptomDayView}>Note</Text>
<View style={styles.symptomEditButton}> <View style={styles.symptomEditButton}>
<Button <Button
onPress={() => this.showView('noteEditView')} onPress={() => this.showView('NoteEditView')}
title={getLabel('note', cycleDay.note)} title={getLabel('note', cycleDay.note)}
> >
</Button> </Button>
......
...@@ -6,16 +6,11 @@ import { ...@@ -6,16 +6,11 @@ import {
} from 'react-native' } from 'react-native'
import cycleModule from '../../lib/cycle' import cycleModule from '../../lib/cycle'
import { getFertilityStatusStringForDay } from '../../lib/sympto-adapter' import { getFertilityStatusStringForDay } from '../../lib/sympto-adapter'
import DayView from './cycle-day-overview'
import BleedingEditView from './symptoms/bleeding'
import TemperatureEditView from './symptoms/temperature'
import MucusEditView from './symptoms/mucus'
import CervixEditView from './symptoms/cervix'
import NoteEditView from './symptoms/note'
import DesireEditView from './symptoms/desire'
import { formatDateForViewHeader } from './labels/format' import { formatDateForViewHeader } from './labels/format'
import styles from '../../styles' import styles from '../../styles'
import actionButtonModule from './action-buttons' import actionButtonModule from './action-buttons'
import symptomComponents from './symptoms'
import DayView from './cycle-day-overview'
const getCycleDayNumber = cycleModule().getCycleDayNumber const getCycleDayNumber = cycleModule().getCycleDayNumber
...@@ -25,14 +20,32 @@ export default class Day extends Component { ...@@ -25,14 +20,32 @@ export default class Day extends Component {
this.cycleDay = props.navigation.state.params.cycleDay this.cycleDay = props.navigation.state.params.cycleDay
this.state = { this.state = {
visibleComponent: 'dayView', visibleComponent: 'DayView',
} }
this.showView = view => { const showView = view => {
this.setState({visibleComponent: view}) this.setState({visibleComponent: view})
} }
this.makeActionButtons = actionButtonModule(this.showView) const makeActionButtons = actionButtonModule(showView)
const symptomComponentNames = Object.keys(symptomComponents)
this.cycleDayViews = symptomComponentNames.reduce((acc, curr) => {
acc[curr] = React.createElement(
symptomComponents[curr],
{
cycleDay: this.cycleDay,
makeActionButtons
}
)
return acc
}, {})
// DayView needs showView instead of makeActionButtons
this.cycleDayViews.DayView = React.createElement(DayView, {
cycleDay: this.cycleDay,
showView
})
} }
render() { render() {
...@@ -56,16 +69,7 @@ export default class Day extends Component { ...@@ -56,16 +69,7 @@ export default class Day extends Component {
</Text> </Text>
</View > </View >
<View> <View>
{ { this.cycleDayViews[this.state.visibleComponent] }
{ dayView: <DayView cycleDay={this.cycleDay} showView={this.showView} />,
bleedingEditView: <BleedingEditView cycleDay={this.cycleDay} makeActionButtons={this.makeActionButtons}/>,
temperatureEditView: <TemperatureEditView cycleDay={this.cycleDay} makeActionButtons={this.makeActionButtons}/>,
mucusEditView: <MucusEditView cycleDay={this.cycleDay} makeActionButtons={this.makeActionButtons}/>,
cervixEditView: <CervixEditView cycleDay={this.cycleDay} makeActionButtons={this.makeActionButtons} />,
noteEditView: <NoteEditView cycleDay={this.cycleDay} makeActionButtons={this.makeActionButtons} />,
desireEditView: <DesireEditView cycleDay={this.cycleDay} makeActionButtons={this.makeActionButtons} />
}[this.state.visibleComponent]
}
</View > </View >
</ScrollView > </ScrollView >
) )
......
import BleedingEditView from './bleeding'
import TemperatureEditView from './temperature'
import MucusEditView from './mucus'
import CervixEditView from './cervix'
import NoteEditView from './note'
import DesireEditView from './desire'
export default {
BleedingEditView,
TemperatureEditView,
MucusEditView,
CervixEditView,
NoteEditView,
DesireEditView
}
\ No newline at end of file
...@@ -12,6 +12,8 @@ import { getPreviousTemperature, saveSymptom } from '../../../db' ...@@ -12,6 +12,8 @@ import { getPreviousTemperature, saveSymptom } from '../../../db'
import styles from '../../../styles' import styles from '../../../styles'
import { LocalTime, ChronoUnit } from 'js-joda' import { LocalTime, ChronoUnit } from 'js-joda'
const MINUTES = ChronoUnit.MINUTES
export default class Temp extends Component { export default class Temp extends Component {
constructor(props) { constructor(props) {
super(props) super(props)
...@@ -32,7 +34,7 @@ export default class Temp extends Component { ...@@ -32,7 +34,7 @@ export default class Temp extends Component {
this.state = { this.state = {
currentValue: initialValue, currentValue: initialValue,
exclude: temp ? temp.exclude : false, exclude: temp ? temp.exclude : false,
time: this.time || LocalTime.now().truncatedTo(ChronoUnit.MINUTES).toString(), time: this.time || LocalTime.now().truncatedTo(MINUTES).toString(),
isTimePickerVisible: false isTimePickerVisible: false
} }
} }
......
...@@ -24,8 +24,9 @@ export default class Home extends Component { ...@@ -24,8 +24,9 @@ export default class Home extends Component {
this.setStateWithCurrentWelcomeText = (function (HomeComponent) { this.setStateWithCurrentWelcomeText = (function (HomeComponent) {
return function () { return function () {
const cycleDayNumber = getCycleDayNumber(HomeComponent.todayDateString)
HomeComponent.setState({ HomeComponent.setState({
welcomeText: determineWelcomeText(getCycleDayNumber(HomeComponent.todayDateString)) welcomeText: determineWelcomeText(cycleDayNumber)
}) })
} }
})(this) })(this)
......
import * as joda from 'js-joda' import * as joda from 'js-joda'
const LocalDate = joda.LocalDate const LocalDate = joda.LocalDate
const DAYS = joda.ChronoUnit.DAYS
export default function config(opts) { export default function config(opts) {
let bleedingDaysSortedByDate let bleedingDaysSortedByDate
...@@ -28,28 +28,32 @@ export default function config(opts) { ...@@ -28,28 +28,32 @@ export default function config(opts) {
return day return day
}) })
const firstBleedingDayBeforeTargetDayIndex = withWrappedDates.findIndex(day => { // the index of the first bleeding day before the target day
const index = withWrappedDates.findIndex(day => {
return ( return (
day.wrappedDate.isEqual(targetDate) || day.wrappedDate.isEqual(targetDate) ||
day.wrappedDate.isBefore(targetDate) day.wrappedDate.isBefore(targetDate)
) )
}) })
if (firstBleedingDayBeforeTargetDayIndex < 0) { if (index < 0) {
withWrappedDates.forEach(day => delete day.wrappedDate) withWrappedDates.forEach(day => delete day.wrappedDate)
return null return null
} }
const previousBleedingDays = withWrappedDates.slice(firstBleedingDayBeforeTargetDayIndex) const prevBleedingDays = withWrappedDates.slice(index)
const lastMensesStart = previousBleedingDays.find((day, i) => { const lastMensesStart = prevBleedingDays.find((day, i) => {
return thereIsNoPreviousBleedingDayWithinTheThreshold(day, previousBleedingDays.slice(i + 1)) return noBleedingDayWithinThreshold(day, prevBleedingDays.slice(i + 1))
}) })
function thereIsNoPreviousBleedingDayWithinTheThreshold(bleedingDay, previousBleedingDays) { function noBleedingDayWithinThreshold(day, previousBleedingDays) {
const periodThreshold = bleedingDay.wrappedDate.minusDays(maxBreakInBleeding + 1) const periodThreshold = day.wrappedDate.minusDays(maxBreakInBleeding + 1)
return !previousBleedingDays.some(({ wrappedDate }) => { return !previousBleedingDays.some(({ wrappedDate }) => {
return wrappedDate.equals(periodThreshold) || wrappedDate.isAfter(periodThreshold) return (
wrappedDate.equals(periodThreshold) ||
wrappedDate.isAfter(periodThreshold)
)
}) })
} }
...@@ -66,9 +70,11 @@ export default function config(opts) { ...@@ -66,9 +70,11 @@ export default function config(opts) {
return day return day
}) })
const firstBleedingDayAfterTargetDay = withWrappedDates.reverse().find(day => { const firstBleedingDayAfterTargetDay = withWrappedDates
return day.wrappedDate.isAfter(targetDate) .reverse()
}) .find(day => {
return day.wrappedDate.isAfter(targetDate)
})
withWrappedDates.forEach(day => delete day.wrappedDate) withWrappedDates.forEach(day => delete day.wrappedDate)
...@@ -80,7 +86,7 @@ export default function config(opts) { ...@@ -80,7 +86,7 @@ export default function config(opts) {
if (!lastMensesStart) return null if (!lastMensesStart) return null
const targetDate = LocalDate.parse(targetDateString) const targetDate = LocalDate.parse(targetDateString)
const lastMensesLocalDate = LocalDate.parse(lastMensesStart.date) const lastMensesLocalDate = LocalDate.parse(lastMensesStart.date)
const diffInDays = lastMensesLocalDate.until(targetDate, joda.ChronoUnit.DAYS) const diffInDays = lastMensesLocalDate.until(targetDate, DAYS)
// cycle starts at day 1 // cycle starts at day 1
return diffInDays + 1 return diffInDays + 1
...@@ -100,7 +106,11 @@ export default function config(opts) { ...@@ -100,7 +106,11 @@ export default function config(opts) {
function getPreviousCycle(dateString) { function getPreviousCycle(dateString) {
const startOfCycle = getLastMensesStart(dateString) const startOfCycle = getLastMensesStart(dateString)
if (!startOfCycle) return null if (!startOfCycle) return null
const dateBeforeStartOfCycle = LocalDate.parse(startOfCycle.date).minusDays(1).toString() const dateBeforeStartOfCycle = LocalDate
.parse(startOfCycle.date)
.minusDays(1)
.toString()
return getCycleForDay(dateBeforeStartOfCycle) return getCycleForDay(dateBeforeStartOfCycle)
} }
......
...@@ -4,7 +4,8 @@ import getPreOvulatoryPhase from './pre-ovulatory' ...@@ -4,7 +4,8 @@ import getPreOvulatoryPhase from './pre-ovulatory'
import { LocalDate } from 'js-joda' import { LocalDate } from 'js-joda'
import assert from 'assert' import assert from 'assert'
export default function getSymptoThermalStatus({ cycle, previousCycle, earlierCycles = [] }) { export default function getSymptoThermalStatus(cycles) {
const { cycle, previousCycle, earlierCycles = [] } = cycles
throwIfArgsAreNotInRequiredFormat([cycle, ...earlierCycles]) throwIfArgsAreNotInRequiredFormat([cycle, ...earlierCycles])
const status = { const status = {
......
...@@ -5,6 +5,10 @@ import cycleModule from '../lib/cycle' ...@@ -5,6 +5,10 @@ import cycleModule from '../lib/cycle'
const expect = chai.expect const expect = chai.expect
chai.use(dirtyChai) chai.use(dirtyChai)
function useBleedingDays(days) {
return cycleModule({ bleedingDaysSortedByDate: days }).getCycleDayNumber
}
describe('getCycleDay', () => { describe('getCycleDay', () => {
it('works for a simple example', () => { it('works for a simple example', () => {
const bleedingDays = [{ const bleedingDays = [{
...@@ -23,7 +27,7 @@ describe('getCycleDay', () => { ...@@ -23,7 +27,7 @@ describe('getCycleDay', () => {
value: 2 value: 2
} }
}] }]
const getCycleDayNumber = cycleModule({ bleedingDaysSortedByDate: bleedingDays }).getCycleDayNumber const getCycleDayNumber = useBleedingDays(bleedingDays)
const targetDate = '2018-05-17' const targetDate = '2018-05-17'
const result = getCycleDayNumber(targetDate) const result = getCycleDayNumber(targetDate)
expect(result).to.eql(9) expect(result).to.eql(9)
...@@ -49,7 +53,7 @@ describe('getCycleDay', () => { ...@@ -49,7 +53,7 @@ describe('getCycleDay', () => {
} }
}] }]
const targetDate = '2018-05-17' const targetDate = '2018-05-17'
const getCycleDayNumber = cycleModule({ bleedingDaysSortedByDate: bleedingDays }).getCycleDayNumber const getCycleDayNumber = useBleedingDays(bleedingDays)
const result = getCycleDayNumber(targetDate) const result = getCycleDayNumber(targetDate)
expect(result).to.eql(15) expect(result).to.eql(15)
}) })
...@@ -73,7 +77,7 @@ describe('getCycleDay', () => { ...@@ -73,7 +77,7 @@ describe('getCycleDay', () => {
}] }]
const targetDate = '2018-04-27' const targetDate = '2018-04-27'
const getCycleDayNumber = cycleModule({ bleedingDaysSortedByDate: bleedingDays }).getCycleDayNumber const getCycleDayNumber = useBleedingDays(bleedingDays)
const result = getCycleDayNumber(targetDate) const result = getCycleDayNumber(targetDate)
expect(result).to.eql(18) expect(result).to.eql(18)
}) })
...@@ -87,7 +91,7 @@ describe('getCycleDay', () => { ...@@ -87,7 +91,7 @@ describe('getCycleDay', () => {
}] }]
const targetDate = '2018-05-13' const targetDate = '2018-05-13'
const getCycleDayNumber = cycleModule({ bleedingDaysSortedByDate: bleedingDays }).getCycleDayNumber const getCycleDayNumber = useBleedingDays(bleedingDays)
const result = getCycleDayNumber(targetDate) const result = getCycleDayNumber(targetDate)
expect(result).to.eql(1) expect(result).to.eql(1)
}) })
...@@ -96,7 +100,7 @@ describe('getCycleDay', () => { ...@@ -96,7 +100,7 @@ describe('getCycleDay', () => {
it('if there are no bleeding days', function () { it('if there are no bleeding days', function () {
const bleedingDays = [] const bleedingDays = []
const targetDate = '2018-05-17' const targetDate = '2018-05-17'
const getCycleDayNumber = cycleModule({ bleedingDaysSortedByDate: bleedingDays }).getCycleDayNumber const getCycleDayNumber = useBleedingDays(bleedingDays)
const result = getCycleDayNumber(targetDate) const result = getCycleDayNumber(targetDate)
expect(result).to.be.null() expect(result).to.be.null()
}) })
...@@ -119,7 +123,10 @@ describe('getCycleDay', () => { ...@@ -119,7 +123,10 @@ describe('getCycleDay', () => {
}] }]
const targetDate = '2018-05-17' const targetDate = '2018-05-17'
const getCycleDayNumber = cycleModule({ bleedingDaysSortedByDate: bleedingDays, maxBreakInBleeding }).getCycleDayNumber const getCycleDayNumber = cycleModule({
bleedingDaysSortedByDate: bleedingDays,
maxBreakInBleeding
}).getCycleDayNumber
const result = getCycleDayNumber(targetDate) const result = getCycleDayNumber(targetDate)
expect(result).to.eql(8) expect(result).to.eql(8)
}) })
...@@ -137,7 +144,10 @@ describe('getCycleDay', () => { ...@@ -137,7 +144,10 @@ describe('getCycleDay', () => {
} }
}] }]
const targetDate = '2018-05-17' const targetDate = '2018-05-17'
const getCycleDayNumber = cycleModule({ bleedingDaysSortedByDate: bleedingDays, maxBreakInBleeding }).getCycleDayNumber const getCycleDayNumber = cycleModule({
bleedingDaysSortedByDate: bleedingDays,
maxBreakInBleeding
}).getCycleDayNumber
const result = getCycleDayNumber(targetDate) const result = getCycleDayNumber(targetDate)
expect(result).to.eql(4) expect(result).to.eql(4)
}) })
......
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