From 994bc43d488eefc0ee39f39dd7fae5515322b17b Mon Sep 17 00:00:00 2001
From: piotrruss <mail@pruss.it>
Date: Sun, 22 May 2022 13:49:12 +0100
Subject: move api & helpers to utils

---
 App.jsx | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 51 insertions(+)
 create mode 100644 App.jsx

(limited to 'App.jsx')

diff --git a/App.jsx b/App.jsx
new file mode 100644
index 0000000..2d40b0e
--- /dev/null
+++ b/App.jsx
@@ -0,0 +1,51 @@
+import { StatusBar } from 'expo-status-bar'
+import { StyleSheet, SafeAreaView, Text } from 'react-native'
+import { useState, useEffect } from 'react'
+import AsyncStorage from '@react-native-async-storage/async-storage'
+import Main from './components/Main'
+import Login from './components/Login'
+
+export default function App() {
+  const [session, setSession] = useState()
+  const [error, setError] = useState(null)
+
+  const showError = (e) => {
+    setError(e)
+    setTimeout(() => { setError(null) }, 2000)
+  }
+
+  useEffect(() => {
+    AsyncStorage.getItem('session')
+      .then(session => setSession(JSON.parse(session)))
+      .catch(() => setSession(null))
+  }, [])
+
+  if (error || session === undefined) return (
+    <SafeAreaView style={styles.container}>
+      {error
+        ? <Text style={styles.error}>{error}</Text>
+        : <Text>Loading...</Text>}
+    </SafeAreaView>
+  )
+
+  return (
+    <SafeAreaView style={styles.container}>
+      {
+        session === null
+          ? <Login setSession={setSession} showError={showError} />
+          : <Main session={session} setSession={setSession} showError={showError} />
+      }
+      <StatusBar style="auto" />
+    </SafeAreaView>
+  )
+}
+
+const styles = StyleSheet.create({
+  container: {
+    flex: 1,
+    backgroundColor: '#000',
+  },
+  error: {
+    color: 'red',
+  }
+})
-- 
cgit v1.2.3

