-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Users may delete cards by accessing a deck and its cards list.
- Loading branch information
1 parent
1573795
commit 6cc28ef
Showing
7 changed files
with
185 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import React, { Component } from 'react'; | ||
import { connect } from 'react-redux'; | ||
import { ScrollView, StyleSheet, Text, View, TouchableOpacity, Alert } from 'react-native'; | ||
import CardItem from '../ui/CardItem'; | ||
import Entypo from '@expo/vector-icons/Entypo'; | ||
|
||
class CardList extends Component { | ||
|
||
render() { | ||
const { cards } = this.props; | ||
const { deckKey, refresher } = this.props.navigation.state.params; | ||
|
||
if (cards.length === 0) { | ||
|
||
return ( | ||
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}> | ||
<Entypo size={75} name="emoji-sad" /> | ||
<Text>You have no cards for this deck.</Text> | ||
</View> | ||
); | ||
} else { | ||
|
||
return ( | ||
<ScrollView style={styles.container}> | ||
{cards.map(card => ( | ||
<CardItem key={card.question} card={card} deck={deckKey} refresher={refresher} /> | ||
))} | ||
|
||
</ScrollView> | ||
); | ||
} | ||
} | ||
|
||
} | ||
|
||
const styles = StyleSheet.create({ | ||
container: { | ||
flex: 1 | ||
} | ||
}); | ||
|
||
function mapStateToProps({ decks }, props) { | ||
const { deckKey } = props.navigation.state.params; | ||
const cards = decks[deckKey].cards; | ||
|
||
return { | ||
cards | ||
} | ||
} | ||
|
||
export default connect(mapStateToProps)(CardList); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
import React, { Component } from 'react'; | ||
import { View, TouchableOpacity, StyleSheet, Text, Alert } from 'react-native'; | ||
import { connect } from 'react-redux'; | ||
|
||
import { MaterialCommunityIcons } from '@expo/vector-icons'; | ||
|
||
import { deleteCardFromDeck } from '../../services'; | ||
import { deleteCard } from '../../actions'; | ||
import { COLOR_B_1, COLOR_WHITE, COLOR_FAILURE } from '../../utils/colors'; | ||
|
||
class CardItem extends Component { | ||
|
||
async deleteCard(cardName) { | ||
const { deck, refresher } = this.props; | ||
|
||
Alert.alert( | ||
'Delete card?', | ||
`Do you confirm the deletion of the card '${cardName}'?`, | ||
[ | ||
{ | ||
text: 'Yes', onPress: async () => { | ||
try { | ||
await deleteCardFromDeck(deck, cardName); | ||
this.props.dispatch(deleteCard(deck, cardName)); | ||
refresher(); | ||
} catch (e) { | ||
Alert.alert( | ||
'Error', | ||
'Error deleting card.', | ||
[ | ||
{ text: 'Ok', onPress: () => { } } | ||
]); | ||
console.error(e); | ||
} | ||
} | ||
}, | ||
{ text: 'No', onPress: () => { } } | ||
] | ||
); | ||
} | ||
|
||
render() { | ||
const { card } = this.props; | ||
|
||
return ( | ||
<View style={{ flex: 1, flexDirection: 'row' }}> | ||
<View style={styles.mainContainer}> | ||
<View style={styles.cardContainer}> | ||
<Text style={styles.question}>{card.question}</Text> | ||
<Text style={styles.answer}>{card.answer}</Text> | ||
</View> | ||
</View> | ||
<View style={styles.deleteContainer}> | ||
<TouchableOpacity style={styles.deleteBtn} onPress={this.deleteCard.bind(this, card.question)}> | ||
<MaterialCommunityIcons name="delete" size={40} color={COLOR_WHITE} /> | ||
</TouchableOpacity> | ||
</View> | ||
</View> | ||
); | ||
} | ||
} | ||
|
||
const styles = StyleSheet.create({ | ||
mainContainer: { | ||
flex: 8, | ||
flexDirection: 'row', | ||
alignItems: 'center', | ||
padding: 5, | ||
borderBottomWidth: 1, | ||
borderBottomColor: COLOR_B_1 | ||
}, | ||
cardContainer: { | ||
flex: 1 | ||
}, | ||
question: { | ||
fontSize: 20, | ||
fontWeight: 'bold' | ||
}, | ||
answer: { | ||
fontSize: 15, | ||
color: 'gray', | ||
fontStyle: 'italic', | ||
flexWrap: 'wrap' | ||
}, | ||
deleteContainer: { | ||
flex: 2, | ||
alignItems: 'center', | ||
justifyContent: 'center', | ||
backgroundColor: COLOR_FAILURE | ||
}, | ||
deleteBtn: { | ||
flex: 1, | ||
alignItems: 'center', | ||
justifyContent: 'center' | ||
} | ||
}); | ||
|
||
export default connect()(CardItem); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters