Skip to content

Commit 7efa4dd

Browse files
committed
Add deck list and new deck components
1 parent 8153716 commit 7efa4dd

File tree

6 files changed

+183
-8
lines changed

6 files changed

+183
-8
lines changed

App.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React from 'react';
22
import { StyleSheet, Text, View } from 'react-native';
3+
import { TabNavigator } from 'react-navigation';
34

45
export default class App extends React.Component {
56
render() {

components/AddDeck.js

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import React from 'react';
2+
import { View, Text, StyleSheet, TextInput, KeyboardAvoidingView, TouchableOpacity } from 'react-native';
3+
import { white, gray, black } from '../utils/colors';
4+
import { saveDeckTitle } from '../api';
5+
6+
export default class AddDeck extends React.Component {
7+
constructor(props) {
8+
super(props);
9+
this.state = { title: '' };
10+
}
11+
12+
onSubmit = () => {
13+
saveDeckTitle(this.state.title);
14+
this.props.navigation.navigate('DeckList');
15+
};
16+
17+
render() {
18+
return (
19+
<View style={styles.container}>
20+
<Text style={styles.heading}>What is the title of your new deck?</Text>
21+
<TextInput
22+
style={styles.input}
23+
placeholder="Deck Title"
24+
onChangeText={text => {
25+
this.setState({ title: text });
26+
}}
27+
spellCheck={false}
28+
underlineColorAndroid={black}
29+
/>
30+
<TouchableOpacity onPress={this.onSubmit}>
31+
<Text style={styles.submitBtn}>Submit</Text>
32+
</TouchableOpacity>
33+
<KeyboardAvoidingView behavior="padding" keyboardVerticalOffset={100} />
34+
</View>
35+
);
36+
}
37+
}
38+
39+
const styles = StyleSheet.create({
40+
container: {
41+
flex: 1,
42+
justifyContent: 'center',
43+
alignItem: 'center'
44+
},
45+
heading: {
46+
fontSize: 22,
47+
fontWeight: 'bold'
48+
},
49+
submitBtn: {
50+
backgroundColor: black,
51+
color: white,
52+
fontWeight: 'bold'
53+
},
54+
input: {
55+
paddingTop: 10,
56+
paddingRight: 10,
57+
paddingBottom: 10,
58+
paddingLeft: 0,
59+
backgroundColor: white,
60+
color: black
61+
}
62+
});

components/DecksList.js

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import React from 'react';
2+
import { View, Text, StyleSheet, FlatList } from 'react-native';
3+
import { gray, black } from '../utils/colors';
4+
import { getAllDecks } from '../api';
5+
6+
export default class DeckList extends React.Component {
7+
constructor(props) {
8+
super(props);
9+
this.state = { decks: [] };
10+
}
11+
12+
componentDidMount() {
13+
getAllDecks().then(data => this.setState({ decks: Object.values(data) }));
14+
}
15+
16+
render() {
17+
return (
18+
<FlatList
19+
style={styles.container}
20+
data={this.state.decks}
21+
renderItem={({ item }) => <Deck key={item.title} {...item} />}
22+
/>
23+
);
24+
}
25+
}
26+
27+
const Deck = props => (
28+
<View style={styles.deck}>
29+
<Text style={styles.deckTitle}>{props.title}</Text>
30+
<Text style={styles.deckCards}>{props.questions.length} Cards</Text>
31+
</View>
32+
);
33+
34+
const styles = StyleSheet.create({
35+
container: {
36+
flex: 1
37+
},
38+
deck: {
39+
height: 100,
40+
justifyContent: 'center',
41+
alignItems: 'center',
42+
borderBottomWidth: 2,
43+
borderBottomColor: black
44+
},
45+
deckTitle: {
46+
fontSize: 20
47+
},
48+
deckCards: {
49+
fontSize: 16,
50+
color: gray
51+
}
52+
});

package.json

+4-3
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
"version": "0.1.0",
44
"private": true,
55
"devDependencies": {
6-
"react-native-scripts": "1.7.0",
76
"jest-expo": "^22.0.0",
7+
"react-native-scripts": "1.7.0",
88
"react-test-renderer": "16.0.0-beta.5"
99
},
1010
"main": "./node_modules/react-native-scripts/build/bin/crna-entry.js",
@@ -21,6 +21,7 @@
2121
"dependencies": {
2222
"expo": "^22.0.2",
2323
"react": "16.0.0-beta.5",
24-
"react-native": "^0.49.5"
24+
"react-native": "^0.49.5",
25+
"react-navigation": "^1.0.0-beta.19"
2526
}
26-
}
27+
}

utils/colors.js

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export const black = '#212121';
2+
export const gray = '#63656A';
3+
export const red = '#C43929';
4+
export const white = '#ffffff';

yarn.lock

+60-5
Original file line numberDiff line numberDiff line change
@@ -613,6 +613,13 @@ babel-plugin-transform-decorators-legacy@^1.3.4:
613613
babel-runtime "^6.2.0"
614614
babel-template "^6.3.0"
615615

616+
babel-plugin-transform-define@^1.3.0:
617+
version "1.3.0"
618+
resolved "https://registry.yarnpkg.com/babel-plugin-transform-define/-/babel-plugin-transform-define-1.3.0.tgz#94c5f9459c810c738cc7c50cbd44a31829d6f319"
619+
dependencies:
620+
lodash "4.17.4"
621+
traverse "0.6.6"
622+
616623
babel-plugin-transform-es2015-arrow-functions@^6.5.0, babel-plugin-transform-es2015-arrow-functions@^6.8.0:
617624
version "6.22.0"
618625
resolved "https://registry.yarnpkg.com/babel-plugin-transform-es2015-arrow-functions/-/babel-plugin-transform-es2015-arrow-functions-6.22.0.tgz#452692cb711d5f79dc7f85e440ce41b9f244d221"
@@ -1269,6 +1276,10 @@ ci-info@^1.0.0:
12691276
version "1.1.1"
12701277
resolved "https://registry.yarnpkg.com/ci-info/-/ci-info-1.1.1.tgz#47b44df118c48d2597b56d342e7e25791060171a"
12711278

1279+
clamp@^1.0.1:
1280+
version "1.0.1"
1281+
resolved "https://registry.yarnpkg.com/clamp/-/clamp-1.0.1.tgz#66a0e64011816e37196828fdc8c8c147312c8634"
1282+
12721283
cli-cursor@^2.1.0:
12731284
version "2.1.0"
12741285
resolved "https://registry.yarnpkg.com/cli-cursor/-/cli-cursor-2.1.0.tgz#b35dac376479facc3e94747d41d0d0f5238ffcb5"
@@ -2496,7 +2507,7 @@ [email protected]:
24962507
version "4.2.0"
24972508
resolved "https://registry.yarnpkg.com/hoek/-/hoek-4.2.0.tgz#72d9d0754f7fe25ca2d01ad8f8f9a9449a89526d"
24982509

2499-
hoist-non-react-statics@^2.2.1:
2510+
hoist-non-react-statics@^2.2.0, hoist-non-react-statics@^2.2.1:
25002511
version "2.3.1"
25012512
resolved "https://registry.yarnpkg.com/hoist-non-react-statics/-/hoist-non-react-statics-2.3.1.tgz#343db84c6018c650778898240135a1420ee22ce0"
25022513

@@ -3472,14 +3483,14 @@ lodash.zipobject@^4.1.3:
34723483
version "4.1.3"
34733484
resolved "https://registry.yarnpkg.com/lodash.zipobject/-/lodash.zipobject-4.1.3.tgz#b399f5aba8ff62a746f6979bf20b214f964dbef8"
34743485

3486+
[email protected], lodash@^4.0.0, lodash@^4.14.0, lodash@^4.14.1, lodash@^4.16.6, lodash@^4.17.4, lodash@^4.2.0, lodash@^4.2.1, lodash@^4.3.0, lodash@^4.6.1:
3487+
version "4.17.4"
3488+
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.4.tgz#78203a4d1c328ae1d86dca6460e369b57f4055ae"
3489+
34753490
lodash@^3.5.0:
34763491
version "3.10.1"
34773492
resolved "https://registry.yarnpkg.com/lodash/-/lodash-3.10.1.tgz#5bf45e8e49ba4189e17d482789dfd15bd140b7b6"
34783493

3479-
lodash@^4.0.0, lodash@^4.14.0, lodash@^4.14.1, lodash@^4.16.6, lodash@^4.17.4, lodash@^4.2.0, lodash@^4.2.1, lodash@^4.3.0, lodash@^4.6.1:
3480-
version "4.17.4"
3481-
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.4.tgz#78203a4d1c328ae1d86dca6460e369b57f4055ae"
3482-
34833494
lodash@~4.5.1:
34843495
version "4.5.1"
34853496
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.5.1.tgz#80e8a074ca5f3893a6b1c10b2a636492d710c316"
@@ -4180,6 +4191,12 @@ [email protected]:
41804191
version "0.1.7"
41814192
resolved "https://registry.yarnpkg.com/path-to-regexp/-/path-to-regexp-0.1.7.tgz#df604178005f522f15eb4490e7247a1bfaa67f8c"
41824193

4194+
path-to-regexp@^1.7.0:
4195+
version "1.7.0"
4196+
resolved "https://registry.yarnpkg.com/path-to-regexp/-/path-to-regexp-1.7.0.tgz#59fde0f435badacba103a84e9d3bc64e96b9937d"
4197+
dependencies:
4198+
isarray "0.0.1"
4199+
41834200
path-type@^1.0.0:
41844201
version "1.1.0"
41854202
resolved "https://registry.yarnpkg.com/path-type/-/path-type-1.1.0.tgz#59c44f7ee491da704da415da5a4070ba4f8fe441"
@@ -4455,6 +4472,22 @@ [email protected]:
44554472
version "2.0.0-beta.3"
44564473
resolved "https://registry.yarnpkg.com/react-native-branch/-/react-native-branch-2.0.0-beta.3.tgz#2167af86bbc9f964bd45bd5f37684e5b54965e32"
44574474

4475+
4476+
version "1.0.0"
4477+
resolved "https://registry.yarnpkg.com/react-native-dismiss-keyboard/-/react-native-dismiss-keyboard-1.0.0.tgz#32886242b3f2317e121f3aeb9b0a585e2b879b49"
4478+
4479+
react-native-drawer-layout-polyfill@^1.3.2:
4480+
version "1.3.2"
4481+
resolved "https://registry.yarnpkg.com/react-native-drawer-layout-polyfill/-/react-native-drawer-layout-polyfill-1.3.2.tgz#192c84d7a5a6b8a6d2be2c7daa5e4164518d0cc7"
4482+
dependencies:
4483+
react-native-drawer-layout "1.3.2"
4484+
4485+
4486+
version "1.3.2"
4487+
resolved "https://registry.yarnpkg.com/react-native-drawer-layout/-/react-native-drawer-layout-1.3.2.tgz#b9740d7663a1dc4f88a61b9c6d93d2d948ea426e"
4488+
dependencies:
4489+
react-native-dismiss-keyboard "1.0.0"
4490+
44584491
44594492
version "1.0.0-alpha.28"
44604493
resolved "https://registry.yarnpkg.com/react-native-gesture-handler/-/react-native-gesture-handler-1.0.0-alpha.28.tgz#198c776b7b7d299f9b03017f666a9829f996e30d"
@@ -4498,6 +4531,12 @@ [email protected]:
44984531
color "^0.11.1"
44994532
lodash "^4.16.6"
45004533

4534+
react-native-tab-view@^0.0.70:
4535+
version "0.0.70"
4536+
resolved "https://registry.yarnpkg.com/react-native-tab-view/-/react-native-tab-view-0.0.70.tgz#1dd2ded32acd0cb6bfef38d26e53675db733b37b"
4537+
dependencies:
4538+
prop-types "^15.5.10"
4539+
45014540
45024541
version "4.4.2"
45034542
resolved "https://registry.yarnpkg.com/react-native-vector-icons/-/react-native-vector-icons-4.4.2.tgz#090f42ee0396c4cc4eae0ddaa518028ba8df40c7"
@@ -4562,6 +4601,18 @@ react-native@^0.49.5:
45624601
xmldoc "^0.4.0"
45634602
yargs "^6.4.0"
45644603

4604+
react-navigation@^1.0.0-beta.19:
4605+
version "1.0.0-beta.19"
4606+
resolved "https://registry.yarnpkg.com/react-navigation/-/react-navigation-1.0.0-beta.19.tgz#96e159c4b6760f51fc92d5c1c3690790cff4dbcf"
4607+
dependencies:
4608+
babel-plugin-transform-define "^1.3.0"
4609+
clamp "^1.0.1"
4610+
hoist-non-react-statics "^2.2.0"
4611+
path-to-regexp "^1.7.0"
4612+
prop-types "^15.5.10"
4613+
react-native-drawer-layout-polyfill "^1.3.2"
4614+
react-native-tab-view "^0.0.70"
4615+
45654616
react-proxy@^1.1.7:
45664617
version "1.1.8"
45674618
resolved "https://registry.yarnpkg.com/react-proxy/-/react-proxy-1.1.8.tgz#9dbfd9d927528c3aa9f444e4558c37830ab8c26a"
@@ -5504,6 +5555,10 @@ tr46@~0.0.3:
55045555
version "0.0.3"
55055556
resolved "https://registry.yarnpkg.com/tr46/-/tr46-0.0.3.tgz#8184fd347dac9cdc185992f3a6622e14b9d9ab6a"
55065557

5558+
5559+
version "0.6.6"
5560+
resolved "https://registry.yarnpkg.com/traverse/-/traverse-0.6.6.tgz#cbdf560fd7b9af632502fed40f918c157ea97137"
5561+
55075562
tree-kill@^1.1.0:
55085563
version "1.2.0"
55095564
resolved "https://registry.yarnpkg.com/tree-kill/-/tree-kill-1.2.0.tgz#5846786237b4239014f05db156b643212d4c6f36"

0 commit comments

Comments
 (0)