-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
97 lines (94 loc) · 2.26 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import React from 'react';
import { Text, View } from 'react-native';
import { StackNavigator } from 'react-navigation'
import AddCard from './components/AddCard'
import Quiz from './components/Quiz'
import Score from './components/Score'
import Tabs from './components/Tabs'
import DeckItemDetails from './components/DeckItemDetails'
import FlashCardsStatusBar from './components/StatusBar'
import { getDecks, saveDeckTitle, addCardToDeck, removeDeck } from './utils/api'
import { objectToArray, setLocalNotification, resetToDeck } from './utils/helpers'
import { white, gray } from './utils/colors'
mainNavOpts = {
headerMode: 'float',
navigationOptions: {
headerTintColor: white,
headerStyle: {
backgroundColor: gray,
}
}
}
MainNav = StackNavigator({
Home: {
screen: Tabs,
},
DeckItemDetails: {
screen: DeckItemDetails,
navigationOptions: {
title: 'Deck',
},
},
AddCard: {
screen: AddCard,
navigationOptions: {
title: 'Add Card',
},
},
Quiz: {
screen: Quiz,
navigationOptions: {
title: 'Quiz',
},
},
Score: {
screen: Score,
navigationOptions: {
header: null,
// title: 'Score',
},
},
},mainNavOpts)
export default class App extends React.Component {
state = {
decks: []
}
getDecksAndSetState = () => {
return getDecks()
.then((decks)=> this.setState({decks: objectToArray(decks)}))
}
componentDidMount() {
setLocalNotification()
this.getDecksAndSetState()
}
submitCard = (deck, card, navigation) => {
return addCardToDeck(deck.title, card)
.then(()=> navigation.dispatch(resetToDeck(deck)) )
.then(this.getDecksAndSetState)
}
submitDeck = (deckTitle) => {
return saveDeckTitle(deckTitle)
.then(this.getDecksAndSetState)
}
removeDeck = (deckTitle) => {
return removeDeck(deckTitle)
.then(this.getDecksAndSetState)
}
render() {
const { decks } = this.state
screenProps = {
decks,
submitDeck: this.submitDeck,
submitCard: this.submitCard,
removeDeck: this.removeDeck,
}
return (
<View style={{flex:1, justifyContent:'center'}}>
<FlashCardsStatusBar />
<MainNav
screenProps={screenProps}
/>
</View>
)
}
}