diff --git a/app/(auth)/sign-in.tsx b/app/(auth)/sign-in.tsx index c2a9da4..4512c65 100644 --- a/app/(auth)/sign-in.tsx +++ b/app/(auth)/sign-in.tsx @@ -27,7 +27,7 @@ const SignIn = () => { if (signInAttempt.status === "complete") { await setActive({ session: signInAttempt.createdSessionId }); - router.push("/"); + router.replace("/"); } else { Alert.alert("Error", "Invalid email or password."); setForm((prevForm) => ({ diff --git a/app/(root)/(tabs)/home.tsx b/app/(root)/(tabs)/home.tsx index 0d11eca..65171bf 100644 --- a/app/(root)/(tabs)/home.tsx +++ b/app/(root)/(tabs)/home.tsx @@ -1,5 +1,6 @@ -import { useUser } from "@clerk/clerk-expo"; +import { useAuth, useUser } from "@clerk/clerk-expo"; import * as Location from "expo-location"; +import { router } from "expo-router"; import { useEffect, useState } from "react"; import { ActivityIndicator, @@ -16,127 +17,22 @@ import { Map } from "@/components/map"; import { RideCard } from "@/components/ride-card"; import { icons, images } from "@/constants"; import { useLocationStore } from "@/store"; -import { router } from "expo-router"; - -const recentRides = [ - { - ride_id: "1", - origin_address: "Kathmandu, Nepal", - destination_address: "Pokhara, Nepal", - origin_latitude: 27.717245, - origin_longitude: 85.323961, - destination_latitude: 28.209583, - destination_longitude: 83.985567, - ride_time: 391, - fare_price: 19500.0, - payment_status: "paid", - driver_id: 2, - user_id: "1", - user_email: "betatesteruserr@gmail.com", - created_at: "2024-08-12 05:19:20.620007", - driver: { - driver_id: "2", - first_name: "David", - last_name: "Brown", - profile_image_url: - "https://ucarecdn.com/6ea6d83d-ef1a-483f-9106-837a3a5b3f67/-/preview/1000x666/", - car_image_url: - "https://ucarecdn.com/a3872f80-c094-409c-82f8-c9ff38429327/-/preview/930x932/", - car_seats: 5, - rating: "4.60", - }, - }, - { - ride_id: "2", - origin_address: "Jalkot, MH", - destination_address: "Pune, Maharashtra, India", - origin_latitude: 18.609116, - origin_longitude: 77.165873, - destination_latitude: 18.52043, - destination_longitude: 73.856744, - ride_time: 491, - fare_price: 24500.0, - payment_status: "paid", - driver_id: 1, - user_id: "1", - user_email: "betatesteruserr@gmail.com", - created_at: "2024-08-12 06:12:17.683046", - driver: { - driver_id: "1", - first_name: "James", - last_name: "Wilson", - profile_image_url: - "https://ucarecdn.com/dae59f69-2c1f-48c3-a883-017bcf0f9950/-/preview/1000x666/", - car_image_url: - "https://ucarecdn.com/a2dc52b2-8bf7-4e49-9a36-3ffb5229ed02/-/preview/465x466/", - car_seats: 4, - rating: "4.80", - }, - }, - { - ride_id: "3", - origin_address: "Zagreb, Croatia", - destination_address: "Rijeka, Croatia", - origin_latitude: 45.815011, - origin_longitude: 15.981919, - destination_latitude: 45.327063, - destination_longitude: 14.442176, - ride_time: 124, - fare_price: 6200.0, - payment_status: "paid", - driver_id: 1, - user_id: "1", - user_email: "betatesteruserr@gmail.com", - created_at: "2024-08-12 08:49:01.809053", - driver: { - driver_id: "1", - first_name: "James", - last_name: "Wilson", - profile_image_url: - "https://ucarecdn.com/dae59f69-2c1f-48c3-a883-017bcf0f9950/-/preview/1000x666/", - car_image_url: - "https://ucarecdn.com/a2dc52b2-8bf7-4e49-9a36-3ffb5229ed02/-/preview/465x466/", - car_seats: 4, - rating: "4.80", - }, - }, - { - ride_id: "4", - origin_address: "Okayama, Japan", - destination_address: "Osaka, Japan", - origin_latitude: 34.655531, - origin_longitude: 133.919795, - destination_latitude: 34.693725, - destination_longitude: 135.502254, - ride_time: 159, - fare_price: 7900.0, - payment_status: "paid", - driver_id: 3, - user_id: "1", - user_email: "betatesteruserr@gmail.com", - created_at: "2024-08-12 18:43:54.297838", - driver: { - driver_id: "3", - first_name: "Michael", - last_name: "Johnson", - profile_image_url: - "https://ucarecdn.com/0330d85c-232e-4c30-bd04-e5e4d0e3d688/-/preview/826x822/", - car_image_url: - "https://ucarecdn.com/289764fb-55b6-4427-b1d1-f655987b4a14/-/preview/930x932/", - car_seats: 4, - rating: "4.70", - }, - }, -]; +import { useFetch } from "@/lib/fetch"; +import type { Ride } from "@/types/type"; const Home = () => { const { setUserLocation, setDestinationLocation } = useLocationStore(); + const { signOut } = useAuth(); const { user } = useUser(); - const isLoading = false; + const { data: recentRides, loading } = useFetch(`/(api)/ride/${user?.id}`); const [hasPermissions, setHasPermissions] = useState(false); - const handleSignOut = () => {}; + const handleSignOut = () => { + signOut(); + + router.replace("/(auth)/sign-in"); + }; const handleDestinationPress = (location: { latitude: number; longitude: number; @@ -153,6 +49,8 @@ const Home = () => { if (status !== "granted") return setHasPermissions(false); + setHasPermissions(true); + let location = await Location.getCurrentPositionAsync(); const address = await Location.reverseGeocodeAsync({ @@ -173,7 +71,7 @@ const Home = () => { return ( } className="px-5" keyboardShouldPersistTaps="handled" @@ -182,7 +80,7 @@ const Home = () => { }} ListEmptyComponent={() => ( - {!isLoading ? ( + {!loading ? ( <> { - + {hasPermissions && }