-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.js
82 lines (76 loc) · 2.09 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
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
import React, { Component } from 'react';
import { StyleSheet, ScrollView, Button, View } from 'react-native';
import AddIdea from './components/AddIdea';
import ListIdeas from './components/ListIdeas';
import { api } from './components/api';
const ADD_IDEAS = 'add-ideas';
const LIST_ACTIVE_IDEAS = 'list-active-ideas';
const LIST_ARCHIVED_IDEAS = 'list-archived-ideas';
export default class App extends Component {
constructor(props) {
super(props);
this.state = {
currentPage: LIST_ACTIVE_IDEAS,
ideas: [],
};
}
changePage(page) {
this.setState({ currentPage: page });
}
async fetchIdeas(status = 'active') {
const query = { status };
const options = { query };
try {
const { ideas } = await api.listIdeas(options);
this.setState({ ideas });
} catch (e) {
alert(e);
}
}
render() {
let Page;
switch (this.state.currentPage) {
case ADD_IDEAS:
Page = AddIdea;
break;
case LIST_ACTIVE_IDEAS:
default:
Page = ListIdeas;
break;
}
return (
<ScrollView style={styles.container}>
<View style={styles.nav}>
<Button color="#920089"
title="List Active Ideas"
onPress={async () => {
await this.fetchIdeas('active');
this.changePage(LIST_ACTIVE_IDEAS)
}}/>
<Button color="teal"
title="List Archived Ideas"
onPress={async () => {
await this.fetchIdeas('archived');
this.changePage(LIST_ARCHIVED_IDEAS);
}}/>
<Button color="#0092fe"
title="Add Idea"
onPress={() => this.changePage(ADD_IDEAS)}/>
</View>
<Page fetchIdeas={this.fetchIdeas.bind(this)}
ideas={this.state.ideas}/>
</ScrollView>
);
}
}
const styles = StyleSheet.create({
container: {
marginTop: 100,
display: 'flex',
flexDirection: 'column',
},
nav: {
display: 'flex',
flexDirection: 'row',
},
});