From 7cd549cad7cbfeb18458cec445083e4cc57fe667 Mon Sep 17 00:00:00 2001 From: Keannu Bernasol Date: Thu, 23 Nov 2023 23:27:38 +0800 Subject: [PATCH 1/7] Refetch user location when refreshing and added code snippet to stop user from studying if they stray too far from where they set their studying locatio. Also allow modal to be shown even when not currently studying --- src/routes/Home/Home.tsx | 132 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 125 insertions(+), 7 deletions(-) diff --git a/src/routes/Home/Home.tsx b/src/routes/Home/Home.tsx index 3769c06..aa29b01 100644 --- a/src/routes/Home/Home.tsx +++ b/src/routes/Home/Home.tsx @@ -48,7 +48,7 @@ import AsyncStorage from "@react-native-async-storage/async-storage"; 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); @@ -117,7 +117,7 @@ export default function Home() { async function DistanceHandler(location: RawLocationType) { let dist = GetDistanceFromUSTP(location.coords); setDist(dist); - // Deactivate student status if too far away and still studying + // Deactivate student status if too far away from USTP and still studying if (dist >= 2 && !map_distance_override && studying && !stopping_toofar) { stop_studying.mutate({ active: false, @@ -152,6 +152,28 @@ export default function Home() { setSubject(data[1].subject); setStudying(data[1].active); setStudentStatus(data[1]); + // Deactivate student status if too far away from current location you are studying in + if(student_status && location){ + const dist = GetDistance( + student_status.location.latitude, + student_status.location.longitude, + location.coords.latitude, + location.coords.longitude + ); + console.log('Distance:',dist) + console.log(student_status.location.latitude, + student_status.location.longitude, + location.coords.latitude, + location.coords.longitude) + if (dist > 0.02 && studying && !stopping_toofar) { + console.log('Too far from current studying location') + stop_studying.mutate({ + active: false, + }); + setStopping(true); + } + } + }, onError: (error: Error) => { toast.show(String(error), { @@ -197,9 +219,7 @@ export default function Home() { }, 500); setStudyGroups([]); setStudying(false); - if (stopping_toofar) { setStopping(false); - } }, onError: (error: Error) => { toast.show(String(error), { @@ -893,6 +913,7 @@ export default function Home() { duration: 2000, animationType: "slide-in", }); + requestLocation() }} > @@ -908,7 +929,7 @@ export default function Home() { setModalOpen(true); }} > - {studying ? : <>} + {student_status?.active && !student_status?.study_group ? ( @@ -967,14 +988,16 @@ export default function Home() { > - + + + List View { setModalByGroup(!modalByGroup); }} + style={{alignSelf:'center'}} /> - List View @@ -1096,7 +1119,102 @@ export default function Home() { + + + setModalOpen(false)} + > + + + + List View + { + setModalByGroup(!modalByGroup); + }} + style={{alignSelf:'center'}} + /> + + + + {!modalByGroup ? ( + student_statuses_global.map( + (student_status: StudentStatusFilterType, index: number) => { + return ( + + + Student: {student_status.user} + + + {`Studying ${student_status.subject}`} + + + ); + } + ) + ) : ( + <> + )} + {modalByGroup ? ( + study_groups_global.map((studygroup: StudyGroupType, index: number) => { + return ( + + + Group Name: {studygroup.name} + + + {`Studying ${studygroup.subject}`} + + + Students Studying: {studygroup.students.length} + + + ); + }) + ) : ( + <> + )} + + + From c0a8a8efc8bd6a554253c98d0df7f8fd110dafea Mon Sep 17 00:00:00 2001 From: Keannu Bernasol Date: Thu, 23 Nov 2023 23:29:27 +0800 Subject: [PATCH 2/7] Always refresh location when pressing refresh button --- src/routes/Home/Home.tsx | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/src/routes/Home/Home.tsx b/src/routes/Home/Home.tsx index aa29b01..21ee76a 100644 --- a/src/routes/Home/Home.tsx +++ b/src/routes/Home/Home.tsx @@ -85,15 +85,8 @@ export default function Home() { if (locationPermitted) { let newLocation = await Location.getCurrentPositionAsync(); if (newLocation) { - // Only update location state if user's location has changed - if ( - !location || - newLocation.coords.latitude !== location.coords.latitude || - newLocation.coords.longitude !== location.coords.longitude - ) { setLocation(newLocation); - await DistanceHandler(newLocation); - } + await DistanceHandler(newLocation); } } } From 51b7b24430ca4b4817b0ac1833051b477a681f8b Mon Sep 17 00:00:00 2001 From: Keannu Bernasol Date: Fri, 24 Nov 2023 00:22:14 +0800 Subject: [PATCH 3/7] Show landmarks if it exists in homepage and in conversation page --- src/components/Api/Api.tsx | 2 +- .../ConversationPage/ConversationPage.tsx | 10 +- src/routes/Home/Home.tsx | 113 +++++++++++------- 3 files changed, 81 insertions(+), 44 deletions(-) diff --git a/src/components/Api/Api.tsx b/src/components/Api/Api.tsx index f5dc3d2..e6111a9 100644 --- a/src/components/Api/Api.tsx +++ b/src/components/Api/Api.tsx @@ -22,7 +22,7 @@ if (__DEV__) { } // Switch this on if you wanna run production URLs while in development -let use_production = true; +let use_production = false; if (__DEV__ && use_production) { backendURL = "https://stude.keannu1.duckdns.org"; backendURLWebsocket = "ws://stude.keannu1.duckdns.org"; diff --git a/src/routes/ConversationPage/ConversationPage.tsx b/src/routes/ConversationPage/ConversationPage.tsx index 6bec280..94cae27 100644 --- a/src/routes/ConversationPage/ConversationPage.tsx +++ b/src/routes/ConversationPage/ConversationPage.tsx @@ -200,9 +200,17 @@ export default function ConversationPage() { > - {`Group: ${studygroup?.name ? studygroup.name : ""}`} + {`Group: ${studygroup?.name ? studygroup.name : "Loading..."}`} + {studygroup.landmark ? ( + + {studygroup.landmark} + + ) : ( + <> + )} + 0.02 && studying && !stopping_toofar) { - console.log('Too far from current studying location') + console.log("Too far from current studying location"); stop_studying.mutate({ active: false, }); setStopping(true); } } - }, onError: (error: Error) => { toast.show(String(error), { @@ -212,7 +213,7 @@ export default function Home() { }, 500); setStudyGroups([]); setStudying(false); - setStopping(false); + setStopping(false); }, onError: (error: Error) => { toast.show(String(error), { @@ -591,6 +592,13 @@ export default function Home() { Study Group: {studygroup.name} + {studygroup.landmark ? ( + + {studygroup.landmark} + + ) : ( + <> + )} {`Studying ${studygroup.subject}`} @@ -698,6 +706,13 @@ export default function Home() { Study Group: {studygroup.name} + {studygroup.landmark ? ( + + {studygroup.landmark} + + ) : ( + <> + )} {`Studying ${studygroup.subject}`} @@ -906,7 +921,7 @@ export default function Home() { duration: 2000, animationType: "slide-in", }); - requestLocation() + requestLocation(); }} > @@ -982,14 +997,13 @@ export default function Home() { - List View { setModalByGroup(!modalByGroup); }} - style={{alignSelf:'center'}} + style={{ alignSelf: "center" }} /> @@ -1048,6 +1062,13 @@ export default function Home() { Group Name: {studygroup.name} + {studygroup.landmark ? ( + + {studygroup.landmark} + + ) : ( + <> + )} {`Studying ${studygroup.subject}`} @@ -1130,14 +1151,13 @@ export default function Home() { - List View { setModalByGroup(!modalByGroup); }} - style={{alignSelf:'center'}} + style={{ alignSelf: "center" }} /> @@ -1174,34 +1194,43 @@ export default function Home() { <> )} {modalByGroup ? ( - study_groups_global.map((studygroup: StudyGroupType, index: number) => { - return ( - - - Group Name: {studygroup.name} - - - {`Studying ${studygroup.subject}`} - - - Students Studying: {studygroup.students.length} - - - ); - }) + study_groups_global.map( + (studygroup: StudyGroupType, index: number) => { + return ( + + + Group Name: {studygroup.name} + + {studygroup.landmark ? ( + + {studygroup.landmark} + + ) : ( + <> + )} + + {`Studying ${studygroup.subject}`} + + + Students Studying: {studygroup.students.length} + + + ); + } + ) ) : ( <> )} From d2aecbd89cb90dc9b6ca9592e72223c601faf61d Mon Sep 17 00:00:00 2001 From: Keannu Bernasol Date: Fri, 24 Nov 2023 00:26:02 +0800 Subject: [PATCH 4/7] Turn off debug flags --- src/components/Api/Api.tsx | 2 +- src/routes/Home/Home.tsx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/Api/Api.tsx b/src/components/Api/Api.tsx index e6111a9..f5dc3d2 100644 --- a/src/components/Api/Api.tsx +++ b/src/components/Api/Api.tsx @@ -22,7 +22,7 @@ if (__DEV__) { } // Switch this on if you wanna run production URLs while in development -let use_production = false; +let use_production = true; if (__DEV__ && use_production) { backendURL = "https://stude.keannu1.duckdns.org"; backendURLWebsocket = "ws://stude.keannu1.duckdns.org"; diff --git a/src/routes/Home/Home.tsx b/src/routes/Home/Home.tsx index e27fdbf..d854b88 100644 --- a/src/routes/Home/Home.tsx +++ b/src/routes/Home/Home.tsx @@ -48,7 +48,7 @@ import AsyncStorage from "@react-native-async-storage/async-storage"; export default function Home() { // Switch this condition to see the main map when debugging - const map_distance_override = true; + const map_distance_override = false; const navigation = useNavigation(); const [location, setLocation] = useState(null); const [locationPermitted, setLocationPermitted] = useState(false); From cbd82a05f9423944d243182e6fb68856c98c812d Mon Sep 17 00:00:00 2001 From: Keannu Bernasol Date: Fri, 24 Nov 2023 21:14:33 +0800 Subject: [PATCH 5/7] 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() { + From 05cee78d31ca07bf8dea431b78a7b9b333744621 Mon Sep 17 00:00:00 2001 From: Keannu Bernasol Date: Fri, 24 Nov 2023 21:15:47 +0800 Subject: [PATCH 6/7] Format with Prettier and turn off debug flag --- src/routes/Home/Home.tsx | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/routes/Home/Home.tsx b/src/routes/Home/Home.tsx index efec988..4197170 100644 --- a/src/routes/Home/Home.tsx +++ b/src/routes/Home/Home.tsx @@ -50,7 +50,7 @@ import AnimatedContainerNoScroll from "../../components/AnimatedContainer/Animat export default function Home() { // Switch this condition to see the main map when debugging - const map_distance_override = true; + const map_distance_override = false; const navigation = useNavigation(); const [location, setLocation] = useState(null); const [locationPermitted, setLocationPermitted] = useState(false); @@ -87,9 +87,8 @@ export default function Home() { if (locationPermitted) { let newLocation = await Location.getCurrentPositionAsync(); - setLocation(newLocation); - await DistanceHandler(newLocation); - + setLocation(newLocation); + await DistanceHandler(newLocation); } } @@ -417,7 +416,7 @@ export default function Home() { } else if ( study_groups == undefined || study_groups_global == undefined || - student_statuses == undefined|| + student_statuses == undefined || student_statuses_global == undefined ) { return ( From 0b3af716a5fecc97df1a63a1b4625567316f6a1f Mon Sep 17 00:00:00 2001 From: Keannu Bernasol Date: Sun, 10 Dec 2023 22:50:53 +0800 Subject: [PATCH 7/7] limit studying to within 250m of the center of ustp --- src/routes/Home/Home.tsx | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/src/routes/Home/Home.tsx b/src/routes/Home/Home.tsx index 4197170..ea7a5a1 100644 --- a/src/routes/Home/Home.tsx +++ b/src/routes/Home/Home.tsx @@ -93,8 +93,8 @@ export default function Home() { } useEffect(() => { - console.log("changed"); - console.log(locationPermitted); + // console.log("Location Update"); + // console.log(locationPermitted); requestLocation(); }, [locationPermitted]); @@ -112,7 +112,7 @@ export default function Home() { let dist = GetDistanceFromUSTP(location.coords); setDist(dist); // Deactivate student status if too far away from USTP and still studying - if (dist >= 2 && !map_distance_override && studying && !stopping_toofar) { + if (dist >= 1 && !map_distance_override && studying && !stopping_toofar) { stop_studying.mutate({ active: false, }); @@ -154,14 +154,7 @@ export default function Home() { location.coords.latitude, location.coords.longitude ); - console.log("Distance:", dist); - console.log( - student_status.location.latitude, - student_status.location.longitude, - location.coords.latitude, - location.coords.longitude - ); - if (dist > 0.02 && studying && !stopping_toofar) { + if (dist > 0.5 && studying && !stopping_toofar) { console.log("Too far from current studying location"); stop_studying.mutate({ active: false, @@ -427,7 +420,7 @@ export default function Home() { ); } else if (dist && location) { - if (dist <= 1 || map_distance_override) { + if (dist <= 0.25 || map_distance_override) { return ( <>