Compare commits

..

No commits in common. "master" and "v0.9.3.7-beta" have entirely different histories.

2 changed files with 27 additions and 307 deletions

View file

@ -200,17 +200,9 @@ export default function ConversationPage() {
> >
<View style={styles.flex_row}> <View style={styles.flex_row}>
<Text style={{ ...styles.text_white_medium }}> <Text style={{ ...styles.text_white_medium }}>
{`Group: ${studygroup?.name ? studygroup.name : "Loading..."}`} {`Group: ${studygroup?.name ? studygroup.name : ""}`}
</Text> </Text>
</View> </View>
{studygroup.landmark ? (
<Text style={{...styles.text_white_tiny_bold,...{textAlign:'left'}}}>
{studygroup.landmark}
</Text>
) : (
<></>
)}
<View style={{ ...styles.flex_row }}> <View style={{ ...styles.flex_row }}>
<Text <Text
style={{ style={{

View file

@ -6,11 +6,10 @@ import {
ScrollView, ScrollView,
Switch, Switch,
ActivityIndicator, ActivityIndicator,
TouchableHighlight,
} from "react-native"; } from "react-native";
import AnimatedContainer from "../../components/AnimatedContainer/AnimatedContainer"; import AnimatedContainer from "../../components/AnimatedContainer/AnimatedContainer";
import { useState, useEffect } from "react"; import { useState, useEffect } from "react";
import MapView, { Callout, Circle, Marker, UrlTile } from "react-native-maps"; import MapView, { Circle, Marker, UrlTile } from "react-native-maps";
import * as Location from "expo-location"; import * as Location from "expo-location";
import GetDistance from "../../components/GetDistance/GetDistance"; import GetDistance from "../../components/GetDistance/GetDistance";
import Button from "../../components/Button/Button"; import Button from "../../components/Button/Button";
@ -46,7 +45,6 @@ import DropdownIcon from "../../icons/CaretDownIcon/CaretDownIcon";
import CaretUpIcon from "../../icons/CaretUpIcon/CaretUpIcon"; import CaretUpIcon from "../../icons/CaretUpIcon/CaretUpIcon";
import RefreshIcon from "../../icons/RefreshIcon/RefreshIcon"; import RefreshIcon from "../../icons/RefreshIcon/RefreshIcon";
import AsyncStorage from "@react-native-async-storage/async-storage"; import AsyncStorage from "@react-native-async-storage/async-storage";
import AnimatedContainerNoScroll from "../../components/AnimatedContainer/AnimatedContainerNoScroll";
export default function Home() { export default function Home() {
// Switch this condition to see the main map when debugging // Switch this condition to see the main map when debugging
@ -86,15 +84,23 @@ export default function Home() {
async function requestLocation() { async function requestLocation() {
if (locationPermitted) { if (locationPermitted) {
let newLocation = await Location.getCurrentPositionAsync(); 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); setLocation(newLocation);
await DistanceHandler(newLocation); await DistanceHandler(newLocation);
} }
} }
}
}
useEffect(() => { useEffect(() => {
// console.log("Location Update"); console.log("changed");
// console.log(locationPermitted); console.log(locationPermitted);
requestLocation(); requestLocation();
}, [locationPermitted]); }, [locationPermitted]);
@ -111,8 +117,8 @@ export default function Home() {
async function DistanceHandler(location: RawLocationType) { async function DistanceHandler(location: RawLocationType) {
let dist = GetDistanceFromUSTP(location.coords); let dist = GetDistanceFromUSTP(location.coords);
setDist(dist); setDist(dist);
// Deactivate student status if too far away from USTP and still studying // Deactivate student status if too far away and still studying
if (dist >= 1 && !map_distance_override && studying && !stopping_toofar) { if (dist >= 2 && !map_distance_override && studying && !stopping_toofar) {
stop_studying.mutate({ stop_studying.mutate({
active: false, active: false,
}); });
@ -146,22 +152,6 @@ export default function Home() {
setSubject(data[1].subject); setSubject(data[1].subject);
setStudying(data[1].active); setStudying(data[1].active);
setStudentStatus(data[1]); 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
);
if (dist > 0.5 && studying && !stopping_toofar) {
console.log("Too far from current studying location");
stop_studying.mutate({
active: false,
});
setStopping(true);
}
}
}, },
onError: (error: Error) => { onError: (error: Error) => {
toast.show(String(error), { toast.show(String(error), {
@ -207,7 +197,9 @@ export default function Home() {
}, 500); }, 500);
setStudyGroups([]); setStudyGroups([]);
setStudying(false); setStudying(false);
if (stopping_toofar) {
setStopping(false); setStopping(false);
}
}, },
onError: (error: Error) => { onError: (error: Error) => {
toast.show(String(error), { toast.show(String(error), {
@ -406,21 +398,8 @@ export default function Home() {
<Text style={styles.text_white_medium}>Loading...</Text> <Text style={styles.text_white_medium}>Loading...</Text>
</> </>
); );
} else if (
study_groups == undefined ||
study_groups_global == undefined ||
student_statuses == undefined ||
student_statuses_global == undefined
) {
return (
<>
<View style={{ paddingVertical: 8 }} />
<ActivityIndicator size={96} color={colors.secondary_1} />
<Text style={styles.text_white_medium}>Loading...</Text>
</>
);
} else if (dist && location) { } else if (dist && location) {
if (dist <= 0.25 || map_distance_override) { if (dist <= 1 || map_distance_override) {
return ( return (
<> <>
<MapView <MapView
@ -479,7 +458,6 @@ export default function Home() {
zIndex={1000} zIndex={1000}
onPress={() => { onPress={() => {
toast.hideAll(); toast.hideAll();
toast.show( toast.show(
<View <View
style={{ style={{
@ -508,26 +486,7 @@ export default function Home() {
} }
); );
}} }}
> />
<Callout>
<Text style={styles.text_white_tiny_bold}>
Student: {student_status.user}
</Text>
<Text style={styles.text_white_tiny_bold}>
{`Studying ${student_status.subject}`}
</Text>
<Text style={styles.text_black_tiny}>
{`${Math.round(
GetDistance(
student_status.location.latitude,
student_status.location.longitude,
location.coords.latitude,
location.coords.longitude
) * 1000
)}m away`}
</Text>
</Callout>
</Marker>
); );
} }
) )
@ -608,7 +567,6 @@ export default function Home() {
zIndex={1000} zIndex={1000}
onPress={() => { onPress={() => {
toast.hideAll(); toast.hideAll();
toast.show( toast.show(
<View <View
style={{ style={{
@ -620,13 +578,6 @@ export default function Home() {
<Text style={styles.text_white_tiny_bold}> <Text style={styles.text_white_tiny_bold}>
Study Group: {studygroup.name} Study Group: {studygroup.name}
</Text> </Text>
{studygroup.landmark ? (
<Text style={styles.text_white_tiny_bold}>
{studygroup.landmark}
</Text>
) : (
<></>
)}
<Text style={styles.text_white_tiny_bold}> <Text style={styles.text_white_tiny_bold}>
{`Studying ${studygroup.subject}`} {`Studying ${studygroup.subject}`}
</Text> </Text>
@ -691,35 +642,7 @@ export default function Home() {
} }
); );
}} }}
> />
<Callout>
<Text style={styles.text_black_tiny}>
Study Group: {studygroup.name}
</Text>
<Text style={styles.text_black_tiny}>
Studying: {studygroup.subject}
</Text>
{studygroup.landmark ? (
<Text style={styles.text_black_tiny}>
{studygroup.landmark}
</Text>
) : (
<></>
)}
<Text style={styles.text_black_tiny}>
{`${studygroup.students.length} ${
studygroup.students.length > 1
? "students"
: "student"
} studying`}
</Text>
<Text style={styles.text_black_tiny}>
{`${Math.round(
studygroup.distance * 1000
)}m away`}
</Text>
</Callout>
</Marker>
<Circle <Circle
center={studygroup.location} center={studygroup.location}
radius={studygroup.radius} radius={studygroup.radius}
@ -762,13 +685,6 @@ export default function Home() {
<Text style={styles.text_white_tiny_bold}> <Text style={styles.text_white_tiny_bold}>
Study Group: {studygroup.name} Study Group: {studygroup.name}
</Text> </Text>
{studygroup.landmark ? (
<Text style={styles.text_white_tiny_bold}>
{studygroup.landmark}
</Text>
) : (
<></>
)}
<Text style={styles.text_white_tiny_bold}> <Text style={styles.text_white_tiny_bold}>
{`Studying ${studygroup.subject}`} {`Studying ${studygroup.subject}`}
</Text> </Text>
@ -801,40 +717,7 @@ export default function Home() {
} }
); );
}} }}
> />
<Callout>
<Text style={styles.text_black_tiny}>
Study Group: {studygroup.name}
</Text>
<Text style={styles.text_black_tiny}>
Studying: {studygroup.subject}
</Text>
{studygroup.landmark ? (
<Text style={styles.text_black_tiny}>
{studygroup.landmark}
</Text>
) : (
<></>
)}
<Text style={styles.text_black_tiny}>
{`${studygroup.students.length} ${
studygroup.students.length > 1
? "students"
: "student"
} studying`}
</Text>
<Text style={styles.text_black_tiny}>
{`${Math.round(
GetDistance(
studygroup.location.latitude,
studygroup.location.longitude,
location.coords.latitude,
location.coords.longitude
)
)}m away`}
</Text>
</Callout>
</Marker>
<Circle <Circle
center={studygroup.location} center={studygroup.location}
radius={studygroup.radius} radius={studygroup.radius}
@ -1010,7 +893,6 @@ export default function Home() {
duration: 2000, duration: 2000,
animationType: "slide-in", animationType: "slide-in",
}); });
requestLocation();
}} }}
> >
<RefreshIcon size={32} /> <RefreshIcon size={32} />
@ -1026,7 +908,7 @@ export default function Home() {
setModalOpen(true); setModalOpen(true);
}} }}
> >
<CaretUpIcon size={32} /> {studying ? <CaretUpIcon size={32} /> : <></>}
</Pressable> </Pressable>
</View> </View>
{student_status?.active && !student_status?.study_group ? ( {student_status?.active && !student_status?.study_group ? (
@ -1085,15 +967,14 @@ export default function Home() {
> >
<DropdownIcon size={32} /> <DropdownIcon size={32} />
</Pressable> </Pressable>
<View style={styles.flex_column}> <View style={styles.flex_row}>
<Text style={styles.text_white_medium}>List View</Text>
<Switch <Switch
value={modalByGroup} value={modalByGroup}
onChange={() => { onChange={() => {
setModalByGroup(!modalByGroup); setModalByGroup(!modalByGroup);
}} }}
style={{ alignSelf: "center" }}
/> />
<Text style={styles.text_white_medium}>List View</Text>
</View> </View>
<ScrollView> <ScrollView>
@ -1124,20 +1005,6 @@ export default function Home() {
<Text style={styles.text_white_tiny_bold}> <Text style={styles.text_white_tiny_bold}>
{`${Math.round(student_status.distance * 1000)}m away`} {`${Math.round(student_status.distance * 1000)}m away`}
</Text> </Text>
{location && location.coords ? (
<Text style={styles.text_black_tiny}>
{`${Math.round(
GetDistance(
student_status.location.latitude,
student_status.location.longitude,
location.coords.latitude,
location.coords.longitude
)
)}m away`}
</Text>
) : (
<></>
)}
</View> </View>
); );
} }
@ -1165,13 +1032,6 @@ export default function Home() {
<Text style={styles.text_white_tiny_bold}> <Text style={styles.text_white_tiny_bold}>
Group Name: {studygroup.name} Group Name: {studygroup.name}
</Text> </Text>
{studygroup.landmark ? (
<Text style={styles.text_white_tiny_bold}>
{studygroup.landmark}
</Text>
) : (
<></>
)}
<Text style={styles.text_white_tiny_bold}> <Text style={styles.text_white_tiny_bold}>
{`Studying ${studygroup.subject}`} {`Studying ${studygroup.subject}`}
</Text> </Text>
@ -1236,138 +1096,6 @@ export default function Home() {
</ScrollView> </ScrollView>
</AnimatedContainer> </AnimatedContainer>
</Modal> </Modal>
<Modal
coverScreen={false}
isVisible={modalOpen && !studying}
style={{ opacity: 0.85 }}
hasBackdrop={false}
>
<AnimatedContainer>
<Pressable
style={{
alignContent: "flex-start",
backgroundColor: colors.secondary_3,
borderRadius: 16,
}}
onPress={() => setModalOpen(false)}
>
<DropdownIcon size={32} />
</Pressable>
<View style={styles.flex_column}>
<Text style={styles.text_white_medium}>List View</Text>
<Switch
value={modalByGroup}
onChange={() => {
setModalByGroup(!modalByGroup);
}}
style={{ alignSelf: "center" }}
/>
</View>
<ScrollView>
{!modalByGroup ? (
student_statuses_global.map(
(student_status: StudentStatusFilterType, index: number) => {
return (
<View
key={index}
style={{
alignContent: "center",
alignSelf: "center",
justifyContent: "center",
backgroundColor: colors.secondary_3,
borderColor: colors.primary_2,
borderWidth: 1,
borderRadius: 16,
width: 256,
marginVertical: 4,
}}
>
<Text style={styles.text_white_tiny_bold}>
Student: {student_status.user}
</Text>
<Text style={styles.text_white_tiny_bold}>
{`Studying ${student_status.subject}`}
</Text>
{location && location.coords ? (
<Text style={styles.text_white_tiny}>
{`${Math.round(
GetDistance(
student_status.location.latitude,
student_status.location.longitude,
location.coords.latitude,
location.coords.longitude
)
)}m away`}
</Text>
) : (
<></>
)}
</View>
);
}
)
) : (
<></>
)}
{modalByGroup ? (
study_groups_global.map(
(studygroup: StudyGroupType, index: number) => {
return (
<View
key={index}
style={{
alignContent: "center",
alignSelf: "center",
justifyContent: "center",
backgroundColor: colors.secondary_3,
borderColor: colors.primary_2,
borderWidth: 1,
borderRadius: 16,
width: 256,
marginVertical: 4,
}}
>
<Text style={styles.text_white_tiny_bold}>
Group Name: {studygroup.name}
</Text>
{studygroup.landmark ? (
<Text style={styles.text_white_tiny_bold}>
{studygroup.landmark}
</Text>
) : (
<></>
)}
<Text style={styles.text_white_tiny_bold}>
{`Studying ${studygroup.subject}`}
</Text>
<Text style={styles.text_white_tiny_bold}>
Students Studying: {studygroup.students.length}
</Text>
{location && location.coords ? (
<Text style={styles.text_white_tiny}>
{`${Math.round(
GetDistance(
studygroup.location.latitude,
studygroup.location.longitude,
location.coords.latitude,
location.coords.longitude
)
)}m away`}
</Text>
) : (
<></>
)}
</View>
);
}
)
) : (
<></>
)}
</ScrollView>
</AnimatedContainer>
</Modal>
<AnimatedContainer> <AnimatedContainer>
<View style={{ borderRadius: 16, overflow: "hidden" }}> <View style={{ borderRadius: 16, overflow: "hidden" }}>