-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.js
More file actions
111 lines (100 loc) · 2.61 KB
/
Copy pathApp.js
File metadata and controls
111 lines (100 loc) · 2.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/**
* @file app.js
* @description Entry for application.
* @author Tad Decker
*
* TODO: simplify functions involving changing screens
* 11/11/2023
*/
import { useState, useEffect, } from 'react'
import { StyleSheet, SafeAreaView, View, Button} from 'react-native'
import HomeScreen from './components/HomeScreen'
import NoteEditScreen from './components/NoteEditScreen'
import LoginScreen from './components/LoginScreen'
import { getNotes } from './api/notesApi'
import AsyncStorage from '@react-native-async-storage/async-storage'
/**
* @description The entry point for the application.
*/
export default function App() {
// Initialize variables
const [screen, setScreen] = useState("LOGIN")
const [data, setData] = useState([])
const [currNote, setCurrNote] = useState(null)
const [loading, setLoading] = useState(false)
useEffect(() => {
if (screen === "HOME")
fetchData()
}, [screen])
async function fetchData() {
try {
const userId = await AsyncStorage.getItem('userId')
const result = await getNotes(userId) // FIXME: update this dynamically!
setData(result.notes)
} catch (error) {
console.error(error)
}
}
/**
* @function goHome
* @param {Object} currNote
* @description Edit a note in the database. Re-load the notes. Transition to the homescreen.
*/
const goHome = async () => {
fetchData()
setScreen("HOME")
}
const selectNote = (item) => {
setCurrNote(item)
setScreen("NOTE")
}
const changeScreen = (screen) => {
setScreen(screen)
}
return (
// <AuthProvider>
// {/** */}
<SafeAreaView style={styles.main}>
{/* <Button onPress={fetchData} /> */}
{/* Content */}
<View style={{ flex: 1 }}>
{/* lOGIN screen */}
{
screen === "LOGIN" ?
<LoginScreen
changeScreen={changeScreen}
/>
: null
}
{/* HOME screen */}
{
screen === "HOME" ?
<HomeScreen
currData={data}
chooseItem={selectNote}
/>
: null
}
{/* NOTE edit screen */}
{
screen === "NOTE" ?
<NoteEditScreen
currItem={currNote}
goBack={goHome}
/>
: null
}
</View>
{/*<Button title="Test" onPress={test} />*/}
</SafeAreaView>
// </AuthProvider>
)
}
const styles = StyleSheet.create({
main: {
flex: 1,
marginRight: 32,
marginBottom: 44,
justifyContent: 'space-between'
}
})