import React, { useState } from "react"; import PropTypes from "prop-types"; import { Button, Card, DataTable, Dialog, FAB, Portal, Modal, } from "react-native-paper"; import { StyleSheet, ScrollView } from "react-native"; import { format } from "date-fns"; import BottomSheet from "reanimated-bottom-sheet"; function sortTimes(t1, t2) { if (t1.getHours() > t2.getHours()) return 1; if (t1.getHours() < t2.getHours()) return -1; if (t1.getMinutes() > t2.getMinutes()) return 1; if (t1.getMinutes() < t2.getMinutes()) return -1; return 0; } function HomeScreen({ days, navigation, removeTimetableEntry, subjects, timetable }) { const [ dialog, setDialog ] = useState({ show: false, id: null }); 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 ( ); } 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 ( { setCurrentBottomSheet(cls); openBottomSheet(); }} > {subject.name} {format(cls.start, "HH:mm")} {format(cls.end, "HH:mm")} {cls.count} ); })} ))} setDialog({ show: false, id: null })}> Remove Entry? navigation.navigate("New Entry")} style={{ position: "absolute", margin: 16, right: 0, bottom: 0, }} /> setCurrentBottomSheet(null)} onCloseEnd={() => {}} /> ); } HomeScreen.propTypes = { timetable: PropTypes.array, subjects: PropTypes.array, navigation: PropTypes.object, days: PropTypes.array, 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" }, bottomNavigation: { height: 250, flexDirection: "column", justifyContent: "space-evenly", }, }); export default HomeScreen;