Merge branch '540-Temperature-value-cannot-be-entered-with-comma' into 'master'

Resolve "Bug: Temperature value cannot be entered with comma"

Closes #540

See merge request bloodyhealth/drip!390
This commit is contained in:
bl00dymarie
2022-04-15 19:23:04 +00:00
4 changed files with 324 additions and 324 deletions
+45 -48
View File
@@ -23,12 +23,11 @@ import info from '../../i18n/en/symptom-info'
import { Colors, Containers, Sizes, Spacing } from '../../styles'
class SymptomEditView extends Component {
static propTypes = {
date: PropTypes.string.isRequired,
onClose: PropTypes.func.isRequired,
symptom: PropTypes.string.isRequired,
symptomData: PropTypes.object
symptomData: PropTypes.object,
}
constructor(props) {
@@ -49,7 +48,7 @@ class SymptomEditView extends Component {
shouldShowInfo: false,
shouldShowNote,
shouldBoxGroup,
shouldTabGroup
shouldTabGroup,
}
}
@@ -97,8 +96,8 @@ class SymptomEditView extends Component {
onSaveTemperature = (value, field) => {
const data = this.getParsedData()
const dataToSave = field === 'value'
? { [field]: Number(value) } : { [field]: value }
const dataToSave =
field === 'value' ? { [field]: Number(value) } : { [field]: value }
Object.assign(data, { ...dataToSave })
this.setState({ data })
@@ -106,10 +105,10 @@ class SymptomEditView extends Component {
onSelectBox = (key) => {
const data = this.getParsedData()
if (key === "other") {
if (key === 'other') {
Object.assign(data, {
note: null,
[key]: !this.state.data[key]
[key]: !this.state.data[key],
})
} else {
Object.assign(data, { [key]: !this.state.data[key] })
@@ -118,7 +117,7 @@ class SymptomEditView extends Component {
this.setState({ data })
}
onSelectBoxNote= (value) => {
onSelectBoxNote = (value) => {
const data = this.getParsedData()
Object.assign(data, { note: value !== '' ? value : null })
@@ -147,12 +146,13 @@ class SymptomEditView extends Component {
render() {
const { symptom } = this.props
const { data,
const {
data,
shouldShowExclude,
shouldShowInfo,
shouldShowNote,
shouldBoxGroup,
shouldTabGroup
shouldTabGroup,
} = this.state
const iconName = shouldShowInfo ? 'chevron-up' : 'chevron-down'
const noteText = symptom === 'note' ? data.value : data.note
@@ -166,73 +166,73 @@ class SymptomEditView extends Component {
<View style={styles.headerContainer}>
<CloseIcon onClose={this.closeView} />
</View>
{symptom === 'temperature' &&
{symptom === 'temperature' && (
<Temperature
data={data}
save={(value, field) => this.onSaveTemperature(value, field)}
/>
}
{shouldTabGroup && symtomPage[symptom].selectTabGroups.map(group => {
)}
{shouldTabGroup &&
symtomPage[symptom].selectTabGroups.map((group) => {
return (
<Segment key={group.key} style={styles.segmentBorder}>
<AppText style={styles.title}>{group.title}</AppText>
<SelectTabGroup
activeButton={data[group.key]}
buttons={group.options}
onSelect={value => this.onSelectTab(group, value)}
onSelect={(value) => this.onSelectTab(group, value)}
/>
</Segment>
)
})
}
{shouldBoxGroup && symtomPage[symptom].selectBoxGroups.map(group => {
})}
{shouldBoxGroup &&
symtomPage[symptom].selectBoxGroups.map((group) => {
const isOtherSelected =
data['other'] !== null
&& data['other'] !== false
&& Object.keys(group.options).includes('other')
data['other'] !== null &&
data['other'] !== false &&
Object.keys(group.options).includes('other')
return (
<Segment key={group.key} style={styles.segmentBorder} >
<Segment key={group.key} style={styles.segmentBorder}>
<AppText style={styles.title}>{group.title}</AppText>
<SelectBoxGroup
labels={group.options}
onSelect={value => this.onSelectBox(value)}
onSelect={(value) => this.onSelectBox(value)}
optionsState={data}
/>
{isOtherSelected &&
{isOtherSelected && (
<AppTextInput
multiline={true}
placeholder={sharedLabels.enter}
value={data.note}
onChangeText={value => this.onSelectBoxNote(value)}
onChangeText={(value) => this.onSelectBoxNote(value)}
/>
}
)}
</Segment>
)
})
}
{shouldShowExclude &&
<Segment style={styles.segmentBorder} >
})}
{shouldShowExclude && (
<Segment style={styles.segmentBorder}>
<AppSwitch
onToggle={this.onExcludeToggle}
text={symtomPage[symptom].excludeText}
value={data.exclude}
/>
</Segment>
}
{shouldShowNote &&
<Segment style={styles.segmentBorder} >
)}
{shouldShowNote && (
<Segment style={styles.segmentBorder}>
<AppText>{symtomPage[symptom].note}</AppText>
<AppTextInput
multiline={true}
numberOfLines={3}
onChangeText={this.onEditNote}
placeholder={sharedLabels.enter}
testID='noteInput'
testID="noteInput"
value={noteText !== null ? noteText : ''}
/>
</Segment>
}
)}
<View style={styles.buttonsContainer}>
<Button iconName={iconName} isSmall onPress={this.onPressLearnMore}>
{sharedLabels.learnMore}
@@ -244,11 +244,11 @@ class SymptomEditView extends Component {
{sharedLabels.save}
</Button>
</View>
{shouldShowInfo &&
<Segment last style={styles.segmentBorder} >
{shouldShowInfo && (
<Segment last style={styles.segmentBorder}>
<AppText>{info[symptom].text}</AppText>
</Segment>
}
)}
</ScrollView>
</AppModal>
)
@@ -257,7 +257,7 @@ class SymptomEditView extends Component {
const styles = StyleSheet.create({
buttonsContainer: {
...Containers.rowContainer
...Containers.rowContainer,
},
headerContainer: {
flexDirection: 'row',
@@ -275,23 +275,20 @@ const styles = StyleSheet.create({
marginVertical: Sizes.huge * 2,
position: 'absolute',
minHeight: '40%',
maxHeight: Dimensions.get('window').height * 0.7
maxHeight: Dimensions.get('window').height * 0.7,
},
segmentBorder: {
borderBottomColor: Colors.greyLight
borderBottomColor: Colors.greyLight,
},
title: {
fontSize: Sizes.subtitle
}
fontSize: Sizes.subtitle,
},
})
const mapStateToProps = (state) => {
return({
return {
date: getDate(state),
})
}
}
export default connect(
mapStateToProps,
null,
)(SymptomEditView)
export default connect(mapStateToProps, null)(SymptomEditView)
+57 -90
View File
@@ -1,4 +1,4 @@
import React, { Component } from 'react'
import React, { useEffect, useState } from 'react'
import { Platform, StyleSheet, View } from 'react-native'
import PropTypes from 'prop-types'
import { Keyboard } from 'react-native'
@@ -11,86 +11,52 @@ import Segment from '../common/segment'
import { connect } from 'react-redux'
import { getDate } from '../../slices/date'
import { isTemperatureOutOfRange, isPreviousTemperature } from '../helpers/cycle-day'
import {
getTemperatureOutOfRangeMessage,
getPreviousTemperature,
formatTemperature,
} from '../helpers/cycle-day'
import { temperature as labels } from '../../i18n/en/cycle-day'
import { Colors, Containers, Sizes, Spacing } from '../../styles'
const formatTemperature = value => value === null
? value
: Number.parseFloat(value).toFixed(2)
const Temperature = ({ data, date, save }) => {
const [isTimePickerVisible, setIsTimePickerVisible] = useState(false)
const [temperature, setTemperature] = useState(
formatTemperature(data.value) || getPreviousTemperature(date)
)
class Temperature extends Component {
// update state in parent component once to ensure
// that pre-filled values are saved on button click
useEffect(() => {
if (temperature) {
save(temperature, 'value')
}
}, [])
static propTypes = {
data: PropTypes.object,
date: PropTypes.string.isRequired,
save: PropTypes.func
function onChangeTemperature(value) {
const formattedValue = value.replace(',', '.').trim()
if (!Number(formattedValue) && value !== '') return false
setTemperature(formattedValue)
}
constructor(props) {
super(props)
const { data, date } = this.props
const { value } = data
const { shouldShowSuggestion, suggestedTemperature } =
isPreviousTemperature(date)
this.state = {
isTimePickerVisible: false,
shouldShowSuggestion,
suggestedTemperature: formatTemperature(suggestedTemperature),
value: formatTemperature(value)
}
}
onCancelTimePicker = () => {
this.setState({ isTimePickerVisible: false })
}
onChangeTemperature = (value) => {
if (!Number(value)) return false
this.setState({
value: value.trim(),
shouldShowSuggestion: false
})
}
onShowTimePicker = () => {
function onShowTimePicker() {
Keyboard.dismiss()
this.setState({ isTimePickerVisible: true })
setIsTimePickerVisible(true)
}
setTemperature = () => {
const { value } = this.state
this.props.save(value, 'value')
}
setTime = (jsDate) => {
function setTime(jsDate) {
const time = moment(jsDate).format('HH:mm')
const isTimePickerVisible = false
this.props.save(time, 'time')
this.setState({ isTimePickerVisible })
save(time, 'time')
setIsTimePickerVisible(false)
}
render() {
const { shouldShowSuggestion, suggestedTemperature, value } = this.state
const { time } = this.props.data
const { time } = data
const inputStyle = (shouldShowSuggestion && value === null)
? { color: Colors.grey }
: {color: Colors.greyDark}
const outOfRangeWarning = isTemperatureOutOfRange(value)
let temperatureToShow = null
if (value) {
temperatureToShow = value
} else if (shouldShowSuggestion) {
temperatureToShow = suggestedTemperature
}
const inputStyle = { color: Colors.greyDark }
const outOfRangeWarning = getTemperatureOutOfRangeMessage(temperature)
return (
<React.Fragment>
@@ -98,9 +64,9 @@ class Temperature extends Component {
<AppText style={styles.title}>{labels.temperature.explainer}</AppText>
<View style={styles.container}>
<AppTextInput
value={temperatureToShow === null ? '' : temperatureToShow}
onChangeText={this.onChangeTemperature}
onEndEditing={this.setTemperature}
value={temperature}
onChangeText={onChangeTemperature}
onEndEditing={() => save(temperature, 'value')}
keyboardType="numeric"
maxLength={5}
style={inputStyle}
@@ -109,56 +75,57 @@ class Temperature extends Component {
/>
<AppText>°C</AppText>
</View>
{ outOfRangeWarning !== null &&
{!!outOfRangeWarning && (
<View style={styles.hintContainer}>
<AppText style={styles.hint}>{outOfRangeWarning}</AppText>
</View>
}
)}
</Segment>
<Segment>
<AppText style={styles.title}>{labels.time}</AppText>
<AppTextInput
onFocus={this.onShowTimePicker}
testID='timeInput'
onFocus={onShowTimePicker}
testID="timeInput"
value={time}
/>
<DateTimePicker
isVisible={this.state.isTimePickerVisible}
isVisible={isTimePickerVisible}
mode="time"
onConfirm={this.setTime}
onCancel={this.onCancelTimePicker}
display={Platform.OS === "ios" ? "spinner" : "default"}
onConfirm={setTime}
onCancel={() => setIsTimePickerVisible(false)}
display={Platform.OS === 'ios' ? 'spinner' : 'default'}
/>
</Segment>
</React.Fragment>
)
}
}
const styles = StyleSheet.create({
container: {
...Containers.rowContainer
...Containers.rowContainer,
},
hint: {
fontStyle: 'italic',
fontSize: Sizes.small
fontSize: Sizes.small,
},
hintContainer: {
marginVertical: Spacing.tiny
marginVertical: Spacing.tiny,
},
title: {
fontSize: Sizes.subtitle
}
fontSize: Sizes.subtitle,
},
})
const mapStateToProps = (state) => {
return({
date: getDate(state),
})
Temperature.propTypes = {
data: PropTypes.object.isRequired,
date: PropTypes.string.isRequired,
save: PropTypes.func.isRequired,
}
export default connect(
mapStateToProps,
null,
)(Temperature)
const mapStateToProps = (state) => {
return {
date: getDate(state),
}
}
export default connect(mapStateToProps, null)(Temperature)
+128 -103
View File
@@ -1,6 +1,6 @@
import { ChronoUnit, LocalDate, LocalTime } from 'js-joda'
import { getPreviousTemperature, saveSymptom } from '../../db'
import { getPreviousTemperatureForDate, saveSymptom } from '../../db'
import { scaleObservable } from '../../local-storage'
import * as labels from '../../i18n/en/cycle-day'
@@ -23,39 +23,35 @@ const temperatureLabels = labels.temperature
const minutes = ChronoUnit.MINUTES
const isNumber = (value) => typeof value === 'number'
export const shouldShow = (value) => value !== null ? true : false
export const shouldShow = (value) => (value !== null ? true : false)
export const isPreviousTemperature = (temperature) => {
const previousTemperature = getPreviousTemperature(temperature)
const shouldShowSuggestion = previousTemperature ? true : false
const suggestedTemperature = previousTemperature ?
previousTemperature.toString() : null
export const formatTemperature = (temperature) =>
!temperature
? temperature
: Number.parseFloat(temperature.toString()).toFixed(2)
return { shouldShowSuggestion, suggestedTemperature }
export const getPreviousTemperature = (date) => {
const previousTemperature = getPreviousTemperatureForDate(date)
return formatTemperature(previousTemperature)
}
export const isTemperatureOutOfRange = (temperature) => {
export const getTemperatureOutOfRangeMessage = (temperature) => {
if (!temperature) return null
const value = Number(temperature)
const range = { min: TEMP_MIN, max: TEMP_MAX }
const scale = scaleObservable.value
let warningMsg = null
if (value < range.min || value > range.max) {
warningMsg = labels.temperature.outOfAbsoluteRangeWarning
} else if (value < scale.min || value > scale.max) {
warningMsg = labels.temperature.outOfRangeWarning
}
return warningMsg
return value < TEMP_MIN || value > TEMP_MAX
? labels.temperature.outOfAbsoluteRangeWarning
: value < scale.min || value > scale.max
? labels.temperature.outOfRangeWarning
: ''
}
export const blank = {
bleeding: {
exclude: false,
value: null
value: null,
},
cervix: {
exclude: false,
@@ -64,9 +60,9 @@ export const blank = {
position: null,
},
desire: {
value: null
value: null,
},
mood:{
mood: {
happy: null,
sad: null,
stressed: null,
@@ -77,16 +73,16 @@ export const blank = {
fatigue: null,
angry: null,
other: null,
note: null
note: null,
},
mucus: {
exclude: false,
feeling: null,
texture: null,
value: null
value: null,
},
note: {
value: null
value: null,
},
pain: {
cramps: null,
@@ -97,7 +93,7 @@ export const blank = {
tenderBreasts: null,
migraine: null,
other: null,
note: null
note: null,
},
sex: {
solo: null,
@@ -111,14 +107,14 @@ export const blank = {
diaphragm: null,
none: null,
other: null,
note: null
note: null,
},
temperature: {
exclude: false,
note: null,
time: LocalTime.now().truncatedTo(minutes).toString(),
value: null
}
value: null,
},
}
export const symtomPage = {
@@ -126,11 +122,13 @@ export const symtomPage = {
excludeText: labels.bleeding.exclude.explainer,
note: null,
selectBoxGroups: null,
selectTabGroups: [{
selectTabGroups: [
{
key: 'value',
options: getLabelsList(bleedingLabels),
title: labels.bleeding.heaviness.explainer,
}]
},
],
},
cervix: {
excludeText: cervixLabels.excludeExplainer,
@@ -151,18 +149,20 @@ export const symtomPage = {
key: 'position',
options: getLabelsList(cervixLabels.position.categories),
title: cervixLabels.position.explainer,
}
]
},
],
},
desire: {
excludeText: null,
note: null,
selectBoxGroups: null,
selectTabGroups: [{
selectTabGroups: [
{
key: 'value',
options: getLabelsList(intensityLabels),
title: labels.desire.explainer
}]
title: labels.desire.explainer,
},
],
},
mucus: {
excludeText: mucusLabels.excludeExplainer,
@@ -178,34 +178,38 @@ export const symtomPage = {
key: 'texture',
options: getLabelsList(mucusLabels.texture.categories),
title: mucusLabels.texture.explainer,
}
]
},
],
},
mood: {
excludeText: null,
note: null,
selectBoxGroups: [{
selectBoxGroups: [
{
key: 'mood',
options: moodLabels,
title: labels.mood.explainer
}],
selectTabGroups: null
title: labels.mood.explainer,
},
],
selectTabGroups: null,
},
note: {
excludeText: null,
note: noteDescription,
selectBoxGroups: null,
selectTabGroups: null
selectTabGroups: null,
},
pain: {
excludeText: null,
note: null,
selectBoxGroups: [{
selectBoxGroups: [
{
key: 'pain',
options: painLabels,
title: labels.pain.explainer
}],
selectTabGroups: null
title: labels.pain.explainer,
},
],
selectTabGroups: null,
},
sex: {
excludeText: null,
@@ -220,40 +224,42 @@ export const symtomPage = {
key: 'contraceptives',
options: contraceptiveLabels,
title: labels.contraceptives.explainer,
}
},
],
selectTabGroups: null
selectTabGroups: null,
},
temperature: {
excludeText: temperatureLabels.exclude.explainer,
note: temperatureLabels.note.explainer,
selectBoxGroups: null,
selectTabGroups: null
}
selectTabGroups: null,
},
}
export const save = {
bleeding: (data, date, shouldDeleteData) => {
const { exclude, value } = data
const isDataEntered = isNumber(value)
const valuesToSave = shouldDeleteData || !isDataEntered
? null : { value, exclude }
const valuesToSave =
shouldDeleteData || !isDataEntered ? null : { value, exclude }
saveSymptom('bleeding', date, valuesToSave)
},
cervix: (data, date, shouldDeleteData) => {
const { opening, firmness, position, exclude } = data
const isDataEntered = ['opening', 'firmness', 'position'].some(
value => isNumber(data[value]))
const valuesToSave = shouldDeleteData || !isDataEntered
? null : { opening, firmness, position, exclude }
const isDataEntered = ['opening', 'firmness', 'position'].some((value) =>
isNumber(data[value])
)
const valuesToSave =
shouldDeleteData || !isDataEntered
? null
: { opening, firmness, position, exclude }
saveSymptom('cervix', date, valuesToSave)
},
desire: (data, date, shouldDeleteData) => {
const { value } = data
const valuesToSave = shouldDeleteData || !isNumber(value)
? null : { value }
const valuesToSave = shouldDeleteData || !isNumber(value) ? null : { value }
saveSymptom('desire', date, valuesToSave)
},
@@ -262,11 +268,18 @@ export const save = {
},
mucus: (data, date, shouldDeleteData) => {
const { feeling, texture, exclude } = data
const isDataEntered = ['feeling', 'texture'].some(
value => isNumber(data[value]))
const valuesToSave = shouldDeleteData || !isDataEntered
const isDataEntered = ['feeling', 'texture'].some((value) =>
isNumber(data[value])
)
const valuesToSave =
shouldDeleteData || !isDataEntered
? null
: { feeling, texture, value: computeNfpValue(feeling, texture), exclude }
: {
feeling,
texture,
value: computeNfpValue(feeling, texture),
exclude,
}
saveSymptom('mucus', date, valuesToSave)
},
@@ -289,21 +302,20 @@ export const save = {
exclude,
note,
time,
value: Number(value)
value: Number(value),
}
saveSymptom(
'temperature',
date,
(shouldDeleteData || value === null) ? null : valuesToSave
shouldDeleteData || value === null ? null : valuesToSave
)
}
},
}
const saveBoxSymptom = (data, date, shouldDeleteData, symptom) => {
const isDataEntered = Object.keys(data).some(key => data[key] !== null)
const valuesToSave = shouldDeleteData || !isDataEntered
? null : data
const isDataEntered = Object.keys(data).some((key) => data[key] !== null)
const valuesToSave = shouldDeleteData || !isDataEntered ? null : data
saveSymptom(symptom, date, valuesToSave)
}
@@ -327,46 +339,59 @@ const label = {
return temperatureLabel
}
},
mucus: mucus => {
const filledCategories = ['feeling', 'texture'].filter(c => isNumber(mucus[c]))
let label = filledCategories.map(category => {
return labels.mucus.subcategories[category] + ': ' + labels.mucus[category].categories[mucus[category]]
}).join(', ')
mucus: (mucus) => {
const filledCategories = ['feeling', 'texture'].filter((c) =>
isNumber(mucus[c])
)
let label = filledCategories
.map((category) => {
return (
labels.mucus.subcategories[category] +
': ' +
labels.mucus[category].categories[mucus[category]]
)
})
.join(', ')
if (isNumber(mucus.value)) label += `\n => ${labels.mucusNFP[mucus.value]}`
if (mucus.exclude) label = `(${label})`
return label
},
cervix: cervix => {
const filledCategories = ['opening', 'firmness', 'position'].filter(c => isNumber(cervix[c]))
let label = filledCategories.map(category => {
return labels.cervix.subcategories[category] + ': ' + labels.cervix[category].categories[cervix[category]]
}).join(', ')
cervix: (cervix) => {
const filledCategories = ['opening', 'firmness', 'position'].filter((c) =>
isNumber(cervix[c])
)
let label = filledCategories
.map((category) => {
return (
labels.cervix.subcategories[category] +
': ' +
labels.cervix[category].categories[cervix[category]]
)
})
.join(', ')
if (cervix.exclude) label = `(${label})`
return label
},
note: note => note.value,
note: (note) => note.value,
desire: ({ value }) => {
if (isNumber(value)) {
return intensityLabels[value]
}
},
sex: sex => {
sex: (sex) => {
const sexLabel = []
if (sex && Object.values({...sex}).some(val => val)){
Object.keys(sex).forEach(key => {
if(sex[key] && key !== 'other' && key !== 'note') {
sexLabel.push(
sexLabels[key] ||
contraceptiveLabels[key]
)
if (sex && Object.values({ ...sex }).some((val) => val)) {
Object.keys(sex).forEach((key) => {
if (sex[key] && key !== 'other' && key !== 'note') {
sexLabel.push(sexLabels[key] || contraceptiveLabels[key])
}
if(key === 'other' && sex.other) {
if (key === 'other' && sex.other) {
let label = contraceptiveLabels[key]
if(sex.note) {
if (sex.note) {
label = `${label} (${sex.note})`
}
sexLabel.push(label)
@@ -375,16 +400,16 @@ const label = {
return sexLabel.join(', ')
}
},
pain: pain => {
pain: (pain) => {
const painLabel = []
if (pain && Object.values({...pain}).some(val => val)){
Object.keys(pain).forEach(key => {
if(pain[key] && key !== 'other' && key !== 'note') {
if (pain && Object.values({ ...pain }).some((val) => val)) {
Object.keys(pain).forEach((key) => {
if (pain[key] && key !== 'other' && key !== 'note') {
painLabel.push(painLabels[key])
}
if(key === 'other' && pain.other) {
if (key === 'other' && pain.other) {
let label = painLabels[key]
if(pain.note) {
if (pain.note) {
label = `${label} (${pain.note})`
}
painLabel.push(label)
@@ -393,16 +418,16 @@ const label = {
return painLabel.join(', ')
}
},
mood: mood => {
mood: (mood) => {
const moodLabel = []
if (mood && Object.values({...mood}).some(val => val)){
Object.keys(mood).forEach(key => {
if(mood[key] && key !== 'other' && key !== 'note') {
if (mood && Object.values({ ...mood }).some((val) => val)) {
Object.keys(mood).forEach((key) => {
if (mood[key] && key !== 'other' && key !== 'note') {
moodLabel.push(moodLabels[key])
}
if(key === 'other' && mood.other) {
if (key === 'other' && mood.other) {
let label = moodLabels[key]
if(mood.note) {
if (mood.note) {
label = `${label} (${mood.note})`
}
moodLabel.push(label)
@@ -410,7 +435,7 @@ const label = {
})
return moodLabel.join(', ')
}
}
},
}
export const getData = (symptom, symptomData) => {
+33 -22
View File
@@ -11,7 +11,7 @@ let db
let checkIsMensesStart
let getMensesDaysRightAfter
export async function openDb (hash) {
export async function openDb(hash) {
const realmConfig = {}
if (hash) {
realmConfig.encryptionKey = hashToInt8Array(hash)
@@ -22,7 +22,7 @@ export async function openDb (hash) {
let tempConnection
try {
tempConnection = await Realm.open(realmConfig)
} catch(err) {
} catch (err) {
const isErrorDecrypting = err.toString().includes('decrypt')
const isErrorMnemonic = err.toString().includes('Invalid mnemonic')
// tried to open without password, but is encrypted or incorrect pwd
@@ -36,20 +36,16 @@ export async function openDb (hash) {
let nextSchemaIndex = Realm.schemaVersion(Realm.defaultPath)
tempConnection.close()
while (nextSchemaIndex < schemas.length - 1) {
const tempConfig = Object.assign(
realmConfig,
schemas[nextSchemaIndex++]
)
const tempConfig = Object.assign(realmConfig, schemas[nextSchemaIndex++])
const migratedRealm = new Realm(tempConfig)
migratedRealm.close()
}
// open the Realm with the latest schema
realmConfig.schema = schemas[schemas.length - 1]
const connection = await Realm.open(Object.assign(
realmConfig,
schemas[schemas.length - 1]
))
const connection = await Realm.open(
Object.assign(realmConfig, schemas[schemas.length - 1])
)
db = connection
const cycle = cycleModule()
@@ -63,17 +59,26 @@ export function closeDb() {
}
export function getBleedingDaysSortedByDate() {
return db.objects('CycleDay').filtered('bleeding != null').sorted('date', true)
return db
.objects('CycleDay')
.filtered('bleeding != null')
.sorted('date', true)
}
export function getTemperatureDaysSortedByDate() {
return db.objects('CycleDay').filtered('temperature != null').sorted('date', true)
return db
.objects('CycleDay')
.filtered('temperature != null')
.sorted('date', true)
}
export function getCycleDaysSortedByDate() {
return db.objects('CycleDay').sorted('date', true)
}
export function getCycleStartsSortedByDate() {
return db.objects('CycleDay').filtered('isCycleStart = true').sorted('date', true)
return db
.objects('CycleDay')
.filtered('isCycleStart = true')
.sorted('date', true)
}
export function saveSymptom(symptom, date, val) {
let cycleDay = getCycleDay(date)
@@ -83,7 +88,10 @@ export function saveSymptom(symptom, date, val) {
if (symptom === 'bleeding') {
const mensesDaysAfter = getMensesDaysRightAfter(cycleDay)
maybeSetNewCycleStart({
val, cycleDay, mensesDaysAfter, checkIsMensesStart
val,
cycleDay,
mensesDaysAfter,
checkIsMensesStart,
})
} else {
cycleDay[symptom] = val
@@ -93,7 +101,7 @@ export function saveSymptom(symptom, date, val) {
export function updateCycleStartsForAllCycleDays() {
db.write(() => {
getBleedingDaysSortedByDate().forEach(day => {
getBleedingDaysSortedByDate().forEach((day) => {
if (checkIsMensesStart(day)) {
day.isCycleStart = true
}
@@ -106,7 +114,7 @@ export function createCycleDay(dateString) {
db.write(() => {
result = db.create('CycleDay', {
date: dateString,
isCycleStart: false
isCycleStart: false,
})
})
return result
@@ -116,9 +124,9 @@ export function getCycleDay(dateString) {
return db.objectForPrimaryKey('CycleDay', dateString)
}
export function getPreviousTemperature(date) {
export function getPreviousTemperatureForDate(date) {
const targetDate = LocalDate.parse(date)
const winner = getTemperatureDaysSortedByDate().find(candidate => {
const winner = getTemperatureDaysSortedByDate().find((candidate) => {
return LocalDate.parse(candidate.date).isBefore(targetDate)
})
if (!winner) return null
@@ -171,10 +179,13 @@ export function tryToImportWithoutDelete(cycleDays) {
}
export function requestHash(type, pw) {
nodejs.channel.post('request-SHA512', JSON.stringify({
nodejs.channel.post(
'request-SHA512',
JSON.stringify({
type: type,
message: pw
}))
message: pw,
})
)
}
export async function changeEncryptionAndRestartApp(hash) {
@@ -199,7 +210,7 @@ export async function changeEncryptionAndRestartApp(hash) {
restart.Restart()
}
export function isDbEmpty () {
export function isDbEmpty() {
return db.empty
}