From de97dca9d31727cea085588f981294da6c71ea01 Mon Sep 17 00:00:00 2001 From: Keannu Bernasol Date: Wed, 19 Jul 2023 17:20:29 +0800 Subject: [PATCH] Improved homepage --- src/components/Button/Button.tsx | 5 +- src/routes/Home/Home.tsx | 88 ++++++++++++++++++-------------- src/styles.tsx | 18 +++---- 3 files changed, 61 insertions(+), 50 deletions(-) diff --git a/src/components/Button/Button.tsx b/src/components/Button/Button.tsx index 68ae767..ee36630 100644 --- a/src/components/Button/Button.tsx +++ b/src/components/Button/Button.tsx @@ -1,7 +1,7 @@ import * as React from "react"; import { Pressable, GestureResponderEvent } from "react-native"; import styles from "../../styles"; - +import { colors } from "../../styles"; export interface props { children: React.ReactNode; onPress: (event: GestureResponderEvent) => void; @@ -10,6 +10,9 @@ export interface props { } export default function Button({ disabled = false, ...props }: props) { + if (!props.color) { + props.color = colors.secondary_3; + } return ( { - startActivityAsync(ActivityAction.LOCATION_SOURCE_SETTINGS); - }, 3000); - console.log("Location Permission denied"); - } - } - - async function getLocation() { - let location = await Location.getCurrentPositionAsync({}); - setLocation(location); - let dist = GetDistance( - location.coords.latitude, - location.coords.longitude, - 8.4857, - 124.6565 - ); - setDist(Math.round(dist)); - } - useEffect(() => { - requestLocation(); - }, []); - const ustpCoords = { latitude: 8.4857, longitude: 124.6565, latitudeDelta: 0.000235, longitudeDelta: 0.000067, }; + + async function requestLocation() { + let { status } = await Location.requestForegroundPermissionsAsync(); + if (status !== "granted") { + setFeedback( + "Permission to access location was denied. Please allow permission" + ); + return; + } + if (status == "granted") { + let location = await Location.getCurrentPositionAsync({}); + if (location) { + setLocation(location); + getDistance(location); + } + } + } + useEffect(() => { + requestLocation(); + }, [location]); + + async function getDistance(location: LocationType) { + let dist = GetDistance( + location.coords.latitude, + location.coords.longitude, + 8.4857, // LatitudeDelta + 124.6565 // LongitudeDelta + ); + setDist(Math.round(dist)); + } + function CustomMap() { - if (dist !== null && location !== null) { + if (dist && location) { if (dist <= 1.5) { // Just switch this condition for map debugging - return ; + return ( + + ); } else { return ( @@ -68,8 +79,8 @@ export default function Home() { {feedback} - ); } } - const creds = useSelector((state: RootState) => state.user.user); return ( diff --git a/src/styles.tsx b/src/styles.tsx index 3618d22..0767444 100644 --- a/src/styles.tsx +++ b/src/styles.tsx @@ -1,10 +1,9 @@ import { StyleSheet, Dimensions } from "react-native"; -const width = Dimensions.get("window").width; -const height = Dimensions.get("window").height; - -const containerWidth = width - width * 0.08; -const containerHeight = height - height * 0.01; +export const Viewport = { + width: Dimensions.get("window").width, + height: Dimensions.get("window").height, +}; export const colors = { primary_1: "#1C2C3F", @@ -117,7 +116,7 @@ const styles = StyleSheet.create({ marginHorizontal: 8, padding: 8, borderRadius: 16, - width: width * 0.4, + width: Viewport.width * 0.4, }, text_input: { color: colors.text_default, @@ -126,7 +125,7 @@ const styles = StyleSheet.create({ borderWidth: 1, padding: 10, borderRadius: 8, - width: width * 0.5, + width: Viewport.width * 0.5, }, dropdown_template: { backgroundColor: colors.primary_2, @@ -135,9 +134,8 @@ const styles = StyleSheet.create({ width: "70%", }, map: { - flex: 1, - height: containerHeight, - width: containerWidth, + height: Viewport.height * 0.8, + width: Viewport.width * 0.8, alignSelf: "center", }, profile: {