From cbd82a05f9423944d243182e6fb68856c98c812d Mon Sep 17 00:00:00 2001 From: Keannu Bernasol Date: Fri, 24 Nov 2023 21:14:33 +0800 Subject: [PATCH] Added callout information for study groups when pressing on maps and improved responsiveness of the homepage map renderer --- src/routes/Home/Home.tsx | 178 ++++++++++++++++++++++++++++++++++----- 1 file changed, 159 insertions(+), 19 deletions(-) diff --git a/src/routes/Home/Home.tsx b/src/routes/Home/Home.tsx index d854b88..efec988 100644 --- a/src/routes/Home/Home.tsx +++ b/src/routes/Home/Home.tsx @@ -6,10 +6,11 @@ import { ScrollView, Switch, ActivityIndicator, + TouchableHighlight, } from "react-native"; import AnimatedContainer from "../../components/AnimatedContainer/AnimatedContainer"; import { useState, useEffect } from "react"; -import MapView, { Circle, Marker, UrlTile } from "react-native-maps"; +import MapView, { Callout, Circle, Marker, UrlTile } from "react-native-maps"; import * as Location from "expo-location"; import GetDistance from "../../components/GetDistance/GetDistance"; import Button from "../../components/Button/Button"; @@ -45,10 +46,11 @@ import DropdownIcon from "../../icons/CaretDownIcon/CaretDownIcon"; import CaretUpIcon from "../../icons/CaretUpIcon/CaretUpIcon"; import RefreshIcon from "../../icons/RefreshIcon/RefreshIcon"; import AsyncStorage from "@react-native-async-storage/async-storage"; +import AnimatedContainerNoScroll from "../../components/AnimatedContainer/AnimatedContainerNoScroll"; export default function Home() { // Switch this condition to see the main map when debugging - const map_distance_override = false; + const map_distance_override = true; const navigation = useNavigation(); const [location, setLocation] = useState(null); const [locationPermitted, setLocationPermitted] = useState(false); @@ -84,10 +86,10 @@ export default function Home() { async function requestLocation() { if (locationPermitted) { let newLocation = await Location.getCurrentPositionAsync(); - if (newLocation) { + setLocation(newLocation); await DistanceHandler(newLocation); - } + } } @@ -412,6 +414,19 @@ export default function Home() { Loading... ); + } else if ( + study_groups == undefined || + study_groups_global == undefined || + student_statuses == undefined|| + student_statuses_global == undefined + ) { + return ( + <> + + + Loading... + + ); } else if (dist && location) { if (dist <= 1 || map_distance_override) { return ( @@ -472,6 +487,7 @@ export default function Home() { zIndex={1000} onPress={() => { toast.hideAll(); + toast.show( + > + + + Student: {student_status.user} + + + {`Studying ${student_status.subject}`} + + + {`${Math.round( + GetDistance( + student_status.location.latitude, + student_status.location.longitude, + location.coords.latitude, + location.coords.longitude + ) * 1000 + )}m away`} + + + ); } ) @@ -581,6 +616,7 @@ export default function Home() { zIndex={1000} onPress={() => { toast.hideAll(); + toast.show( + > + + + Study Group: {studygroup.name} + + + Studying: {studygroup.subject} + + {studygroup.landmark ? ( + + {studygroup.landmark} + + ) : ( + <> + )} + + {`${studygroup.students.length} ${ + studygroup.students.length > 1 + ? "students" + : "student" + } studying`} + + + {`${Math.round( + studygroup.distance * 1000 + )}m away`} + + + + > + + + Study Group: {studygroup.name} + + + Studying: {studygroup.subject} + + {studygroup.landmark ? ( + + {studygroup.landmark} + + ) : ( + <> + )} + + {`${studygroup.students.length} ${ + studygroup.students.length > 1 + ? "students" + : "student" + } studying`} + + + {`${Math.round( + GetDistance( + studygroup.location.latitude, + studygroup.location.longitude, + location.coords.latitude, + location.coords.longitude + ) + )}m away`} + + + {`${Math.round(student_status.distance * 1000)}m away`} + {location && location.coords ? ( + + {`${Math.round( + GetDistance( + student_status.location.latitude, + student_status.location.longitude, + location.coords.latitude, + location.coords.longitude + ) + )}m away`} + + ) : ( + <> + )} ); } @@ -1063,12 +1174,12 @@ export default function Home() { Group Name: {studygroup.name} {studygroup.landmark ? ( - - {studygroup.landmark} - - ) : ( - <> - )} + + {studygroup.landmark} + + ) : ( + <> + )} {`Studying ${studygroup.subject}`} @@ -1186,6 +1297,20 @@ export default function Home() { {`Studying ${student_status.subject}`} + {location && location.coords ? ( + + {`${Math.round( + GetDistance( + student_status.location.latitude, + student_status.location.longitude, + location.coords.latitude, + location.coords.longitude + ) + )}m away`} + + ) : ( + <> + )} ); } @@ -1215,18 +1340,32 @@ export default function Home() { Group Name: {studygroup.name} {studygroup.landmark ? ( - - {studygroup.landmark} - - ) : ( - <> - )} + + {studygroup.landmark} + + ) : ( + <> + )} {`Studying ${studygroup.subject}`} Students Studying: {studygroup.students.length} + {location && location.coords ? ( + + {`${Math.round( + GetDistance( + studygroup.location.latitude, + studygroup.location.longitude, + location.coords.latitude, + location.coords.longitude + ) + )}m away`} + + ) : ( + <> + )} ); } @@ -1237,6 +1376,7 @@ export default function Home() { +