From 180a25cd4c8204c3f2c71a144a1bbe4b9e03a22d Mon Sep 17 00:00:00 2001
From: Julia Friesel <julia.friesel@gmail.com>
Date: Sat, 18 Aug 2018 20:21:16 +0200
Subject: [PATCH] Turn symptom buttons into footer component

---
 .../symptoms/action-button-footer.js          | 54 +++++++++++++++++++
 1 file changed, 54 insertions(+)
 create mode 100644 components/cycle-day/symptoms/action-button-footer.js

diff --git a/components/cycle-day/symptoms/action-button-footer.js b/components/cycle-day/symptoms/action-button-footer.js
new file mode 100644
index 00000000..0f05a7bc
--- /dev/null
+++ b/components/cycle-day/symptoms/action-button-footer.js
@@ -0,0 +1,54 @@
+import React, { Component } from 'react'
+import {
+  View,
+  Button,
+} from 'react-native'
+import { saveSymptom } from '../../../db'
+import styles from '../../../styles'
+
+export default class ActionButtonFooter extends Component {
+  render() {
+    const { symptom, cycleDay, saveAction, saveDisabled, navigate} = this.props
+    const navigateToOverView = () => navigate('CycleDay', cycleDay)
+    const buttons = [
+      {
+        title: 'Cancel',
+        action: () => navigateToOverView()
+      },
+      {
+        title: 'Delete',
+        action: () => {
+          saveSymptom(symptom, cycleDay)
+          navigateToOverView()
+        },
+        disabledCondition: !cycleDay[symptom]
+      }, {
+        title: 'Save',
+        action: () => {
+          saveAction()
+          navigateToOverView()
+        },
+        disabledCondition: saveDisabled
+      }
+    ]
+
+    return (
+      <View style={styles.actionButtonRow}>
+        {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 (
+            <View style={style} key={i}>
+              <Button
+                onPress={action}
+                disabled={disabledCondition}
+                title={title}>
+              </Button>
+            </View >
+          )
+        })}
+      </View>
+    )
+  }
+}
\ No newline at end of file
-- 
GitLab