-
-
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.
feat: Implement support for decks and lists of decks
- Loading branch information
1 parent
c09b588
commit c74e1f5
Showing
2 changed files
with
116 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { Ionicons } from "@expo/vector-icons"; | ||
import { LinearGradient } from "expo-linear-gradient"; | ||
import React from "react"; | ||
import { StyleSheet, Text, TouchableHighlight, View } from "react-native"; | ||
|
||
import { colorPrimary, white } from "../../../utils/colors"; | ||
|
||
export default function Deck({ deck, onPress }) { | ||
const { title, questions } = deck; | ||
const count = questions.length; | ||
|
||
return ( | ||
<View style={styles.card}> | ||
<TouchableHighlight onPress={onPress}> | ||
<LinearGradient | ||
colors={["#24a0ed", colorPrimary]} | ||
style={{ | ||
padding: 15, | ||
justifyContent: "center", | ||
borderRadius: 7, | ||
height: "100%" | ||
}} | ||
> | ||
<Text style={styles.title}>{title}</Text> | ||
|
||
<Text style={{ color: white, fontSize: 16 }}> | ||
{count} {count === 0 || count > 1 ? "flashcards" : "flashcard"} | ||
</Text> | ||
<Ionicons name="md-albums" size={30} color="white" /> | ||
</LinearGradient> | ||
</TouchableHighlight> | ||
</View> | ||
); | ||
} | ||
|
||
const styles = StyleSheet.create({ | ||
card: { | ||
borderColor: white, | ||
borderWidth: 1, | ||
borderRadius: 4, | ||
marginBottom: 20, | ||
shadowColor: "0 4px 8px 0 rgba(0,0,0,0.2)", | ||
minHeight: 100, | ||
flex: 1 | ||
}, | ||
title: { | ||
fontSize: 24, | ||
color: white, | ||
fontWeight: "700", | ||
marginBottom: 10 | ||
} | ||
}); |
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,64 @@ | ||
import React, { Component } from "react"; | ||
import { FlatList, SafeAreaView, StyleSheet, View } from "react-native"; | ||
import { connect } from "react-redux"; | ||
|
||
import { receiveDeckEntries } from "../../../actions"; | ||
import { fetchDeckResults, scheduleNotification } from "../../../utils/API"; | ||
import Deck from "../../atoms/Deck/Deck"; | ||
import { white } from "../../../utils/colors"; | ||
|
||
class DeckList extends Component { | ||
componentDidMount() { | ||
scheduleNotification(); | ||
|
||
const { dispatch } = this.props; | ||
|
||
fetchDeckResults().then(data => { | ||
dispatch(receiveDeckEntries(data)); | ||
}); | ||
} | ||
|
||
openDeck = (id, deck) => { | ||
this.props.navigation.navigate("ViewDeck", { | ||
deckId: id, | ||
deck | ||
}); | ||
}; | ||
|
||
render() { | ||
const { decks, data } = this.props; | ||
return ( | ||
<View style={styles.container}> | ||
<SafeAreaView> | ||
<FlatList | ||
data={decks} | ||
renderItem={({ item }) => { | ||
const deck = data[item]; | ||
return ( | ||
<Deck deck={deck} onPress={() => this.openDeck(item, deck)} /> | ||
); | ||
}} | ||
keyExtractor={item => item} | ||
/> | ||
</SafeAreaView> | ||
</View> | ||
); | ||
} | ||
} | ||
|
||
const styles = StyleSheet.create({ | ||
container: { | ||
flex: 1, | ||
backgroundColor: white, | ||
padding: 10 | ||
} | ||
}); | ||
|
||
function mapStateToProps(state) { | ||
return { | ||
data: state, | ||
decks: Object.keys(state).reverse() | ||
}; | ||
} | ||
|
||
export default connect(mapStateToProps)(DeckList); |