Skip to content

Commit

Permalink
feat: Implement support for decks and lists of decks
Browse files Browse the repository at this point in the history
  • Loading branch information
VibrantCarl committed May 26, 2020
1 parent c09b588 commit c74e1f5
Show file tree
Hide file tree
Showing 2 changed files with 116 additions and 0 deletions.
52 changes: 52 additions & 0 deletions components/atoms/Deck/Deck.js
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
}
});
64 changes: 64 additions & 0 deletions components/molecules/DeckList/DeckList.js
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);

0 comments on commit c74e1f5

Please sign in to comment.