Skip to content
Snippets Groups Projects
pain.js 2.2 KiB
Newer Older
import React, { Component } from 'react'
import {
} from 'react-native'
import { saveSymptom } from '../../../db'
import { pain as labels } from '../../../i18n/en/cycle-day'
import { shared } from '../../../i18n/en/labels'
import ActionButtonFooter from './action-button-footer'
import SelectBoxGroup from '../select-box-group'
Julia Friesel's avatar
Julia Friesel committed
import SymptomSection from './symptom-section'
Julia Friesel's avatar
Julia Friesel committed
import styles from '../../../styles'
export default class Pain extends Component {
  constructor(props) {
    super(props)
    const cycleDay = props.cycleDay
    if (cycleDay && cycleDay.pain) {
      this.state = Object.assign({}, cycleDay.pain)
    } else {
      this.state = {}
    }
    if (this.state.note) {
      this.state.other = true
  toggleState = (key) => {
    const curr = this.state[key]
    this.setState({[key]: !curr})
    if (key === 'other' && !curr) {
      this.setState({focusTextArea: true})
    }
  }

  render() {
    return (
Julia Friesel's avatar
Julia Friesel committed
        <ScrollView style={styles.page}>
Julia Friesel's avatar
Julia Friesel committed
          <SymptomSection
            explainer={labels.explainer}
          >
            <SelectBoxGroup
              labels={labels.categories}
              onSelect={this.toggleState}
              optionsState={this.state}
            />
            { this.state.other &&
              <TextInput
                autoFocus={this.state.focusTextArea}
                multiline={true}
                placeholder={shared.enter}
                value={this.state.note}
                onChangeText={(val) => {
                  this.setState({note: val})
                }}
              />
            }
Julia Friesel's avatar
Julia Friesel committed
          </SymptomSection>
        </ScrollView>
        <ActionButtonFooter
          symptom='pain'
          date={this.props.date}
          currentSymptomValue={this.state}
          saveAction={() => {
            const copyOfState = Object.assign({}, this.state)
            if (!copyOfState.other) {
              copyOfState.note = null
            saveSymptom('pain', this.props.date, copyOfState)
          }}
          saveDisabled={Object.values(this.state).every(value => !value)}
          navigate={this.props.navigate}
        />