aboutsummaryrefslogtreecommitdiffstats
path: root/App.jsx
diff options
context:
space:
mode:
authorGravatar piotrruss <mail@pruss.it> 2022-05-22 13:49:12 +0100
committerGravatar piotrruss <mail@pruss.it> 2022-05-22 13:49:12 +0100
commit994bc43d488eefc0ee39f39dd7fae5515322b17b (patch)
tree64872194dbcc1112f1850dd94fd4c3185c1a6d6f /App.jsx
parent853aefca82243a574e3fd8d5e5c7270355ba0cdb (diff)
downloadnotes_mobile-994bc43d488eefc0ee39f39dd7fae5515322b17b.tar.gz
notes_mobile-994bc43d488eefc0ee39f39dd7fae5515322b17b.tar.bz2
notes_mobile-994bc43d488eefc0ee39f39dd7fae5515322b17b.zip
move api & helpers to utils
Diffstat (limited to 'App.jsx')
-rw-r--r--App.jsx51
1 files changed, 51 insertions, 0 deletions
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',
+ }
+})