Only use db functions when components are actually mounted
This commit is contained in:
@@ -1,13 +1,15 @@
|
||||
import React, { Component } from 'react'
|
||||
import { CalendarList } from 'react-native-calendars'
|
||||
import {LocalDate} from 'js-joda'
|
||||
import { getOrCreateCycleDay, bleedingDaysSortedByDate } from '../db'
|
||||
import { getOrCreateCycleDay, getBleedingDaysSortedByDate } from '../db'
|
||||
import cycleModule from '../lib/cycle'
|
||||
import {shadesOfRed} from '../styles/index'
|
||||
import styles from '../styles/index'
|
||||
|
||||
|
||||
export default class CalendarView extends Component {
|
||||
constructor(props) {
|
||||
const bleedingDaysSortedByDate = getBleedingDaysSortedByDate()
|
||||
super(props)
|
||||
const predictedMenses = cycleModule().getPredictedMenses()
|
||||
this.state = {
|
||||
@@ -31,7 +33,7 @@ export default class CalendarView extends Component {
|
||||
}
|
||||
|
||||
componentWillUnmount() {
|
||||
bleedingDaysSortedByDate.removeListener(this.setStateWithCalFormattedDays)
|
||||
getBleedingDaysSortedByDate().removeListener(this.setStateWithCalFormattedDays)
|
||||
}
|
||||
|
||||
passDateToDayView = (result) => {
|
||||
|
||||
@@ -5,7 +5,7 @@ import { LocalDate } from 'js-joda'
|
||||
import { makeYAxisLabels, normalizeToScale, makeHorizontalGrid } from './y-axis'
|
||||
import nfpLines from './nfp-lines'
|
||||
import DayColumn from './day-column'
|
||||
import { getCycleDay, cycleDaysSortedByDate, getAmountOfCycleDays } from '../../db'
|
||||
import { getCycleDay, getCycleDaysSortedByDate, getAmountOfCycleDays } from '../../db'
|
||||
import styles from './styles'
|
||||
import { scaleObservable } from '../../local-storage'
|
||||
import config from '../../config'
|
||||
@@ -25,6 +25,7 @@ export default class CycleChart extends Component {
|
||||
/>
|
||||
)
|
||||
}
|
||||
this.cycleDaysSortedByDate = getCycleDaysSortedByDate()
|
||||
}
|
||||
|
||||
onLayout = ({ nativeEvent }) => {
|
||||
@@ -35,12 +36,12 @@ export default class CycleChart extends Component {
|
||||
this.setState({ columns: this.makeColumnInfo(nfpLines(height)) })
|
||||
}
|
||||
|
||||
cycleDaysSortedByDate.addListener(this.reCalculateChartInfo)
|
||||
this.cycleDaysSortedByDate.addListener(this.reCalculateChartInfo)
|
||||
this.removeObvListener = scaleObservable(this.reCalculateChartInfo, false)
|
||||
}
|
||||
|
||||
componentWillUnmount() {
|
||||
cycleDaysSortedByDate.removeListener(this.reCalculateChartInfo)
|
||||
this.cycleDaysSortedByDate.removeListener(this.reCalculateChartInfo)
|
||||
this.removeObvListener()
|
||||
}
|
||||
|
||||
|
||||
@@ -9,10 +9,13 @@ import { getOrCreateCycleDay } from '../../db'
|
||||
import cycleModule from '../../lib/cycle'
|
||||
import DotAndLine from './dot-and-line'
|
||||
|
||||
const getCycleDayNumber = cycleModule().getCycleDayNumber
|
||||
const label = styles.column.label
|
||||
|
||||
export default class DayColumn extends Component {
|
||||
constructor() {
|
||||
super()
|
||||
this.getCycleDayNumber = cycleModule().getCycleDayNumber
|
||||
}
|
||||
passDateToDayView(dateString) {
|
||||
const cycleDay = getOrCreateCycleDay(dateString)
|
||||
this.props.navigate('CycleDay', { cycleDay })
|
||||
@@ -68,7 +71,7 @@ export default class DayColumn extends Component {
|
||||
)
|
||||
}
|
||||
|
||||
const cycleDayNumber = getCycleDayNumber(dateString)
|
||||
const cycleDayNumber = this.getCycleDayNumber(dateString)
|
||||
const shortDate = dateString.split('-').slice(1).join('-')
|
||||
const cycleDayLabel = (
|
||||
<Text style = {label.number}>
|
||||
|
||||
+4
-5
@@ -8,14 +8,13 @@ import {
|
||||
import { LocalDate, ChronoUnit } from 'js-joda'
|
||||
import styles from '../styles/index'
|
||||
import cycleModule from '../lib/cycle'
|
||||
import { requestHash, getOrCreateCycleDay, bleedingDaysSortedByDate, fillWithMucusDummyData, fillWithCervixDummyData, deleteAll } from '../db'
|
||||
import { requestHash, getOrCreateCycleDay, getBleedingDaysSortedByDate, fillWithMucusDummyData, fillWithCervixDummyData, deleteAll } from '../db'
|
||||
import {bleedingPrediction as labels} from './labels'
|
||||
|
||||
const getCycleDayNumber = cycleModule().getCycleDayNumber
|
||||
|
||||
export default class Home extends Component {
|
||||
constructor(props) {
|
||||
super(props)
|
||||
const getCycleDayNumber = cycleModule().getCycleDayNumber
|
||||
this.todayDateString = LocalDate.now().toString()
|
||||
const cycleDayNumber = getCycleDayNumber(this.todayDateString)
|
||||
|
||||
@@ -34,11 +33,11 @@ export default class Home extends Component {
|
||||
}
|
||||
})(this)
|
||||
|
||||
bleedingDaysSortedByDate.addListener(this.setStateWithCurrentText)
|
||||
getBleedingDaysSortedByDate().addListener(this.setStateWithCurrentText)
|
||||
}
|
||||
|
||||
componentWillUnmount() {
|
||||
bleedingDaysSortedByDate.removeListener(this.setStateWithCurrentText)
|
||||
getBleedingDaysSortedByDate().removeListener(this.setStateWithCurrentText)
|
||||
}
|
||||
|
||||
passTodayToDayView() {
|
||||
|
||||
+2
-2
@@ -13,8 +13,8 @@ export default function config(opts) {
|
||||
if (!opts) {
|
||||
// we only want to require (and run) the db module
|
||||
// when not running the tests
|
||||
bleedingDaysSortedByDate = require('../db').bleedingDaysSortedByDate
|
||||
cycleDaysSortedByDate = require('../db').cycleDaysSortedByDate
|
||||
bleedingDaysSortedByDate = require('../db').getBleedingDaysSortedByDate()
|
||||
cycleDaysSortedByDate = require('../db').getCycleDaysSortedByDate()
|
||||
maxBreakInBleeding = 1
|
||||
maxCycleLength = 99
|
||||
minCyclesForPrediction = 3
|
||||
|
||||
@@ -2,12 +2,6 @@ import getFertilityStatus from './sympto'
|
||||
import cycleModule from './cycle'
|
||||
import { fertilityStatus } from '../components/cycle-day/labels/labels'
|
||||
|
||||
const {
|
||||
getCycleForDay,
|
||||
getCyclesBefore,
|
||||
getPreviousCycle
|
||||
} = cycleModule()
|
||||
|
||||
export function getFertilityStatusStringForDay(dateString) {
|
||||
const status = getCycleStatusForDay(dateString)
|
||||
if (!status) return fertilityStatus.unknown
|
||||
@@ -28,6 +22,12 @@ export function getFertilityStatusStringForDay(dateString) {
|
||||
}
|
||||
|
||||
export function getCycleStatusForDay(dateString) {
|
||||
const {
|
||||
getCycleForDay,
|
||||
getCyclesBefore,
|
||||
getPreviousCycle
|
||||
} = cycleModule()
|
||||
|
||||
const cycle = getCycleForDay(dateString)
|
||||
if (!cycle) return null
|
||||
|
||||
|
||||
Reference in New Issue
Block a user