-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSetscreen.js
More file actions
91 lines (84 loc) · 2.17 KB
/
Setscreen.js
File metadata and controls
91 lines (84 loc) · 2.17 KB
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
import React from 'react';
import { StyleSheet, Text, View, FlatList, ScrollView, Alert } from 'react-native';
export default class Setscreen extends React.Component {
constructor(props) {
super(props)
this.state = { cards: [] }
}
static navigationOptions = {
title: 'Home'
};
render() {
// let cardsData = cards.map(
// (card) => ({key: card })
// );
const { navigate } = this.props.navigation;
const { set } = this.props.navigation.state.params;
if (this.state.cards.length === 0) {
fetch(`https://api.magicthegathering.io/v1/cards?set=${set.code}`)
.then((response) => response.json())
.then(
(responseJson) => {
results = responseJson
cards = results.cards.map(
(card) => {
return {
name: card.name,
cmc: card.cmc,
colors: card.colors,
type: card.type,
rarity: card.rarity,
text: card.text,
number: card.number,
imageUrl: card.imageUrl
};
}
)
}
).then(
() => this.setState({ cards: cards })
)
}
if (this.state.cards === 0) {
return <Text>Loading...</Text>
}
return (
<View style={styles.container}>
<Text style={[styles.header, styles.bold]}>Welcome to {set.name}</Text>
<ScrollView style={styles.list}>
{this.state.cards.map(
(card) => <Text
key={card.name + card.number}
style={styles.listItem}
onPress={() => navigate('Card', { card: card })}
>{`${card.number}: ${card.name}`}</Text>
)}
</ScrollView>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
padding: 10
},
header: {
fontSize: 24,
marginBottom: 25,
width: 300
},
list: {
width: 300
},
listItem: {
fontSize: 18,
marginBottom: 5
},
bold: {
fontWeight: 'bold'
}
});