diff --git a/components/bleeding.js b/components/bleeding.js deleted file mode 100644 index 0472c3c..0000000 --- a/components/bleeding.js +++ /dev/null @@ -1,102 +0,0 @@ -import React, { Component } from 'react' -import { - View, - Button, - Text, - Switch -} from 'react-native' -import RadioForm from 'react-native-simple-radio-button' -import styles from '../styles/index' -import { saveBleeding } from '../db' -import { bleeding as labels } from '../labels/labels' - -export default class Bleeding extends Component { - constructor(props) { - super(props) - this.cycleDay = props.cycleDay - this.showView = props.showView - let bleedingValue = this.cycleDay.bleeding && this.cycleDay.bleeding.value - if (! (typeof bleedingValue === 'number') ){ - bleedingValue = -1 - } - this.state = { - currentValue: bleedingValue, - exclude: this.cycleDay.bleeding ? this.cycleDay.bleeding.exclude : false - } - } - - render() { - const bleedingRadioProps = [ - {label: labels[0], value: 0 }, - {label: labels[1], value: 1 }, - {label: labels[2], value: 2 }, - {label: labels[3], value: 3 }, - ] - return ( - - - - - Bleeding - - - { - this.setState({currentValue: itemValue}) - }} - /> - - - - - Exclude - - - { - this.setState({exclude: val}) - }} - value={this.state.exclude} - /> - - - - - - - - - - - - - - - - ) - } -} \ No newline at end of file diff --git a/components/cycle-day/action-buttons.js b/components/cycle-day/action-buttons.js new file mode 100644 index 0000000..0008552 --- /dev/null +++ b/components/cycle-day/action-buttons.js @@ -0,0 +1,46 @@ +import React from 'react' +import { + View, + Button, +} from 'react-native' +import { saveSymptom } from '../../db' + +export default function (showView) { + return function ({ symptom, cycleDay, saveAction, saveDisabled}) { + const buttons = [ + { + title: 'Cancel', + action: () => showView('dayView') + }, + { + title: 'Delete', + action: () => { + saveSymptom(symptom, cycleDay) + showView('dayView') + } + }, { + title: 'Save', + action: () => { + saveAction() + showView('dayView') + }, + disabled: saveDisabled + } + ] + + return buttons.map(({ title, action, disabledCondition }, i) => { + const style = { flex: 1, marginHorizontal: 10 } + if (i === 0) style.marginLeft = 0 + if (i === buttons.length - 1) style.marginRight = 0 + return ( + + + + ) + }) + } +} \ No newline at end of file diff --git a/components/cycle-day-overview.js b/components/cycle-day/cycle-day-overview.js similarity index 67% rename from components/cycle-day-overview.js rename to components/cycle-day/cycle-day-overview.js index cc780da..6741598 100644 --- a/components/cycle-day-overview.js +++ b/components/cycle-day/cycle-day-overview.js @@ -4,10 +4,10 @@ import { Button, Text } from 'react-native' -import styles from '../styles/index' -import { bleeding as labels} from '../labels/labels' -import cycleDayModule from '../lib/get-cycle-day-number' -import { bleedingDaysSortedByDate } from '../db' +import styles from '../../styles' +import { bleeding as labels} from './labels/labels' +import cycleDayModule from '../../lib/get-cycle-day-number' +import { bleedingDaysSortedByDate } from '../../db' const getCycleDayNumber = cycleDayModule() @@ -47,30 +47,28 @@ export default class DayView extends Component { const temperatureValue = this.cycleDay.temperature && this.cycleDay.temperature.value let temperatureLabel if (typeof temperatureValue === 'number') { - temperatureLabel = `${temperatureValue} °C` - if (this.cycleDay.temperature.exclude) temperatureLabel = "( " + temperatureLabel + " )" + temperatureLabel = `${temperatureValue} °C - ${this.cycleDay.temperature.time}` + if (this.cycleDay.temperature.exclude) { + temperatureLabel = "( " + temperatureLabel + " )" + } } else { temperatureLabel = 'edit' } return ( - - - - Bleeding - - + + + Bleeding + - - - Temperature - - + + Temperature + - + - + - + - - - - - - - - - - ) - } -} diff --git a/db.js b/db.js index 3fdd401..00e1d94 100644 --- a/db.js +++ b/db.js @@ -47,20 +47,14 @@ const db = new Realm({ const bleedingDaysSortedByDate = db.objects('CycleDay').filtered('bleeding != null').sorted('date', true) const temperatureDaysSortedByDate = db.objects('CycleDay').filtered('temperature != null').sorted('date', true) -function saveTemperature(cycleDay, temperature) { +function saveSymptom(symptom, cycleDay, val) { db.write(() => { - cycleDay.temperature = temperature + cycleDay[symptom] = val }) } const cycleDaysSortedByDate = db.objects('CycleDay').sorted('date', true) -function saveBleeding(cycleDay, bleeding) { - db.write(() => { - cycleDay.bleeding = bleeding - }) -} - function getOrCreateCycleDay(localDate) { let result = db.objectForPrimaryKey('CycleDay', localDate) if (!result) { @@ -94,8 +88,7 @@ function getPreviousTemperature(cycleDay) { } export { - saveTemperature, - saveBleeding, + saveSymptom, getOrCreateCycleDay, bleedingDaysSortedByDate, temperatureDaysSortedByDate, diff --git a/styles/index.js b/styles/index.js index 5eb9cc1..52fc65d 100644 --- a/styles/index.js +++ b/styles/index.js @@ -14,91 +14,73 @@ export default StyleSheet.create({ dateHeader: { fontSize: 20, fontWeight: 'bold', - margin: 30, + margin: 15, color: 'white', textAlign: 'center', textAlignVertical: 'center' }, cycleDayNumber: { fontSize: 18, - margin: 20, + margin: 15, textAlign: 'center', textAlignVertical: 'center' }, symptomDayView: { fontSize: 20, - margin: 30, - textAlign: 'left', textAlignVertical: 'center' }, radioButton: { fontSize: 18, - margin: 5, + margin: 8, textAlign: 'center', textAlignVertical: 'center' }, - singleButtonView: { - flex: 1, - margin: 5 - }, - itemsInRowView: { - flex: 1, - flexDirection: 'row', - justifyContent: 'flex-start', - alignItems: 'center' - }, - itemsInRowSeparatedView: { - flex: 1, - flexDirection: 'row', - justifyContent: 'space-evenly', - alignItems: 'center' - }, symptomEditView: { - flex: 1, - flexDirection: 'column', justifyContent: 'space-between', - alignItems: 'flex-start' + marginHorizontal: 15 }, - symptomEditSplitSymptomsAndLastRowButtons: { - flex: 4, - flexDirection: 'column', - justifyContent: 'flex-start', - alignItems: 'flex-start' + symptomEditRow: { + justifyContent: 'space-between', + marginBottom: 10, }, - symptomEditListedSymptomView: { - flex: 1, - flexDirection: 'column', - justifyContent: 'flex-start', - alignItems: 'flex-start' - }, - cycleDayOuterView: { - flex: 1, - flexDirection: 'column', - justifyContent: 'space-around' + symptomViewRowInline: { + flexDirection: 'row', + justifyContent: 'space-between', + marginBottom: 10, + alignItems: 'center', + height: 50 }, cycleDayDateView: { - flex: 2, justifyContent: 'center', backgroundColor: 'steelblue' }, cycleDayNumberView: { - flex: 1, justifyContent: 'center', - backgroundColor: 'skyblue' + backgroundColor: 'skyblue', + marginBottom: 15 }, - cycleDaySymptomsView: { - flex: 8, - justifyContent: 'center' + homeButtons: { + marginHorizontal: 15 }, - homeContainerView: { - flex: 0.5, - flexDirection: 'column', - justifyContent: 'space-around' + homeButton: { + marginBottom: 15 }, - homeButtonsView: { - flex: 3, - flexDirection: 'column', - justifyContent: 'space-around', - margin: 5 + temperatureTextInput: { + width: 80, + textAlign: 'center', + fontSize: 20 + }, + actionButtonRow: { + flexDirection: 'row', + justifyContent: 'space-evenly', + marginTop: 50 + }, + symptomEditButton: { + width: 130 + }, + radioButtonRow: { + marginTop: 15, + marginLeft: 'auto', + marginRight: 'auto' } }) \ No newline at end of file