Skip to content

Commit

Permalink
FIX: Empty deck quiz
Browse files Browse the repository at this point in the history
Empty decks throws alert when trying to start quiz.
  • Loading branch information
diogosilverio committed Feb 4, 2018
1 parent c326945 commit cafe938
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion components/flashcards/DeckDetails.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,22 @@ class DeckDetails extends Component {
return true;
}

startQuiz(deckKey) {
const { deck, navigation } = this.props;

if (deck.cards.length === 0) {
Alert.alert(
'Empty Deck',
'This deck has no cards. Add some to start playing!',
[
{ text: 'Ok', onPress: () => { } }
]
)
} else {
navigation.navigate('Quiz', { deckKey: deck.name })
}
}

render() {
const { deck } = this.props;
if (typeof deck === 'undefined') {
Expand Down Expand Up @@ -97,7 +113,7 @@ class DeckDetails extends Component {
</TouchableOpacity>
</View>
<View style={styles.subSubContainerBtn}>
<TouchableOpacity style={styles.btn} onPress={() => this.props.navigation.navigate('Quiz', { deckKey: deck.name })}>
<TouchableOpacity style={styles.btn} onPress={() => this.startQuiz(deck.name)}>
<Text style={styles.btnText}>Start Quiz</Text>
</TouchableOpacity>
</View>
Expand Down

0 comments on commit cafe938

Please sign in to comment.