Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions app/src/app/(contribute)/4-edit-transfer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,9 @@ export default function RouteInput() {
}
};

const handleResetWaypoints = () => {
setCustomWaypoint([]);
const handleUndoWaypoint = () => {
if (customWaypoints.length === 0) return;
setCustomWaypoint((prev) => prev.slice(0, -1));
updateRoute({ ...route, duration: 0, distance: 0, waypoints: [], navigationSteps: [] });
};

Expand Down Expand Up @@ -157,7 +158,7 @@ export default function RouteInput() {
<View className="flex flex-col w-full justify-between gap-5">
<View className="flex flex-row justify-center gap-5">
<PrimaryButtonOutline onPress={handleProcessRoute}>Calculate</PrimaryButtonOutline>
<PrimaryButtonOutline onPress={handleResetWaypoints}>Clear</PrimaryButtonOutline>
<PrimaryButtonOutline onPress={handleUndoWaypoint}>Undo</PrimaryButtonOutline>
</View>
<PrimaryButton label="Done" onPress={handleCompleteEditing} />
</View>
Expand Down
38 changes: 16 additions & 22 deletions app/src/app/(search)/3-trip-overview.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { useEffect, useState, useCallback } from "react";
import { ActivityIndicator, Alert, BackHandler, SafeAreaView, Text, View } from "react-native";
import { useLocalSearchParams, useRouter, useFocusEffect } from "expo-router";
import { useLocalSearchParams, useRouter } from "expo-router";
import { useFocusEffect } from "@react-navigation/native";


import Header from "@components/ui/Header";
import { MapShell } from "@components/map/MapShell";
Expand All @@ -10,6 +12,7 @@ import SymbolMarker from "@components/map/SymbolMarker";
import SymbolSource from "@components/map/SymbolSource";
import TripSummary from "@components/search/TripSummary";

import "@contexts/LocationContext";
import { useMapView } from "@hooks/use-map-view";
import { useTripSearch } from "@contexts/TripSearchContext";
import { useSession } from "@contexts/SessionContext";
Expand Down Expand Up @@ -84,20 +87,16 @@ export default function TripOverview() {
};
await updateSearchLog(logsPayload);

} catch (error) {
Alert.alert("Error starting trip, please try again");
setHasError(true);
}
}

useEffect(() => {
if (!!transitJournalId && !hasError) {
router.replace({
pathname: "/(journal)/transit-journal",
params: { journalReview: "no" },
});

} catch (error) {
Alert.alert("Error starting trip, please try again");
setHasError(true);
}
}, [transitJournalId]);
}

useEffect(() => {
if (!trip.segments) return;
Expand Down Expand Up @@ -127,19 +126,14 @@ export default function TripOverview() {
router.replace("/(search)/2-trip-suggestions");
};

useFocusEffect(
useCallback(() => {
const onBackPress = () => {
if (loadingTrip || !doneLiveStatus) return true;
router.replace("/(search)/2-trip-suggestions");
return true;
};

BackHandler.addEventListener("hardwareBackPress", onBackPress);
useFocusEffect(() => {
const backHandler = BackHandler.addEventListener("hardwareBackPress", () => {
prevCallback();
return true;
});
return () => backHandler.remove();
});

return () => BackHandler.removeEventListener("hardwareBackPress", onBackPress);
}, [loadingTrip]),
);

if(!doneLiveStatus) {
return (
Expand Down
Binary file modified app/src/assets/tab-account.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 4 additions & 1 deletion app/src/components/contribute/RouteInformation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export default function RouteInformation({

const handleEditRoute = () => {
setIsEditingWaypoints(true);
updateRoute({ ...route, duration: 0, distance: 0, waypoints: [], navigationSteps: [] });
sheetRef.current?.close();
};

Expand Down Expand Up @@ -73,12 +74,14 @@ export default function RouteInformation({
</View>
</View>
<OutlinedTextInput
label="Landmark"
label="Landmark of destination"
placeholder="e.g., Near Jollibee Katipunan or beside LRT Station"
value={route.landmark ?? ""}
onChangeText={(landmark) => updateRoute({ landmark })}
/>
<OutlinedTextInput
label="Instruction"
placeholder="e.g., Ride the jeep labeled 'Cubao' and get off at the destination"
value={route.instruction ?? ""}
onChangeText={(instruction) => updateRoute({ instruction })}
/>
Expand Down
69 changes: 51 additions & 18 deletions app/src/contexts/LocationContext.tsx
Original file line number Diff line number Diff line change
@@ -1,43 +1,65 @@
import * as ExpoLocation from "expo-location";
import { createContext, useContext, useState, useEffect, ReactNode } from "react";
import { AppState } from "react-native";
import { Alert } from "react-native";

// Define the context type
interface LocationContextType {
userLocation: Coordinates | null;
permissionGranted: boolean;
requestLocationPermission: () => Promise<string>;
}

// Create context with default values
export const LocationContext = createContext<LocationContextType>({
userLocation: null,
permissionGranted: false,
requestLocationPermission: async () => "",
});

// Provider component
export const LocationProvider: React.FC<{ children: ReactNode }> = ({ children }) => {
const [userLocation, setUserLocation] = useState<Coordinates | null>(null);
const [permissionGranted, setPermissionGranted] = useState(false);

const checkPermission = async () => {
const { status } = await ExpoLocation.getForegroundPermissionsAsync();
setPermissionGranted(status === "granted");
return status;
};

const requestLocationPermission = async () => {
const { status } = await ExpoLocation.requestForegroundPermissionsAsync();
await checkPermission();
return status;
};

// On mount
useEffect(() => {
(async () => {
try {
const { status: foregroundStatus } = await ExpoLocation.requestForegroundPermissionsAsync();
await requestLocationPermission();
})();
}, []);

if (foregroundStatus === "granted") {
setPermissionGranted(true);
const location = await ExpoLocation.getCurrentPositionAsync({});
const newCoords: Coordinates = [location.coords.longitude, location.coords.latitude];
setUserLocation(newCoords);
} else {
console.warn("Permission denied");
}
} catch (error) {
console.error("Error getting location:", error);
// Refresh permission when app returns from background
useEffect(() => {
const subscription = AppState.addEventListener("change", (state) => {
if (state === "active") {
checkPermission();
}
})();
});
return () => subscription.remove();
}, []);

// add a listener to update user location when it changes
// Update location if permission is granted
useEffect(() => {
const getLocation = async () => {
if (permissionGranted) {
const location = await ExpoLocation.getCurrentPositionAsync({});
const coords: Coordinates = [location.coords.longitude, location.coords.latitude];
setUserLocation(coords);
}
};
getLocation();
}, [permissionGranted]);

useEffect(() => {
const watchLocation = async () => {
if (permissionGranted) {
Expand All @@ -55,7 +77,7 @@ export const LocationProvider: React.FC<{ children: ReactNode }> = ({ children }
}, [permissionGranted]);

return (
<LocationContext.Provider value={{ userLocation, permissionGranted }}>
<LocationContext.Provider value={{ userLocation, permissionGranted, requestLocationPermission }}>
{children}
</LocationContext.Provider>
);
Expand All @@ -66,5 +88,16 @@ export const useUserLocation = (): LocationContextType => {
if (!context) {
throw new Error("useLocation must be used within a LocationProvider");
}
if (!context.permissionGranted){
Alert.alert(
"Location Permission Required",
"Lakbayan needs access to your location to function properly. Please go to your device's settings to enable it.",
[
{
text: "OK",
},
],
);
}
return context;
};
6 changes: 0 additions & 6 deletions app/src/contexts/TransitJournalContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -204,12 +204,6 @@ export function TransitJournalProvider({ children }: { children: ReactNode }) {
setLastTripFinishedTime(now);
setShowNextSegmentModal(false);
setShowTripFinishedModal(true);
} else {
if (now - lastTripFinishedTime < FINISHED_MODAL_COOLDOWN) {
console.log('⏱ Trip finished cooldown active');
} else {
console.log('🛣 Still far from destination');
}
}

// update the active segments and step information
Expand Down
Loading