From d44b6c348e6d7201a5649cf1dd830680d9dcdc45 Mon Sep 17 00:00:00 2001 From: Julia Friesel Date: Tue, 24 Jul 2018 11:19:58 +0200 Subject: [PATCH] Add note symptom view --- components/cycle-day/cycle-day-overview.js | 108 +++++++++++---------- components/cycle-day/index.js | 6 +- components/cycle-day/symptoms/note.js | 53 ++++++++++ db/index.js | 14 ++- 4 files changed, 127 insertions(+), 54 deletions(-) create mode 100644 components/cycle-day/symptoms/note.js diff --git a/components/cycle-day/cycle-day-overview.js b/components/cycle-day/cycle-day-overview.js index 094bc65..f021a82 100644 --- a/components/cycle-day/cycle-day-overview.js +++ b/components/cycle-day/cycle-day-overview.js @@ -44,53 +44,7 @@ export default class DayView extends Component { } render() { - let bleedingLabel - if (this.cycleDay.bleeding) { - const bleeding = this.cycleDay.bleeding - if (typeof bleeding.value === 'number') { - bleedingLabel = `${bleedingLabels[bleeding.value]}` - if (bleeding.exclude) bleedingLabel = "( " + bleedingLabel + " )" - } - } else { - bleedingLabel = 'edit' - } - - let temperatureLabel - if (this.cycleDay.temperature) { - const temperature = this.cycleDay.temperature - if (typeof temperature.value === 'number') { - temperatureLabel = `${temperature.value} °C - ${temperature.time}` - if (temperature.exclude) { - temperatureLabel = "( " + temperatureLabel + " )" - } - } - } else { - temperatureLabel = 'edit' - } - - let mucusLabel - if (this.cycleDay.mucus) { - const mucus = this.cycleDay.mucus - if (typeof mucus.feeling === 'number' && typeof mucus.texture === 'number') { - mucusLabel = `${feelingLabels[mucus.feeling]} + ${textureLabels[mucus.texture]} ( ${computeSensiplanMucusLabels[mucus.value]} )` - if (mucus.exclude) mucusLabel = "( " + mucusLabel + " )" - } - } else { - mucusLabel = 'edit' - } - - let cervixLabel - if (this.cycleDay.cervix) { - const cervix = this.cycleDay.cervix - if (cervix.opening > -1 && cervix.firmness > -1) { - cervixLabel = `${openingLabels[cervix.opening]} + ${firmnessLabels[cervix.firmness]}` - if (cervix.position > -1) cervixLabel += `+ ${positionLabels[cervix.position]}` - if (cervix.exclude) cervixLabel = "( " + cervixLabel + " )" - } - } else { - cervixLabel = 'edit' - } - + const cycleDay = this.cycleDay return ( @@ -98,7 +52,7 @@ export default class DayView extends Component { @@ -107,7 +61,7 @@ export default class DayView extends Component { @@ -116,7 +70,7 @@ export default class DayView extends Component { @@ -125,7 +79,17 @@ export default class DayView extends Component { + + + + Note + + @@ -133,3 +97,45 @@ export default class DayView extends Component { ) } } + +function getLabel(symptomName, symptom) { + const labels = { + bleeding: bleeding => { + if (typeof bleeding.value === 'number') { + let bleedingLabel = `${bleedingLabels[bleeding.value]}` + if (bleeding.exclude) bleedingLabel = "( " + bleedingLabel + " )" + return bleedingLabel + } + }, + temperature: temperature => { + if (typeof temperature.value === 'number') { + let temperatureLabel = `${temperature.value} °C - ${temperature.time}` + if (temperature.exclude) { + temperatureLabel = "( " + temperatureLabel + " )" + } + return temperatureLabel + } + }, + mucus: mucus => { + if (typeof mucus.feeling === 'number' && typeof mucus.texture === 'number') { + let mucusLabel = `${feelingLabels[mucus.feeling]} + ${textureLabels[mucus.texture]} ( ${computeSensiplanMucusLabels[mucus.computedNfp]} )` + if (mucus.exclude) mucusLabel = "( " + mucusLabel + " )" + return mucusLabel + } + }, + cervix: cervix => { + if (cervix.opening > -1 && cervix.firmness > -1) { + let cervixLabel = `${openingLabels[cervix.opening]} + ${firmnessLabels[cervix.firmness]}` + if (cervix.position > -1) cervixLabel += `+ ${positionLabels[cervix.position]}` + if (cervix.exclude) cervixLabel = "( " + cervixLabel + " )" + return cervixLabel + } + }, + note: note => { + return note.value.slice(0, 12) + '...' + } + } + + if (!symptom) return 'edit' + return labels[symptomName](symptom) || 'edit' +} \ No newline at end of file diff --git a/components/cycle-day/index.js b/components/cycle-day/index.js index e0eb666..fa8aedf 100644 --- a/components/cycle-day/index.js +++ b/components/cycle-day/index.js @@ -10,8 +10,9 @@ import DayView from './cycle-day-overview' import BleedingEditView from './symptoms/bleeding' import TemperatureEditView from './symptoms/temperature' import MucusEditView from './symptoms/mucus' -import { formatDateForViewHeader } from './labels/format' import CervixEditView from './symptoms/cervix' +import NoteEditView from './symptoms/note' +import { formatDateForViewHeader } from './labels/format' import styles from '../../styles' import actionButtonModule from './action-buttons' @@ -59,7 +60,8 @@ export default class Day extends Component { bleedingEditView: , temperatureEditView: , mucusEditView: , - cervixEditView: + cervixEditView: , + noteEditView: }[this.state.visibleComponent] } diff --git a/components/cycle-day/symptoms/note.js b/components/cycle-day/symptoms/note.js new file mode 100644 index 0000000..d0e41ac --- /dev/null +++ b/components/cycle-day/symptoms/note.js @@ -0,0 +1,53 @@ +import React, { Component } from 'react' +import { + View, + Text, + TextInput, +} from 'react-native' + +import styles from '../../../styles' +import { saveSymptom } from '../../../db' + +export default class Temp extends Component { + constructor(props) { + super(props) + this.cycleDay = props.cycleDay + const note = this.cycleDay.note + this.makeActionButtons = props.makeActionButtons + + this.state = { + currentValue: note && note.value || '' + } + } + + render() { + console.log(this.cycleDay.note) + return ( + + + Note + { + this.setState({ currentValue: val }) + }} + value={this.state.currentValue} + /> + + + {this.makeActionButtons({ + symptom: 'note', + cycleDay: this.cycleDay, + saveAction: () => { + saveSymptom('note', this.cycleDay, { + value: this.state.currentValue + }) + }, + saveDisabled: !this.state.currentValue + })} + + + ) + } +} \ No newline at end of file diff --git a/db/index.js b/db/index.js index ed3e275..80dc08e 100644 --- a/db/index.js +++ b/db/index.js @@ -46,6 +46,13 @@ const CervixSchema = { } } +const NoteSchema = { + name: 'Note', + properties: { + value: 'string' + } +} + const CycleDaySchema = { name: 'CycleDay', primaryKey: 'date', @@ -66,6 +73,10 @@ const CycleDaySchema = { cervix: { type: 'Cervix', optional: true + }, + note: { + type: 'Note', + optional: true } } } @@ -76,7 +87,8 @@ const realmConfig = { TemperatureSchema, BleedingSchema, MucusSchema, - CervixSchema + CervixSchema, + NoteSchema ], // we only want this in dev mode deleteRealmIfMigrationNeeded: true