Get previous temperature and fill it as placeholder
This commit is contained in:
@@ -1,9 +1,8 @@
|
||||
import realm from 'realm'
|
||||
|
||||
let db
|
||||
|
||||
let bleedingDaysSortedByDate = []
|
||||
let cycleDaysSortedbyDate = []
|
||||
let bleedingDaysSortedByDate = []
|
||||
|
||||
const TemperatureSchema = {
|
||||
name: 'Temperature',
|
||||
@@ -48,11 +47,8 @@ async function openDatabase() {
|
||||
deleteRealmIfMigrationNeeded: true
|
||||
})
|
||||
|
||||
bleedingDaysSortedByDate = db.objects('CycleDay').fil<<<<<<< 933b64056a13d04c3bfdebf531962b84d9daa4ce
|
||||
// just for testing purposes, the highest temperature will be topmost
|
||||
// because I was too layz to make a scroll view
|
||||
cycleDaysSortedbyTempValueView = db.objects('CycleDay').filtered('temperature != null').sorted('temperature.value', true) tered('bleeding != null').sorted('date', true)
|
||||
cycleDaysSortedbyDate = db.objects('CycleDay').sorted('date', true)
|
||||
bleedingDaysSortedByDate = db.objects('CycleDay').filtered('bleeding != null').sorted('date', true)
|
||||
}
|
||||
|
||||
function saveTemperature(cycleDay, temperature) {
|
||||
@@ -79,10 +75,20 @@ function getOrCreateCycleDay(localDate) {
|
||||
return result
|
||||
}
|
||||
|
||||
function getPreviousTemperature(cycleDay) {
|
||||
const cycleDayIndex = cycleDaysSortedbyDate.findIndex(day => day === cycleDay)
|
||||
const previousCycleDays = cycleDaysSortedbyDate.slice(cycleDayIndex + 1)
|
||||
const winner = previousCycleDays.find(cycleDay => cycleDay.temperature)
|
||||
if (!winner) return null
|
||||
return winner.temperature.value
|
||||
}
|
||||
|
||||
export {
|
||||
cycleDaysSortedbyDate,
|
||||
openDatabase,
|
||||
saveTemperature,
|
||||
saveBleeding,
|
||||
getOrCreateCycleDay,
|
||||
bleedingDaysSortedByDate
|
||||
bleedingDaysSortedByDate,
|
||||
getPreviousTemperature
|
||||
}
|
||||
|
||||
+11
-3
@@ -8,7 +8,7 @@ import {
|
||||
} from 'react-native'
|
||||
|
||||
import styles from './styles'
|
||||
import { saveTemperature } from './db'
|
||||
import { saveTemperature, getPreviousTemperature } from './db'
|
||||
import { formatDateForViewHeader } from './format'
|
||||
import getCycleDay from './get-cycle-day'
|
||||
|
||||
@@ -16,10 +16,18 @@ export default class Temp extends Component {
|
||||
constructor(props) {
|
||||
super(props)
|
||||
const cycleDay = props.navigation.state.params.cycleDay
|
||||
console.log(cycleDay.temperature ? cycleDay.temperature.value : '')
|
||||
let initialValue
|
||||
|
||||
if(cycleDay.temperature) {
|
||||
initialValue = cycleDay.temperature.toString()
|
||||
} else {
|
||||
const prevTemp = getPreviousTemperature(cycleDay)
|
||||
initialValue = prevTemp ? prevTemp.toString() : ''
|
||||
}
|
||||
|
||||
this.state = {
|
||||
cycleDay,
|
||||
currentValue: cycleDay.temperature ? cycleDay.temperature.value.toString() : '',
|
||||
currentValue: initialValue,
|
||||
exclude: cycleDay.temperature ? cycleDay.temperature.exclude : false
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user