import React, { useState } from "react"; import PropTypes from "prop-types"; import { Button, IconButton, Card, DataTable, Dialog, Portal, withTheme, } from "react-native-paper"; import { StyleSheet, ScrollView } from "react-native"; import { format } from "date-fns"; function sortTimes(t1, t2) { if (t1.getHours() > t2.getHours()) return 1; if (t1.getHours() < t2.getHours()) return -1; if (t1.getMinute() > t2.getMinute()) return 1; if (t1.getMinute() < t2.getMinute()) return -1; return 0; } function HomeScreen({ days, navigation, removeTimetableEntry, subjects, theme, timetable }) { const [ dialog, setDialog ] = useState({ show: false, id: null }); return ( {timetable.map((day, dayIdx) => ( Course From To Count {[...day].sort((i, j) => sortTimes(i.start, j.start)).map((cls, idx) => { const subject = subjects.find(i => i.id === cls.sub_id); return ( setDialog({ show: true, id: cls.id })} > {subject.name} {format(cls.start, "HH:mm")} {format(cls.end, "HH:mm")} {cls.count} ); })} navigation.navigate(`New Entry ${days[dayIdx]}`)} icon="plus" color={theme.colors.primary} /> ))} setDialog({ show: false, id: null })}> Remove Entry? ); } HomeScreen.propTypes = { timetable: PropTypes.array, subjects: PropTypes.array, navigation: PropTypes.object, days: PropTypes.array, theme: PropTypes.object, removeTimetableEntry: PropTypes.func, }; const style = StyleSheet.create({ card: { marginTop: 12, marginLeft: 10, marginRight: 10, }, text: { marginTop: 12, textAlign: "center", }, class: { flexDirection: "row", justifyContent: "space-between" }, }); export default withTheme(HomeScreen);