mirror of
https://github.com/lemeow125/StudE-Frontend.git
synced 2025-04-20 17:01:22 +08:00
Compare commits
No commits in common. "master" and "v1.1" have entirely different histories.
1 changed files with 32 additions and 164 deletions
|
@ -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,16 @@ 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) {
|
||||||
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]);
|
||||||
|
|
||||||
|
@ -112,7 +111,7 @@ export default function Home() {
|
||||||
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 from USTP 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,
|
||||||
});
|
});
|
||||||
|
@ -154,7 +153,14 @@ export default function Home() {
|
||||||
location.coords.latitude,
|
location.coords.latitude,
|
||||||
location.coords.longitude
|
location.coords.longitude
|
||||||
);
|
);
|
||||||
if (dist > 0.5 && studying && !stopping_toofar) {
|
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");
|
console.log("Too far from current studying location");
|
||||||
stop_studying.mutate({
|
stop_studying.mutate({
|
||||||
active: false,
|
active: false,
|
||||||
|
@ -406,21 +412,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 +472,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 +500,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 +581,6 @@ export default function Home() {
|
||||||
zIndex={1000}
|
zIndex={1000}
|
||||||
onPress={() => {
|
onPress={() => {
|
||||||
toast.hideAll();
|
toast.hideAll();
|
||||||
|
|
||||||
toast.show(
|
toast.show(
|
||||||
<View
|
<View
|
||||||
style={{
|
style={{
|
||||||
|
@ -691,35 +663,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}
|
||||||
|
@ -801,40 +745,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}
|
||||||
|
@ -1124,20 +1035,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>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -1166,12 +1063,12 @@ export default function Home() {
|
||||||
Group Name: {studygroup.name}
|
Group Name: {studygroup.name}
|
||||||
</Text>
|
</Text>
|
||||||
{studygroup.landmark ? (
|
{studygroup.landmark ? (
|
||||||
<Text style={styles.text_white_tiny_bold}>
|
<Text style={styles.text_white_tiny_bold}>
|
||||||
{studygroup.landmark}
|
{studygroup.landmark}
|
||||||
</Text>
|
</Text>
|
||||||
) : (
|
) : (
|
||||||
<></>
|
<></>
|
||||||
)}
|
)}
|
||||||
<Text style={styles.text_white_tiny_bold}>
|
<Text style={styles.text_white_tiny_bold}>
|
||||||
{`Studying ${studygroup.subject}`}
|
{`Studying ${studygroup.subject}`}
|
||||||
</Text>
|
</Text>
|
||||||
|
@ -1289,20 +1186,6 @@ export default function Home() {
|
||||||
<Text style={styles.text_white_tiny_bold}>
|
<Text style={styles.text_white_tiny_bold}>
|
||||||
{`Studying ${student_status.subject}`}
|
{`Studying ${student_status.subject}`}
|
||||||
</Text>
|
</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>
|
</View>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -1332,32 +1215,18 @@ export default function Home() {
|
||||||
Group Name: {studygroup.name}
|
Group Name: {studygroup.name}
|
||||||
</Text>
|
</Text>
|
||||||
{studygroup.landmark ? (
|
{studygroup.landmark ? (
|
||||||
<Text style={styles.text_white_tiny_bold}>
|
<Text style={styles.text_white_tiny_bold}>
|
||||||
{studygroup.landmark}
|
{studygroup.landmark}
|
||||||
</Text>
|
</Text>
|
||||||
) : (
|
) : (
|
||||||
<></>
|
<></>
|
||||||
)}
|
)}
|
||||||
<Text style={styles.text_white_tiny_bold}>
|
<Text style={styles.text_white_tiny_bold}>
|
||||||
{`Studying ${studygroup.subject}`}
|
{`Studying ${studygroup.subject}`}
|
||||||
</Text>
|
</Text>
|
||||||
<Text style={styles.text_white_tiny_bold}>
|
<Text style={styles.text_white_tiny_bold}>
|
||||||
Students Studying: {studygroup.students.length}
|
Students Studying: {studygroup.students.length}
|
||||||
</Text>
|
</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>
|
</View>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -1368,7 +1237,6 @@ export default function Home() {
|
||||||
</ScrollView>
|
</ScrollView>
|
||||||
</AnimatedContainer>
|
</AnimatedContainer>
|
||||||
</Modal>
|
</Modal>
|
||||||
|
|
||||||
<AnimatedContainer>
|
<AnimatedContainer>
|
||||||
<View style={{ borderRadius: 16, overflow: "hidden" }}>
|
<View style={{ borderRadius: 16, overflow: "hidden" }}>
|
||||||
<CustomMap />
|
<CustomMap />
|
||||||
|
|
Loading…
Add table
Reference in a new issue