-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNavigator.js
105 lines (94 loc) · 2.07 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
import React from "react";
import {
StyleSheet,
View,
Text,
TouchableHighlight,
ActivityIndicator,
Button
} from "react-native";
import { StackNavigator } from "react-navigation";
import { Fab, Icon } from "native-base";
import { graphql } from "react-apollo";
import gql from "graphql-tag";
import { withApollo } from 'react-apollo';
import Post from "./components/posts/Post";
import UpdatePost from "./components/posts/UpdatePost";
import NewPost from "./components/posts/NewPost";
import Posts from "./components/posts/Posts";
import navStyles from "./styles/navStyles";
import Login from "./components/user/Login";
import { signOut } from './loginUtils';
class Home extends React.Component {
static navigationOptions = {
title: "Home",
...navStyles
};
goToPost = () => {
this.props.navigation.navigate("Post");
};
newPost = () => {
this.props.navigation.navigate("NewPost");
};
render() {
return (
<View style={styles.container}>
<Posts {...this.props} />
<Button
onPress={() => {
signOut();
this.props.client.resetStore();
}}
title="Logout"
/>
<Fab style={styles.newPost} onPress={this.newPost}>
<Icon name="add" />
</Fab>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: "space-between"
},
newPost: {
backgroundColor: "#82D8D8"
}
});
const Navigator = StackNavigator({
Home: {
screen: withApollo(Home)
},
Post: {
screen: Post
},
NewPost: {
screen: NewPost
},
UpdatePost: {
screen: UpdatePost
}
});
const NavWrapper = ({ loading, user }) => {
console.log(user);
if (loading) return <ActivityIndicator size="large" />;
if (!user) return <Login />;
return <Navigator screenProps={{ user }} />;
};
const userQuery = gql`
query userQuery {
user {
id
email
posts(orderBy: createdAt_DESC) {
id
title
}
}
}
`;
export default graphql(userQuery, {
props: ({ data }) => ({ ...data })
})(NavWrapper);