2020-03-24 19:17:54 +01:00
|
|
|
import React, { useState } from "react";
|
2020-03-20 15:35:50 +01:00
|
|
|
import PropTypes from "prop-types";
|
|
|
|
|
|
|
|
import {
|
2020-03-24 19:17:54 +01:00
|
|
|
Button,
|
2020-03-20 15:35:50 +01:00
|
|
|
Card,
|
2020-03-24 19:17:54 +01:00
|
|
|
DataTable,
|
|
|
|
Dialog,
|
2020-04-09 18:35:23 +02:00
|
|
|
FAB,
|
2020-03-24 19:17:54 +01:00
|
|
|
Portal,
|
2020-04-14 18:00:53 +02:00
|
|
|
Modal,
|
2020-03-20 15:35:50 +01:00
|
|
|
} from "react-native-paper";
|
|
|
|
|
|
|
|
import {
|
2020-03-21 09:04:18 +01:00
|
|
|
StyleSheet,
|
|
|
|
ScrollView
|
2020-03-20 15:35:50 +01:00
|
|
|
} from "react-native";
|
2020-03-21 10:17:10 +01:00
|
|
|
import { format } from "date-fns";
|
2020-03-20 15:35:50 +01:00
|
|
|
|
2020-04-14 18:00:53 +02:00
|
|
|
import BottomSheet from "reanimated-bottom-sheet";
|
|
|
|
|
2020-03-22 11:49:16 +01:00
|
|
|
function sortTimes(t1, t2) {
|
|
|
|
if (t1.getHours() > t2.getHours())
|
|
|
|
return 1;
|
|
|
|
if (t1.getHours() < t2.getHours())
|
|
|
|
return -1;
|
2020-04-09 18:35:23 +02:00
|
|
|
if (t1.getMinutes() > t2.getMinutes())
|
2020-03-22 11:49:16 +01:00
|
|
|
return 1;
|
2020-04-09 18:35:23 +02:00
|
|
|
if (t1.getMinutes() < t2.getMinutes())
|
2020-03-22 11:49:16 +01:00
|
|
|
return -1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-04-09 18:35:23 +02:00
|
|
|
function HomeScreen({ days, navigation, removeTimetableEntry, subjects, timetable }) {
|
2020-03-24 19:17:54 +01:00
|
|
|
const [ dialog, setDialog ] = useState({ show: false, id: null });
|
2020-04-14 18:00:53 +02:00
|
|
|
const [ currentBottomSheet, setCurrentBottomSheet ] = useState(null);
|
|
|
|
|
|
|
|
this.bs = React.createRef();
|
|
|
|
const openBottomSheet = () => {this.bs.current.snapTo(0);this.bs.current.snapTo(0);};
|
|
|
|
const closeBottomSheet = () => {this.bs.current.snapTo(2);this.bs.current.snapTo(2);};
|
|
|
|
|
|
|
|
function CardContents() {
|
|
|
|
if (!currentBottomSheet) {
|
|
|
|
return <></>;
|
|
|
|
}
|
|
|
|
const subject = subjects.find(i => i.id === currentBottomSheet.sub_id);
|
|
|
|
return (
|
|
|
|
<Card>
|
|
|
|
<Card.Title title={subject.name} />
|
|
|
|
<Card.Content style={style.bottomNavigation}>
|
|
|
|
<Button mode="contained">Change Subject</Button>
|
|
|
|
<Button mode="contained">Change Start Time</Button>
|
|
|
|
<Button mode="contained">Change End Time</Button>
|
|
|
|
<Button mode="contained" onPress={() => {
|
|
|
|
closeBottomSheet();
|
|
|
|
setDialog({ show: true, id: currentBottomSheet.name });
|
|
|
|
}}>Remove</Button>
|
|
|
|
</Card.Content>
|
|
|
|
</Card>
|
|
|
|
);
|
|
|
|
}
|
2020-03-24 19:17:54 +01:00
|
|
|
return (<Portal.Host><ScrollView>
|
2020-03-20 15:35:50 +01:00
|
|
|
{timetable.map((day, dayIdx) => (
|
2020-03-21 09:04:18 +01:00
|
|
|
<Card
|
|
|
|
key={dayIdx}
|
|
|
|
style={
|
|
|
|
[
|
|
|
|
style.card,
|
|
|
|
{marginBottom: dayIdx === 6 ? 80 : 0 }
|
|
|
|
]
|
|
|
|
}
|
|
|
|
>
|
2020-03-20 15:35:50 +01:00
|
|
|
<Card.Title title={days[dayIdx]} />
|
|
|
|
<Card.Content>
|
2020-03-24 19:17:54 +01:00
|
|
|
<DataTable>
|
|
|
|
<DataTable.Header>
|
|
|
|
<DataTable.Title
|
|
|
|
style={{ flexGrow: 2 }}
|
|
|
|
>
|
|
|
|
Course
|
|
|
|
</DataTable.Title>
|
|
|
|
<DataTable.Title
|
|
|
|
style={{ flexGrow: 1 }}
|
|
|
|
>
|
|
|
|
From
|
|
|
|
</DataTable.Title>
|
|
|
|
<DataTable.Title
|
|
|
|
style={{ flexGrow: 1 }}
|
|
|
|
>
|
|
|
|
To
|
|
|
|
</DataTable.Title>
|
|
|
|
<DataTable.Title
|
|
|
|
style={{ flexGrow: 1 }}
|
|
|
|
>
|
|
|
|
Count
|
|
|
|
</DataTable.Title>
|
|
|
|
</DataTable.Header>
|
|
|
|
{[...day].sort((i, j) => sortTimes(i.start, j.start)).map((cls, idx) => {
|
|
|
|
const subject = subjects.find(i => i.id === cls.sub_id);
|
|
|
|
return (
|
|
|
|
<DataTable.Row
|
|
|
|
key={idx}
|
2020-04-14 18:00:53 +02:00
|
|
|
onPress={() => {
|
|
|
|
setCurrentBottomSheet(cls);
|
|
|
|
openBottomSheet();
|
|
|
|
}}
|
2020-03-24 19:17:54 +01:00
|
|
|
>
|
|
|
|
<DataTable.Cell
|
|
|
|
style={{ flexGrow: 2 }}
|
|
|
|
>
|
|
|
|
{subject.name}
|
|
|
|
</DataTable.Cell>
|
|
|
|
<DataTable.Cell
|
|
|
|
style={{ flexGrow: 1 }}
|
|
|
|
>
|
|
|
|
{format(cls.start, "HH:mm")}
|
|
|
|
</DataTable.Cell>
|
|
|
|
<DataTable.Cell
|
|
|
|
style={{ flexGrow: 1 }}
|
|
|
|
>
|
|
|
|
{format(cls.end, "HH:mm")}
|
|
|
|
</DataTable.Cell>
|
|
|
|
<DataTable.Cell
|
|
|
|
style={{ flexGrow: 1 }}
|
|
|
|
>
|
|
|
|
{cls.count}
|
|
|
|
</DataTable.Cell>
|
|
|
|
</DataTable.Row>
|
|
|
|
);
|
|
|
|
})}
|
|
|
|
</DataTable>
|
2020-03-20 15:35:50 +01:00
|
|
|
</Card.Content>
|
|
|
|
</Card>
|
|
|
|
))}
|
2020-03-24 19:17:54 +01:00
|
|
|
<Portal>
|
|
|
|
<Dialog
|
|
|
|
visible={dialog.show}
|
|
|
|
onDismiss={() => setDialog({ show: false, id: null })}>
|
|
|
|
<Dialog.Title>Remove Entry?</Dialog.Title>
|
|
|
|
<Dialog.Actions>
|
|
|
|
<Button onPress={() => setDialog({ show: false, id: null })}>Cancel</Button>
|
|
|
|
<Button
|
|
|
|
onPress={() => {
|
|
|
|
setDialog({ show: false, id: null });
|
|
|
|
removeTimetableEntry(dialog.id);
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
Remove
|
|
|
|
</Button>
|
|
|
|
</Dialog.Actions>
|
|
|
|
</Dialog>
|
2020-04-09 18:35:23 +02:00
|
|
|
<FAB
|
2020-04-14 18:00:53 +02:00
|
|
|
visible={currentBottomSheet == null}
|
|
|
|
large
|
2020-04-09 18:35:23 +02:00
|
|
|
icon="plus"
|
|
|
|
onPress={() => navigation.navigate("New Entry")}
|
|
|
|
style={{
|
|
|
|
position: "absolute",
|
|
|
|
margin: 16,
|
|
|
|
right: 0,
|
|
|
|
bottom: 0,
|
|
|
|
}}
|
|
|
|
/>
|
2020-04-14 18:00:53 +02:00
|
|
|
<Modal
|
|
|
|
visible={currentBottomSheet != null}
|
|
|
|
onDismiss={closeBottomSheet}
|
|
|
|
dismissable={false}
|
|
|
|
>
|
|
|
|
</Modal>
|
|
|
|
<BottomSheet
|
|
|
|
ref={this.bs}
|
|
|
|
snapPoints={[300, 150, 0]}
|
|
|
|
initialSnap={1}
|
|
|
|
renderContent={CardContents}
|
|
|
|
enabledInnerScrolling={false}
|
|
|
|
onCloseStart={() => setCurrentBottomSheet(null)}
|
|
|
|
onCloseEnd={() => {}}
|
|
|
|
/>
|
2020-03-24 19:17:54 +01:00
|
|
|
</Portal>
|
|
|
|
</ScrollView></Portal.Host>);
|
2020-03-20 15:35:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
HomeScreen.propTypes = {
|
|
|
|
timetable: PropTypes.array,
|
|
|
|
subjects: PropTypes.array,
|
|
|
|
navigation: PropTypes.object,
|
|
|
|
days: PropTypes.array,
|
2020-03-24 19:17:54 +01:00
|
|
|
removeTimetableEntry: PropTypes.func,
|
2020-03-20 15:35:50 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
const style = StyleSheet.create({
|
|
|
|
card: {
|
|
|
|
marginTop: 12,
|
|
|
|
marginLeft: 10,
|
|
|
|
marginRight: 10,
|
|
|
|
},
|
|
|
|
text: {
|
|
|
|
marginTop: 12,
|
|
|
|
textAlign: "center",
|
|
|
|
},
|
|
|
|
class: {
|
|
|
|
flexDirection: "row",
|
|
|
|
justifyContent: "space-between"
|
|
|
|
},
|
2020-04-14 18:00:53 +02:00
|
|
|
bottomNavigation: {
|
|
|
|
height: 250,
|
|
|
|
flexDirection: "column",
|
|
|
|
justifyContent: "space-evenly",
|
|
|
|
},
|
2020-03-20 15:35:50 +01:00
|
|
|
});
|
|
|
|
|
2020-04-09 18:35:23 +02:00
|
|
|
export default HomeScreen;
|