-
Notifications
You must be signed in to change notification settings - Fork 0
/
Navigator.js
117 lines (107 loc) · 2.38 KB
/
Navigator.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
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
112
113
114
115
116
117
import React, { Component } from 'react';
import {
StyleSheet,
View,
Text,
ActivityIndicator,
Button,
} from 'react-native';
import { Fab, Icon } from 'native-base';
import { createStackNavigator, createAppContainer } from 'react-navigation';
import { useQuery } from '@apollo/react-hooks';
import { gql } from 'apollo-boost';
import { withApollo } from '@apollo/react-hoc';
import navStyles from './styles/navStyles';
import Posts from './components/posts/Posts';
import Post from './components/posts/Post';
import NewPost from './components/posts/NewPost';
import Login from './components/user/Login';
import { signOut } from './loginUtils';
import UpdatePost from './components/posts/UpdatePost';
const Home = ({ ...props }) => {
newPost = () => {
props.navigation.navigate('NewPost');
};
return (
<View style={styles.container}>
<Posts {...props} />
<Button
onPress={() => {
signOut();
props.client.resetStore();
}}
title="Logout"
/>
<Fab style={styles.newPost} onPress={newPost}>
<Icon name="add" />
</Fab>
</View>
);
};
Home.navigationOptions = {
title: 'Home',
...navStyles,
};
const Navigator = createStackNavigator(
{
Home: {
screen: withApollo(Home),
},
Post: {
screen: Post,
},
NewPost: {
screen: NewPost,
},
UpdatePost: {
screen: UpdatePost,
},
Login: {
screen: Login,
},
},
{
defaultNavigationOptions: {},
},
);
const AppContainer = createAppContainer(Navigator);
const NavWrapper = ({ ...props }) => {
const userQuery = gql`
query userQuery {
user {
id
email
posts(orderBy: createdAt_DESC) {
id
title
}
}
}
`;
const { loading, error, data } = useQuery(userQuery);
if (loading)
return (
<ActivityIndicator
size="large"
animating={loading}
style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}
/>
);
console.log(data.user);
if (!data.user) return <Login />;
return <AppContainer screenProps={{ user: data.user }} />;
};
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'space-between',
},
newPost: {
backgroundColor: '#82D8D8',
},
newPostText: {
fontSize: 20,
textAlign: 'center',
},
});
export default NavWrapper;