-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.js
54 lines (50 loc) · 1.64 KB
/
App.js
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
import React, {useState, useEffect} from 'react';
import {StyleSheet, View, StatusBar, Text} from 'react-native';
import Room from './components/panels/Room.js'
import Settings from './components/panels/Settings.js';
import PageHeader from './components/PageHeader.js'
import { colors } from './components/styles/globalStyles'
import { getRooms, setRooms } from './storage/settings';
import { SafeAreaProvider } from 'react-native-safe-area-context';
export default function App() {
let [roomId, setRoomId] = useState(0);
let [rooms, setRooms] = useState([]);
let [panel, setPanel] = useState('room');
useEffect(() => {
getRooms().then(rooms => setRooms(rooms))
}, []);
useEffect(() => {
console.log('rooms changed')
setPanel('room');
}, [rooms]);
return (
<SafeAreaProvider>
{/* <StatusBar backgroundColor={colors.secondary} barStyle="light-content" /> */}
<PageHeader panel={panel} rooms={rooms} panelCBFN={val=> setPanel(val)} changeValueCBFN={val => {setRoomId(val)}}/>
{giveBody(panel, rooms, roomId, (rooms) => setRooms(rooms), (panel) => setPanel(panel))}
</SafeAreaProvider>
);
}
function giveBody(panel, rooms, roomId, roomsChangeCBFN, panelChangeCBFN)
{
function saveRooms(rooms)
{
if (rooms)
setRooms(rooms).then(() => roomsChangeCBFN(rooms))
else
panelChangeCBFN('room')
}
if (rooms.length > 0 && panel === 'room')
{
return <Room style={{flex: 1}} room={rooms[roomId]}/>
}
else if (panel === 'settings')
return <Settings rooms={rooms} doneCBFN={saveRooms}/>
else
return null
}
const styles = StyleSheet.create({
rooms: {
backgroundColor: '#F5FCFF',
},
});