From 774113edda1b9219001ef4adab3f4e19c46bcecc Mon Sep 17 00:00:00 2001
From: piotrruss <mail@pruss.it>
Date: Sat, 21 May 2022 18:42:30 +0100
Subject: refactor

---
 components/Menu.jsx | 100 +++++++++++++++++++++++-----------------------------
 1 file changed, 44 insertions(+), 56 deletions(-)

(limited to 'components/Menu.jsx')

diff --git a/components/Menu.jsx b/components/Menu.jsx
index fb82f34..519fe94 100644
--- a/components/Menu.jsx
+++ b/components/Menu.jsx
@@ -1,61 +1,49 @@
-import { StyleSheet, Text, View, Alert } from 'react-native';
-import AsyncStorage from '@react-native-async-storage/async-storage';
-import { confirmLogout } from '../helpers'
+import { StyleSheet, Text, View } from 'react-native';
+import { handleLogout } from '../helpers'
 
-const Menu = ({ session, setSession, setEdit, showError, saveNote }) => {
-  const logout = async () => {
-    try {
-      await AsyncStorage.clear();
-      setSession(null)
-    } catch(e) {
-      showError('Error while logging out')
+const Menu = ({ session, setSession, setEdit, showError, saveNote }) => (
+  <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}
+            >
+              Sort
+            </Text>
+            <Text
+              style={styles.menuText}
+              onPress={() => handleLogout({ session, setSession, showError })}
+            >
+              {session.email}
+            </Text>
+          </>
+        )
     }
-  }
-
-  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}
-              >
-                Sort
-              </Text>
-              <Text
-                style={styles.menuText}
-                onPress={() => confirmLogout({ logout, email: session.email })}
-              >
-                {session.email}
-              </Text>
-            </>
-          )
-      }
-    </View>
-  )
-}
+  </View>
+)
 
 const styles = StyleSheet.create({
   menu: {
-- 
cgit v1.2.3

