mirror of
https://github.com/lemeow125/StudE-Frontend.git
synced 2025-05-17 03:48:06 +08:00
Code cleanup and add pull up menu for complete student status/study group list
This commit is contained in:
parent
fb8e948dfc
commit
8279665ab9
6 changed files with 98 additions and 86 deletions
|
@ -1,41 +0,0 @@
|
||||||
import { Callout } from "react-native-maps";
|
|
||||||
import { LocationType, RawLocationType } from "../../interfaces/Interfaces";
|
|
||||||
import styles from "../../styles";
|
|
||||||
import { Text } from "react-native";
|
|
||||||
|
|
||||||
// Map popup for user's location
|
|
||||||
|
|
||||||
type props = {
|
|
||||||
location: LocationType;
|
|
||||||
studying: boolean;
|
|
||||||
subject?: string;
|
|
||||||
};
|
|
||||||
|
|
||||||
export default function CustomMapCallout(props: props) {
|
|
||||||
let { location, studying, subject } = props;
|
|
||||||
if (location && location.latitude && location.longitude) {
|
|
||||||
if (studying) {
|
|
||||||
return (
|
|
||||||
<Callout>
|
|
||||||
<Text style={styles.text_black_tiny}>
|
|
||||||
You are here {"\n"}
|
|
||||||
X: {Math.round(location.longitude) + "\n"}
|
|
||||||
Z: {Math.round(location.latitude) + "\n"}
|
|
||||||
Studying: {subject}
|
|
||||||
</Text>
|
|
||||||
</Callout>
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
return (
|
|
||||||
<Callout>
|
|
||||||
<Text style={styles.text_black_tiny}>
|
|
||||||
You are here {"\n"}
|
|
||||||
X: {Math.round(location.longitude) + "\n"}
|
|
||||||
Z: {Math.round(location.latitude)}
|
|
||||||
</Text>
|
|
||||||
</Callout>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return <></>;
|
|
||||||
}
|
|
|
@ -13,7 +13,7 @@ type props = {
|
||||||
|
|
||||||
export default function MapRendererFar(props: props) {
|
export default function MapRendererFar(props: props) {
|
||||||
return (
|
return (
|
||||||
<View>
|
<>
|
||||||
<Text style={styles.text_white_medium}>
|
<Text style={styles.text_white_medium}>
|
||||||
You are too far from USTP {"\n"}
|
You are too far from USTP {"\n"}
|
||||||
Get closer to use Stud-E
|
Get closer to use Stud-E
|
||||||
|
@ -74,6 +74,6 @@ export default function MapRendererFar(props: props) {
|
||||||
<Text style={styles.text_white_small}>
|
<Text style={styles.text_white_small}>
|
||||||
{props.dist}km away from USTP {"\n"}
|
{props.dist}km away from USTP {"\n"}
|
||||||
</Text>
|
</Text>
|
||||||
</View>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@ import { IconProps } from "../../interfaces/Interfaces";
|
||||||
import { Svg, Path } from "react-native-svg";
|
import { Svg, Path } from "react-native-svg";
|
||||||
import { colors } from "../../styles";
|
import { colors } from "../../styles";
|
||||||
|
|
||||||
export default function DropdownIcon(props: IconProps) {
|
export default function CaretDownIcon(props: IconProps) {
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Svg
|
<Svg
|
24
src/icons/CaretUpIcon/CaretUpIcon.tsx
Normal file
24
src/icons/CaretUpIcon/CaretUpIcon.tsx
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
import * as React from "react";
|
||||||
|
import { IconProps } from "../../interfaces/Interfaces";
|
||||||
|
import { Svg, Path } from "react-native-svg";
|
||||||
|
import { colors } from "../../styles";
|
||||||
|
|
||||||
|
export default function CaretUpIcon(props: IconProps) {
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Svg
|
||||||
|
height={props.size + "px"}
|
||||||
|
width={props.size + "px"}
|
||||||
|
viewBox="0 0 24 24"
|
||||||
|
stroke-width="2"
|
||||||
|
stroke={colors.icon_color}
|
||||||
|
fill="none"
|
||||||
|
stroke-linecap="round"
|
||||||
|
stroke-linejoin="round"
|
||||||
|
>
|
||||||
|
<Path stroke="none" d="M0 0h24v24H0z" fill="none"></Path>
|
||||||
|
<Path d="M18 14l-6 -6l-6 6h12"></Path>
|
||||||
|
</Svg>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
|
@ -1,16 +1,8 @@
|
||||||
import styles, { Viewport, colors } from "../../styles";
|
import styles, { colors } from "../../styles";
|
||||||
import { View, Text } from "react-native";
|
import { View, Text, Pressable } 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, {
|
import MapView, { Circle, Marker } from "react-native-maps";
|
||||||
Callout,
|
|
||||||
Heatmap,
|
|
||||||
Circle,
|
|
||||||
Marker,
|
|
||||||
UrlTile,
|
|
||||||
Overlay,
|
|
||||||
Polygon,
|
|
||||||
} 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";
|
||||||
|
@ -21,13 +13,10 @@ import {
|
||||||
StudentStatusType,
|
StudentStatusType,
|
||||||
StudentStatusListReturnType,
|
StudentStatusListReturnType,
|
||||||
StudentStatusListType,
|
StudentStatusListType,
|
||||||
subjectUserMapType,
|
|
||||||
StudentStatusFilterTypeFlattened,
|
|
||||||
StudentStatusPatchType,
|
StudentStatusPatchType,
|
||||||
StudyGroupType,
|
StudyGroupType,
|
||||||
StudyGroupReturnType,
|
StudyGroupReturnType,
|
||||||
StudentStatusFilterType,
|
StudentStatusFilterType,
|
||||||
StudyGroupCreateType,
|
|
||||||
} from "../../interfaces/Interfaces";
|
} from "../../interfaces/Interfaces";
|
||||||
import { useNavigation } from "@react-navigation/native";
|
import { useNavigation } from "@react-navigation/native";
|
||||||
import {
|
import {
|
||||||
|
@ -40,16 +29,15 @@ import {
|
||||||
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
||||||
import { useToast } from "react-native-toast-notifications";
|
import { useToast } from "react-native-toast-notifications";
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import CustomMapCallout from "../../components/CustomMapCallout/CustomMapCallout";
|
|
||||||
import MapRendererFar from "../../components/MapRenderer/MapRendererFar";
|
import MapRendererFar from "../../components/MapRenderer/MapRendererFar";
|
||||||
import GetDistanceFromUSTP from "../../components/GetDistance/GetDistanceFromUSTP";
|
import GetDistanceFromUSTP from "../../components/GetDistance/GetDistanceFromUSTP";
|
||||||
import { useSelector } from "react-redux";
|
import Modal from "react-native-modal";
|
||||||
import { RootState } from "../../features/redux/Store/Store";
|
import DropdownIcon from "../../icons/CaretDownIcon/CaretDownIcon";
|
||||||
|
import CaretUpIcon from "../../icons/CaretUpIcon/CaretUpIcon";
|
||||||
|
|
||||||
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
|
||||||
const map_debug = true;
|
const map_debug = true;
|
||||||
const user_state = useSelector((state: RootState) => state.user);
|
|
||||||
const navigation = useNavigation<RootDrawerParamList>();
|
const navigation = useNavigation<RootDrawerParamList>();
|
||||||
const [location, setLocation] = useState<RawLocationType | null>(null);
|
const [location, setLocation] = useState<RawLocationType | null>(null);
|
||||||
const [dist, setDist] = useState<number | null>(null);
|
const [dist, setDist] = useState<number | null>(null);
|
||||||
|
@ -59,12 +47,8 @@ export default function Home() {
|
||||||
const queryClient = useQueryClient();
|
const queryClient = useQueryClient();
|
||||||
const toast = useToast();
|
const toast = useToast();
|
||||||
|
|
||||||
const ustpCoords = {
|
const [modalOpen, setModalOpen] = useState(false);
|
||||||
latitude: 8.4857,
|
|
||||||
longitude: 124.6565,
|
|
||||||
latitudeDelta: 0.000235,
|
|
||||||
longitudeDelta: 0.000067,
|
|
||||||
};
|
|
||||||
async function requestLocation() {
|
async function requestLocation() {
|
||||||
const { status } = await Location.requestForegroundPermissionsAsync();
|
const { status } = await Location.requestForegroundPermissionsAsync();
|
||||||
if (status !== "granted") {
|
if (status !== "granted") {
|
||||||
|
@ -333,7 +317,7 @@ export default function Home() {
|
||||||
if (dist && location) {
|
if (dist && location) {
|
||||||
if (dist <= 2 || map_debug) {
|
if (dist <= 2 || map_debug) {
|
||||||
return (
|
return (
|
||||||
<View>
|
<>
|
||||||
<MapView
|
<MapView
|
||||||
style={styles.map}
|
style={styles.map}
|
||||||
customMapStyle={[
|
customMapStyle={[
|
||||||
|
@ -413,9 +397,7 @@ export default function Home() {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
)}
|
)}
|
||||||
{!StudyGroupQuery.isPaused &&
|
{studying ? (
|
||||||
!StudyGroupQuery.isRefetching &&
|
|
||||||
!StudyGroupQuery.error ? (
|
|
||||||
study_groups.map(
|
study_groups.map(
|
||||||
(studygroup: StudyGroupType, index: number) => {
|
(studygroup: StudyGroupType, index: number) => {
|
||||||
const randomColorWithOpacity = `rgba(${Math.floor(
|
const randomColorWithOpacity = `rgba(${Math.floor(
|
||||||
|
@ -697,20 +679,45 @@ export default function Home() {
|
||||||
<></>
|
<></>
|
||||||
)}
|
)}
|
||||||
</MapView>
|
</MapView>
|
||||||
<Button
|
<View
|
||||||
onPress={async () => {
|
style={{
|
||||||
if (!student_status?.active) {
|
display: "flex",
|
||||||
navigation.navigate("Start Studying", { location: location });
|
flexDirection: "row",
|
||||||
} else {
|
justifyContent: "center",
|
||||||
stop_studying.mutate({
|
|
||||||
active: false,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Text style={styles.text_white_medium}>{buttonLabel}</Text>
|
<Button
|
||||||
</Button>
|
onPress={async () => {
|
||||||
</View>
|
if (!student_status?.active) {
|
||||||
|
navigation.navigate("Start Studying", {
|
||||||
|
location: location,
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
stop_studying.mutate({
|
||||||
|
active: false,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Text style={styles.text_white_small}>{buttonLabel}</Text>
|
||||||
|
</Button>
|
||||||
|
<Pressable
|
||||||
|
style={{
|
||||||
|
display: modalOpen ? "none" : "flex",
|
||||||
|
backgroundColor: colors.secondary_3,
|
||||||
|
borderRadius: 16,
|
||||||
|
alignSelf: "center",
|
||||||
|
}}
|
||||||
|
onPress={() => {
|
||||||
|
setModalOpen(true);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<CaretUpIcon size={32} />
|
||||||
|
</Pressable>
|
||||||
|
</View>
|
||||||
|
|
||||||
|
<View style={styles.padding} />
|
||||||
|
</>
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
return <MapRendererFar location={location.coords} dist={dist} />;
|
return <MapRendererFar location={location.coords} dist={dist} />;
|
||||||
|
@ -718,17 +725,38 @@ export default function Home() {
|
||||||
} else {
|
} else {
|
||||||
requestLocation();
|
requestLocation();
|
||||||
return (
|
return (
|
||||||
<AnimatedContainer>
|
<>
|
||||||
<Text style={styles.text_white_medium}>{feedback}</Text>
|
<Text style={styles.text_white_medium}>{feedback}</Text>
|
||||||
<Button onPress={requestLocation}>
|
<Button onPress={requestLocation}>
|
||||||
<Text style={styles.text_white_medium}>Allow Access</Text>
|
<Text style={styles.text_white_medium}>Allow Access</Text>
|
||||||
</Button>
|
</Button>
|
||||||
</AnimatedContainer>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return (
|
return (
|
||||||
<View style={styles.background}>
|
<View style={styles.background}>
|
||||||
|
<Modal
|
||||||
|
coverScreen={false}
|
||||||
|
isVisible={modalOpen}
|
||||||
|
style={{ opacity: 0.85 }}
|
||||||
|
hasBackdrop={false}
|
||||||
|
useNativeDriver={true}
|
||||||
|
>
|
||||||
|
<AnimatedContainer>
|
||||||
|
<Text style={styles.text_white_medium}>Groups List</Text>
|
||||||
|
<Pressable
|
||||||
|
style={{
|
||||||
|
alignContent: "flex-start",
|
||||||
|
backgroundColor: colors.secondary_3,
|
||||||
|
borderRadius: 16,
|
||||||
|
}}
|
||||||
|
onPress={() => setModalOpen(false)}
|
||||||
|
>
|
||||||
|
<DropdownIcon size={32} />
|
||||||
|
</Pressable>
|
||||||
|
</AnimatedContainer>
|
||||||
|
</Modal>
|
||||||
<AnimatedContainer>
|
<AnimatedContainer>
|
||||||
<CustomMap />
|
<CustomMap />
|
||||||
</AnimatedContainer>
|
</AnimatedContainer>
|
||||||
|
|
|
@ -51,6 +51,7 @@ const styles = StyleSheet.create({
|
||||||
display: "flex",
|
display: "flex",
|
||||||
flexDirection: "row",
|
flexDirection: "row",
|
||||||
alignItems: "center",
|
alignItems: "center",
|
||||||
|
flexGrow: 1,
|
||||||
},
|
},
|
||||||
flex_column: {
|
flex_column: {
|
||||||
display: "flex",
|
display: "flex",
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue