mirror of
https://github.com/lemeow125/StudE-Frontend.git
synced 2024-11-17 06:19:25 +08:00
Homepage and subjects page improvements
This commit is contained in:
parent
d87f61ec08
commit
22707b8372
3 changed files with 83 additions and 20 deletions
|
@ -1,11 +1,12 @@
|
||||||
import styles, { Viewport } from "../../styles";
|
import styles, { Viewport, colors } from "../../styles";
|
||||||
import { View, Text } from "react-native";
|
import { View, Text } 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, { UrlTile } from "react-native-maps";
|
import MapView, { Callout, 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";
|
||||||
|
import { AnimatedMapView } from "react-native-maps/lib/MapView";
|
||||||
type LocationType = Location.LocationObject;
|
type LocationType = Location.LocationObject;
|
||||||
export default function Home() {
|
export default function Home() {
|
||||||
const [location, setLocation] = useState<LocationType | null>(null);
|
const [location, setLocation] = useState<LocationType | null>(null);
|
||||||
|
@ -47,6 +48,11 @@ export default function Home() {
|
||||||
return () => clearInterval(interval);
|
return () => clearInterval(interval);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Refresh when user moves location
|
||||||
|
useEffect(() => {
|
||||||
|
requestLocation();
|
||||||
|
}, [location]);
|
||||||
|
|
||||||
// Run when screen loads
|
// Run when screen loads
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
requestLocation();
|
requestLocation();
|
||||||
|
@ -67,16 +73,16 @@ export default function Home() {
|
||||||
if (dist <= 1.5) {
|
if (dist <= 1.5) {
|
||||||
// Just switch this condition for map debugging
|
// Just switch this condition for map debugging
|
||||||
return (
|
return (
|
||||||
<MapView
|
<AnimatedMapView
|
||||||
style={styles.map}
|
style={styles.map}
|
||||||
mapType="none"
|
mapType="none"
|
||||||
initialRegion={ustpCoords}
|
initialRegion={ustpCoords}
|
||||||
showsUserLocation={true}
|
|
||||||
scrollEnabled={false}
|
scrollEnabled={false}
|
||||||
zoomEnabled={false}
|
zoomEnabled={false}
|
||||||
rotateEnabled={false}
|
rotateEnabled={false}
|
||||||
followsUserLocation={true}
|
followsUserLocation={true}
|
||||||
minZoomLevel={18}
|
minZoomLevel={18}
|
||||||
|
toolbarEnabled={false}
|
||||||
customMapStyle={[
|
customMapStyle={[
|
||||||
{
|
{
|
||||||
featureType: "poi",
|
featureType: "poi",
|
||||||
|
@ -95,7 +101,13 @@ export default function Home() {
|
||||||
flipY={false}
|
flipY={false}
|
||||||
zIndex={1}
|
zIndex={1}
|
||||||
/>
|
/>
|
||||||
</MapView>
|
<Marker
|
||||||
|
coordinate={{
|
||||||
|
latitude: location.coords.latitude,
|
||||||
|
longitude: location.coords.longitude,
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</AnimatedMapView>
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
return (
|
return (
|
||||||
|
@ -104,7 +116,7 @@ export default function Home() {
|
||||||
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
|
||||||
</Text>
|
</Text>
|
||||||
<MapView
|
<AnimatedMapView
|
||||||
style={{
|
style={{
|
||||||
height: Viewport.height * 0.5,
|
height: Viewport.height * 0.5,
|
||||||
width: Viewport.width * 0.8,
|
width: Viewport.width * 0.8,
|
||||||
|
@ -121,9 +133,9 @@ export default function Home() {
|
||||||
},
|
},
|
||||||
]}
|
]}
|
||||||
mapType="none"
|
mapType="none"
|
||||||
showsUserLocation={true}
|
|
||||||
scrollEnabled={false}
|
scrollEnabled={false}
|
||||||
zoomEnabled={false}
|
zoomEnabled={false}
|
||||||
|
toolbarEnabled={false}
|
||||||
rotateEnabled={false}
|
rotateEnabled={false}
|
||||||
followsUserLocation={true}
|
followsUserLocation={true}
|
||||||
minZoomLevel={18}
|
minZoomLevel={18}
|
||||||
|
@ -141,7 +153,22 @@ export default function Home() {
|
||||||
flipY={false}
|
flipY={false}
|
||||||
zIndex={1}
|
zIndex={1}
|
||||||
/>
|
/>
|
||||||
</MapView>
|
<Marker
|
||||||
|
coordinate={{
|
||||||
|
latitude: location.coords.latitude,
|
||||||
|
longitude: location.coords.longitude,
|
||||||
|
}}
|
||||||
|
onPress={() => console.log(location)}
|
||||||
|
pinColor={colors.primary_1}
|
||||||
|
>
|
||||||
|
<Callout>
|
||||||
|
<Text style={styles.text_black_tiny}>
|
||||||
|
X: {Math.round(location.coords.longitude) + "\n"}
|
||||||
|
Z: {Math.round(location.coords.latitude)}
|
||||||
|
</Text>
|
||||||
|
</Callout>
|
||||||
|
</Marker>
|
||||||
|
</AnimatedMapView>
|
||||||
<Text style={styles.text_white_small}>
|
<Text style={styles.text_white_small}>
|
||||||
{dist}km away from USTP {"\n"}
|
{dist}km away from USTP {"\n"}
|
||||||
</Text>
|
</Text>
|
||||||
|
|
|
@ -225,20 +225,14 @@ export default function SubjectsPage() {
|
||||||
<View style={styles.padding} />
|
<View style={styles.padding} />
|
||||||
<Button
|
<Button
|
||||||
onPress={() => {
|
onPress={() => {
|
||||||
if (subjectsOpen) {
|
setSelectedSubjects([]);
|
||||||
setSelectedSubjects([]);
|
setSubjectsOpen(!subjectsOpen);
|
||||||
setSubjectsOpen(false);
|
mutation.mutate({
|
||||||
mutation.mutate({
|
subjects: selected_subjects,
|
||||||
subjects: selected_subjects,
|
});
|
||||||
});
|
|
||||||
} else {
|
|
||||||
setSubjectsOpen(true);
|
|
||||||
}
|
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Text style={styles.text_white_small}>
|
<Text style={styles.text_white_small}>Save Change</Text>
|
||||||
{subjectsOpen && StudentInfo.isSuccess ? "Save" : "Edit Subjects"}
|
|
||||||
</Text>
|
|
||||||
</Button>
|
</Button>
|
||||||
</View>
|
</View>
|
||||||
</AnimatedContainerNoScroll>
|
</AnimatedContainerNoScroll>
|
||||||
|
|
|
@ -16,6 +16,7 @@ export const colors = {
|
||||||
secondary_4: "#FFE9CE",
|
secondary_4: "#FFE9CE",
|
||||||
secondary_5: "#FFF5E9",
|
secondary_5: "#FFF5E9",
|
||||||
text_default: "#FFFF",
|
text_default: "#FFFF",
|
||||||
|
text_dark: "black",
|
||||||
text_error: "#e32d1e",
|
text_error: "#e32d1e",
|
||||||
text_success: "#2ecc71",
|
text_success: "#2ecc71",
|
||||||
icon_color: "#FFFF",
|
icon_color: "#FFFF",
|
||||||
|
@ -105,6 +106,42 @@ const styles = StyleSheet.create({
|
||||||
fontWeight: "bold",
|
fontWeight: "bold",
|
||||||
textAlign: "center",
|
textAlign: "center",
|
||||||
},
|
},
|
||||||
|
text_black_tiny: {
|
||||||
|
color: colors.text_dark,
|
||||||
|
fontSize: font_sizes.tiny,
|
||||||
|
fontWeight: "bold",
|
||||||
|
textAlign: "center",
|
||||||
|
},
|
||||||
|
text_black_small: {
|
||||||
|
color: colors.text_dark,
|
||||||
|
fontSize: font_sizes.small,
|
||||||
|
fontWeight: "bold",
|
||||||
|
textAlign: "center",
|
||||||
|
},
|
||||||
|
text_black_medium: {
|
||||||
|
color: colors.text_dark,
|
||||||
|
fontSize: font_sizes.medium,
|
||||||
|
fontWeight: "bold",
|
||||||
|
textAlign: "center",
|
||||||
|
},
|
||||||
|
text_black_medium_large: {
|
||||||
|
color: colors.text_dark,
|
||||||
|
fontSize: font_sizes.medium_large,
|
||||||
|
fontWeight: "bold",
|
||||||
|
textAlign: "center",
|
||||||
|
},
|
||||||
|
text_black_large: {
|
||||||
|
color: colors.text_dark,
|
||||||
|
fontSize: font_sizes.large,
|
||||||
|
fontWeight: "bold",
|
||||||
|
textAlign: "center",
|
||||||
|
},
|
||||||
|
text_black_xl: {
|
||||||
|
color: colors.text_dark,
|
||||||
|
fontSize: font_sizes.xl,
|
||||||
|
fontWeight: "bold",
|
||||||
|
textAlign: "center",
|
||||||
|
},
|
||||||
button_template: {
|
button_template: {
|
||||||
justifyContent: "center",
|
justifyContent: "center",
|
||||||
alignSelf: "center",
|
alignSelf: "center",
|
||||||
|
@ -158,5 +195,10 @@ const styles = StyleSheet.create({
|
||||||
padding: {
|
padding: {
|
||||||
paddingVertical: 8,
|
paddingVertical: 8,
|
||||||
},
|
},
|
||||||
|
calloutContainer: {
|
||||||
|
backgroundColor: colors.secondary_1,
|
||||||
|
padding: 0,
|
||||||
|
border: 0,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
export default styles;
|
export default styles;
|
||||||
|
|
Loading…
Reference in a new issue