From d77d7c440333ded46eeb8d28e22ec5517f3b15b8 Mon Sep 17 00:00:00 2001
From: piotrruss <mail@pruss.it>
Date: Wed, 18 May 2022 23:02:58 +0100
Subject: small fixes

---
 components/Menu.jsx | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 71 insertions(+)
 create mode 100644 components/Menu.jsx

(limited to 'components/Menu.jsx')

diff --git a/components/Menu.jsx b/components/Menu.jsx
new file mode 100644
index 0000000..bc883e4
--- /dev/null
+++ b/components/Menu.jsx
@@ -0,0 +1,71 @@
+import { StyleSheet, Text, View } from 'react-native';
+import AsyncStorage from '@react-native-async-storage/async-storage';
+
+const Menu = ({ session, setSession, setEdit, showError, saveNote }) => {
+  const logout = async () => {
+    try {
+      await AsyncStorage.clear();
+      setSession(null)
+    } catch(e) {
+      showError('Error while logging out')
+    }
+  }
+
+  return (
+    <View style={styles.menu}>
+      {
+        saveNote
+          ? (
+            <>
+              <Text
+                style={styles.menuText}
+                onPress={() => setEdit(null)}
+              >
+                Back
+              </Text>
+              <Text
+                style={styles.menuText}
+                onPress={saveNote}
+              >
+                Save
+              </Text>
+            </>
+          ) : (
+            <>
+              <Text
+                style={styles.menuText}
+                onPress={() => setEdit({})}
+              >
+                New Note
+              </Text>
+              <Text style={styles.menuText}>{session.email}</Text>
+              <Text
+                style={styles.menuText}
+                onPress={logout}
+              >
+                Logout
+              </Text>
+            </>
+          )
+      }
+    </View>
+  )
+}
+
+const styles = StyleSheet.create({
+  menu: {
+    backgroundColor: 'lightgrey',
+    height: 55,
+    width: '100%',
+    flexDirection: 'row',
+    alignItems: 'flex-end',
+    justifyContent: 'space-between',
+    padding: 10,
+  },
+  menuText: {
+    fontWeight: 'bold',
+    paddingHorizontal: 10,
+  },
+});
+
+export default Menu
-- 
cgit v1.2.3

