2020-03-16 16:01:05 +01:00
|
|
|
import React, { useState } from "react";
|
|
|
|
import PropTypes from "prop-types";
|
|
|
|
import {
|
2020-03-20 15:23:06 +01:00
|
|
|
IconButton,
|
2020-03-16 16:01:05 +01:00
|
|
|
Card,
|
|
|
|
FAB,
|
2020-03-19 19:43:34 +01:00
|
|
|
Portal,
|
2020-03-20 15:23:06 +01:00
|
|
|
Text,
|
|
|
|
withTheme
|
2020-03-16 16:01:05 +01:00
|
|
|
} from "react-native-paper";
|
|
|
|
|
|
|
|
import {
|
2020-03-19 19:43:34 +01:00
|
|
|
ScrollView,
|
2020-03-16 16:01:05 +01:00
|
|
|
StyleSheet
|
|
|
|
} from "react-native";
|
|
|
|
|
|
|
|
import InputDialog from "./InputDialog";
|
|
|
|
|
2020-03-20 15:23:06 +01:00
|
|
|
function Subjects({ theme, subjects, addSubject, removeSubject }) {
|
2020-03-16 16:01:05 +01:00
|
|
|
const [ showDialog, setShowDialog ] = useState(false);
|
|
|
|
function onInput(text) {
|
|
|
|
addSubject(text);
|
|
|
|
setShowDialog(false);
|
|
|
|
}
|
|
|
|
return (
|
2020-03-25 23:35:50 +01:00
|
|
|
<Portal.Host><ScrollView style={{ backgroundColor: theme.colors.background }}>
|
2020-03-16 16:13:14 +01:00
|
|
|
{subjects.length === 0 ?
|
2020-03-19 19:43:34 +01:00
|
|
|
<Text style={style.text}>
|
|
|
|
No Subjects added. Press + to add a subject.
|
|
|
|
</Text>
|
2020-03-16 16:13:14 +01:00
|
|
|
: null
|
|
|
|
}
|
2020-03-19 19:43:34 +01:00
|
|
|
{subjects.map((subject, idx) => (
|
|
|
|
<Card
|
|
|
|
key={subject.id}
|
|
|
|
style={
|
|
|
|
[
|
|
|
|
style.card,
|
2020-03-21 09:04:18 +01:00
|
|
|
{marginBottom: idx === subjects.length - 1 ? 80 : 0 }
|
2020-03-19 19:43:34 +01:00
|
|
|
]
|
|
|
|
}
|
|
|
|
>
|
2020-03-16 16:01:05 +01:00
|
|
|
<Card.Title title={subject.name} />
|
2020-03-20 15:23:06 +01:00
|
|
|
<Card.Actions style={{justifyContent: "flex-end"}}>
|
|
|
|
<IconButton
|
|
|
|
onPress={() => removeSubject(subject.id)}
|
|
|
|
icon="delete"
|
|
|
|
color={theme.colors.primary}
|
|
|
|
/>
|
2020-03-16 16:01:05 +01:00
|
|
|
</Card.Actions>
|
|
|
|
</Card>
|
|
|
|
))}
|
|
|
|
<InputDialog
|
|
|
|
visible={showDialog}
|
|
|
|
onDismiss={() => setShowDialog(false)}
|
|
|
|
title="Enter Name of New Subject"
|
|
|
|
placeholder="Subject Name"
|
|
|
|
label="Subject Name"
|
|
|
|
onOK={onInput}
|
|
|
|
/>
|
2020-03-19 19:43:34 +01:00
|
|
|
<Portal>
|
|
|
|
<FAB
|
|
|
|
large
|
|
|
|
icon="plus"
|
|
|
|
onPress={() => setShowDialog(true)}
|
|
|
|
style={{
|
|
|
|
position: "absolute",
|
|
|
|
margin: 16,
|
|
|
|
right: 0,
|
|
|
|
bottom: 0,
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
</Portal>
|
|
|
|
</ScrollView></Portal.Host>
|
2020-03-16 16:01:05 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
Subjects.propTypes = {
|
|
|
|
subjects: PropTypes.array,
|
|
|
|
addSubject: PropTypes.func,
|
|
|
|
removeSubject: PropTypes.func,
|
2020-03-20 15:23:06 +01:00
|
|
|
theme: PropTypes.object,
|
2020-03-16 16:01:05 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
const style = StyleSheet.create({
|
|
|
|
card: {
|
|
|
|
marginTop: 12,
|
2020-03-17 14:55:03 +01:00
|
|
|
marginLeft: 10,
|
|
|
|
marginRight: 10,
|
2020-03-16 16:13:14 +01:00
|
|
|
},
|
|
|
|
text: {
|
|
|
|
marginTop: 12,
|
|
|
|
textAlign: "center",
|
2020-03-16 16:01:05 +01:00
|
|
|
}
|
|
|
|
});
|
2020-03-20 15:23:06 +01:00
|
|
|
|
|
|
|
export default withTheme(Subjects);
|