Repository navigation
Expand file tree
/
Copy pathApp.js
More file actions
91 lines (79 loc) · 2.81 KB
/
Copy pathApp.js
File metadata and controls
91 lines (79 loc) · 2.81 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
import React, { useState, useEffect } from 'react'
import { StatusBar } from "react-native"
import AsyncStorage from '@react-native-async-storage/async-storage';
// components
import OpenDrawer from './components/drawer/open'
import ClosedDrawer from './components/drawer/closed'
// data load from file
import { TaskData } from "./components/data/data";
const animationSpeed = 500 // ms
const App = () => {
const [ data, setData ] = useState( null )
const [ show, setShow ] = useState( false )
const [ active, setActive ] = useState( 'TODO' )
// day/night toggle
const [ mode, setMode ] = React.useState( false );
const [ backgroundColor, setBackgroundColor ] = useState( '#fff' );
const [ foregroundColor, setForegroundColor ] = useState( '#333' );
StatusBar.setBarStyle( 'light-content' )
// this will only be called once when the app loads:
useEffect( () => {
const fetchData = async () => {
let tasks = await AsyncStorage.getItem( '@tasks' );
// if there's no tasks in storage, then pull from local examples
if ( !tasks || tasks === undefined ) {
await AsyncStorage.setItem(
'@tasks',
JSON.stringify( TaskData )
)
setData( TaskData );
}
// need to parse the string into a useable JSON object
else {
setData( JSON.parse( tasks ) );
}
}
fetchData();
}, [] )
// drawer open
if ( show ) {
return (
<OpenDrawer
TaskData={ data }
show={ show }
mode={ mode }
active={ active }
setMode={ setMode }
setTaskData={ setData }
setShow={ setShow }
setActive={ setActive }
setForegroundColor={ setForegroundColor }
setBackgroundColor={ setBackgroundColor }
animationSpeed={ animationSpeed }
foregroundColor={ foregroundColor }
backgroundColor={ backgroundColor }
/>
)
}
// drawer closed (viewing tasks)
else {
return (
<ClosedDrawer
TaskData={ data }
show={ show }
mode={ mode }
active={ active }
setMode={ setMode }
setTaskData={ setData }
setShow={ setShow }
setActive={ setActive }
setForegroundColor={ setForegroundColor }
setBackgroundColor={ setBackgroundColor }
animationSpeed={ animationSpeed }
foregroundColor={ foregroundColor }
backgroundColor={ backgroundColor }
/>
)
}
}
export default App