Skip to content
Snippets Groups Projects
mucus.js 3.18 KiB
Newer Older
import React, { Component } from 'react'
import {
  View,
  Switch,
  ScrollView
} from 'react-native'
import styles from '../../../styles'
import { saveSymptom } from '../../../db'
Julia Friesel's avatar
Julia Friesel committed
import { mucus as labels } from '../labels/labels'
emelko's avatar
emelko committed
import computeSensiplanValue from '../../../lib/sensiplan-mucus'
import ActionButtonFooter from './action-button-footer'
import SelectTabGroup from '../select-tab-group'
Julia Friesel's avatar
Julia Friesel committed
import SymptomSection from './symptom-section'
emelko's avatar
emelko committed


export default class Mucus extends Component {
  constructor(props) {
    super(props)
    this.cycleDay = props.cycleDay
emelko's avatar
emelko committed
    this.makeActionButtons = props.makeActionButtons
    this.state = {
      exclude: this.cycleDay.mucus ? this.cycleDay.mucus.exclude : false
    /* eslint-disable react/no-direct-mutation-state */
    ['feeling', 'texture'].forEach(label => {
      this.state[label] = this.cycleDay.mucus && this.cycleDay.mucus[label]
      if (typeof this.state[label] !== 'number') {
        this.state[label] = -1
      }
    })
    /* eslint-enable react/no-direct-mutation-state */
    const mucusFeeling = [
Julia Friesel's avatar
Julia Friesel committed
      { label: labels.feeling.categories[0], stateKey: ''},
      { label: labels.feeling.categories[1], value: 1 },
      { label: labels.feeling.categories[2], value: 2 },
      { label: labels.feeling.categories[3], value: 3 }
    const mucusTexture = [
Julia Friesel's avatar
Julia Friesel committed
      { label: labels.texture.categories[0], value: 0 },
      { label: labels.texture.categories[1], value: 1 },
      { label: labels.texture.categories[2], value: 2 }
      <View style={{ flex: 1 }}>
        <ScrollView style={styles.page}>
Julia Friesel's avatar
Julia Friesel committed
          <SymptomSection
            header='Feeling'
            explainer={labels.feeling.explainer}
          >
              buttons={mucusFeeling}
              onSelect={val => this.setState({ feeling: val })}
              active={this.state.feeling}
            />
Julia Friesel's avatar
Julia Friesel committed
          </SymptomSection>
          <SymptomSection
            header='Texture'
            explainer={labels.texture.explainer}
          >
              buttons={mucusTexture}
              onSelect={val => this.setState({ texture: val })}
              active={this.state.texture}
            />
Julia Friesel's avatar
Julia Friesel committed
          </SymptomSection>
          <SymptomSection
            header="Exclude"
            explainer={labels.excludeExplainer}
            inline={true}
Julia Friesel's avatar
Julia Friesel committed
          >
            <Switch
              onValueChange={(val) => {
                this.setState({ exclude: val })
              }}
              value={this.state.exclude}
            />
          </SymptomSection>
        </ScrollView>
        <ActionButtonFooter
          symptom='mucus'
          cycleDay={this.cycleDay}
          saveAction={() => {
Julia Friesel's avatar
Julia Friesel committed
            const feeling = this.state.feeling
            const texture = this.state.texture
            saveSymptom('mucus', this.cycleDay, {
Julia Friesel's avatar
Julia Friesel committed
              feeling,
              texture,
              value: computeSensiplanValue(feeling, texture),
              exclude: this.state.exclude
            })
          }}
          saveDisabled={this.state.feeling === -1 || this.state.texture === -1}
          navigate={this.props.navigate}
        />