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
2 changes: 1 addition & 1 deletion app/app.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export default ({ config }: ConfigContext): ExpoConfig => ({
...config,
slug: "Lakbayan",
name: "Lakbayan",
version: "1.0.0",
version: "1.0.1",
orientation: "portrait",
scheme: "myapp",
userInterfaceStyle: "automatic",
Expand Down
9 changes: 3 additions & 6 deletions app/src/app/(account)/bookmarked-trips.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
ActivityIndicator,
Text,
TouchableOpacity,
BackHandler
BackHandler,
} from "react-native";
import { useRouter } from "expo-router";
import { useFocusEffect } from "@react-navigation/native";
Expand All @@ -33,7 +33,7 @@ export default function BookmarkedTrips() {
postSegment: null,
};

router.push({
router.replace({
pathname: "/(search)/3-trip-overview",
params: { tripData: JSON.stringify(tripSearch), from: "bookmarked-trips" },
});
Expand All @@ -51,10 +51,7 @@ export default function BookmarkedTrips() {
return true;
};

const backHandler = BackHandler.addEventListener(
"hardwareBackPress",
backAction,
);
const backHandler = BackHandler.addEventListener("hardwareBackPress", backAction);

return () => backHandler.remove();
}, []),
Expand Down
9 changes: 3 additions & 6 deletions app/src/app/(account)/submitted-trips.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export default function SubmittedTrips() {
const { submittedTrips, loading } = useSubmittedTrips(user?.id || null);

function handleTripPress(trip: TripSearch) {
router.push({
router.replace({
pathname: "/(search)/3-trip-overview",
params: { tripData: JSON.stringify(trip), from: "submitted-trips" },
});
Expand All @@ -43,18 +43,15 @@ export default function SubmittedTrips() {
return true;
};

const backHandler = BackHandler.addEventListener(
"hardwareBackPress",
backAction,
);
const backHandler = BackHandler.addEventListener("hardwareBackPress", backAction);

return () => backHandler.remove();
}, []),
);

return (
<SafeAreaView className="flex-1">
<Header title="Submitted Trips" prevCallback={prevCallback}/>
<Header title="Submitted Trips" prevCallback={prevCallback} />
<View className="flex-1 px-4">
{loading ? (
<ActivityIndicator size="small" testID="activity-indicator" />
Expand Down
26 changes: 20 additions & 6 deletions app/src/app/(contribute)/2-review-trip.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useEffect } from "react";
import React, { useState } from "react";
import { router } from "expo-router";
import { useFocusEffect } from "@react-navigation/native";
import { SafeAreaView, View, Alert, BackHandler } from "react-native";
import { ActivityIndicator, SafeAreaView, View, Alert, Text, BackHandler } from "react-native";

import Header from "@components/ui/Header";
import LineSource from "@components/map/LineSource";
Expand All @@ -22,6 +22,7 @@ import {
fetchSubmitLogId,
deleteSubmitLog,
} from "@services/logs-service";
import { set } from "lodash";

export default function TripReview() {
const { user } = useSession();
Expand All @@ -38,6 +39,9 @@ export default function TripReview() {
clearRouteData,
submitTrip,
} = useTripCreator();

const [isSubmitting, setIsSubmitting] = useState(false);

if (!user) throw new Error("User must be logged in to create a trip!");

const handleCreateSegment = async () => {
Expand All @@ -59,18 +63,20 @@ export default function TripReview() {
};

const handleSubmitTrip = async () => {
setIsSubmitting(true);
try {
await submitTrip();
Alert.alert("Trip Submitted", "Your trip has been submitted successfully!");
const id = await fetchSubmitLogId({ userId: user.id });
if (!id) {
console.error("No submit log ID found.");
return;
}

await updateSubmitLog({ id, status: "completed" });
Alert.alert("Trip Submitted", "Your trip has been submitted successfully!");
setIsSubmitting(false);
router.replace("/(tabs)");
} catch (error) {
setIsSubmitting(false);
Alert.alert("Error", "Failed to submit your trip. Please try again.");
}
};
Expand Down Expand Up @@ -113,7 +119,7 @@ export default function TripReview() {
});

return (
<SafeAreaView style={{ flex: 1 }}>
<SafeAreaView className="flex-1 relative">
<Header prevCallback={prevCallback} title="Trip Review" />

<View className="flex justify-center items-center">
Expand All @@ -132,12 +138,20 @@ export default function TripReview() {
deleteSegment={handleDeleteSegment}
/>

<View className="absolute bottom-0 z-50 p-5 w-full justify-center">
<View className="absolute bottom-0 p-5 w-full justify-center">
<PrimaryButton
label={isSegmentComplete ? "Submit" : "Add Transfers"}
onPress={isSegmentComplete ? handleSubmitTrip : handleCreateSegment}
disabled={!isSubmitting}
/>
</View>

{isSubmitting && (
<View className="absolute inset-0 bg-black/50 justify-center items-center z-50">
<ActivityIndicator size="large" color="#fff" />
<Text className="text-lg text-white">Submitting trip, please wait...</Text>
</View>
)}
</SafeAreaView>
);
}
8 changes: 7 additions & 1 deletion app/src/app/(contribute)/3-add-transfer.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { useMemo } from "react";
import { router } from "expo-router";
import { SafeAreaView, View, Alert, BackHandler } from "react-native";
import { useFocusEffect } from "@react-navigation/native";
Expand Down Expand Up @@ -54,13 +55,18 @@ export default function RouteSelectInfo() {
return () => backHandler.remove();
});

const memoizedEnd: [string | null, [number, number] | null] = useMemo(
() => [route.endLocation ?? null, route.endCoords ?? null],
[route.endLocation, route.endCoords],
);

return (
<SafeAreaView style={{ flex: 1 }}>
<Header prevCallback={prevCallback} title="Route Information" />
<StartEndSearchBar
isStartActive={false}
start={[route.startLocation, route.endCoords]}
end={[route.endLocation, route.endCoords]}
end={memoizedEnd}
onEndChange={(l, c) => handleEndChange(c, l)}
/>
<MapShell
Expand Down
2 changes: 2 additions & 0 deletions app/src/app/(contribute)/4-edit-transfer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ export default function RouteInput() {
setSubmitting(false);
return;
}
console.log("Submitted route name: ", route.segmentName);
try {
await addSegment();
clearRouteData();
Expand Down Expand Up @@ -169,6 +170,7 @@ export default function RouteInput() {
sheetRef={bottomSheetRef}
handleSubmit={handleSubmit}
setIsEditingWaypoints={setIsEditingWaypoints}
isEditing={editingIndex !== -1}
/>
</SafeAreaView>
);
Expand Down
9 changes: 9 additions & 0 deletions app/src/app/(contribute)/toda-stops.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export default function TodaStops() {
const [stops, setStops] = useState<StopData[]>([]);
const [loadingStops, setLoadingStops] = useState(false);
const [formSnapshot, setFormSnapshot] = useState("");
const [isSubmitting, setIsSubmitting] = useState(false);

const loadStops = async () => {
setLoadingStops(true);
Expand Down Expand Up @@ -114,7 +115,15 @@ export default function TodaStops() {
coordinates={coordinates}
onNewStopAdded={loadStops}
onFormChange={(form) => setFormSnapshot(JSON.stringify(form))}
setIsSubmitting={setIsSubmitting}
isSubmitting={isSubmitting}
/>
{isSubmitting && (
<View className="absolute inset-0 bg-black/50 justify-center items-center z-50">
<ActivityIndicator size="large" color="#fff" />
<Text className="text-lg text-white">Submitting TODA stop, please wait...</Text>
</View>
)}
</SafeAreaView>
);
}
33 changes: 24 additions & 9 deletions app/src/app/(journal)/journal-review.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useRouter } from "expo-router";
import React, { useState, useCallback } from "react";
import { SafeAreaView, Alert, BackHandler } from "react-native";
import { SafeAreaView, Alert, BackHandler, View, ActivityIndicator, Text } from "react-native";
import { useFocusEffect } from "@react-navigation/native";

import Header from "@components/ui/Header";
Expand All @@ -26,7 +26,8 @@ export default function JournalReview() {
const router = useRouter();
const { user } = useSession();
const { cameraRef } = useMapView();
const { trip, segments, transitJournal, rating, hasDeviated, setRating, setHasDeviated } = useTransitJournal();
const { trip, segments, transitJournal, rating, hasDeviated, setRating, setHasDeviated } =
useTransitJournal();
const [newComment, setNewComment] = useState("");
const [isSubmitting, setIsSubmitting] = useState(false);

Expand All @@ -39,8 +40,14 @@ export default function JournalReview() {

const handleSubmit = async () => {
setIsSubmitting(true);
if (!newComment.trim()) { setIsSubmitting(false); return; }
if (!trip || !segments || !user) { setIsSubmitting(false); return; }
if (!newComment.trim()) {
setIsSubmitting(false);
return;
}
if (!trip || !segments || !user) {
setIsSubmitting(false);
return;
}

const journalPayload: Partial<TransitJournal> = {
id: transitJournal.id,
Expand All @@ -56,7 +63,10 @@ export default function JournalReview() {

// // if did not deviate, increment GPS count
if (!Boolean(hasDeviated)) {
await incrementSegmentGPSCount(trip.segments.map(({ id }) => id), !Boolean(hasDeviated));
await incrementSegmentGPSCount(
trip.segments.map(({ id }) => id),
!Boolean(hasDeviated),
);
}
await updateTransitJournal(journalPayload);
await updateProfile({ id: user.id, transitJournalId: null });
Expand All @@ -65,6 +75,7 @@ export default function JournalReview() {
setIsSubmitting(false);
router.replace("/(tabs)");
} catch (error) {
setIsSubmitting(false);
Alert.alert("Error", "Failed to submit your transit journal. Please try again.");
}
};
Expand All @@ -88,10 +99,7 @@ export default function JournalReview() {
return true;
};

const backHandler = BackHandler.addEventListener(
"hardwareBackPress",
backAction,
);
const backHandler = BackHandler.addEventListener("hardwareBackPress", backAction);

return () => backHandler.remove();
}, []),
Expand Down Expand Up @@ -122,6 +130,13 @@ export default function JournalReview() {
setHasDeviated={setHasDeviated}
isSubmitting={isSubmitting}
/>

{isSubmitting && (
<View className="absolute inset-0 bg-black/50 justify-center items-center z-50">
<ActivityIndicator size="large" color="#fff" />
<Text className="text-lg text-white">Submitting trip, please wait...</Text>
</View>
)}
</SafeAreaView>
);
}
2 changes: 1 addition & 1 deletion app/src/app/(search)/1-search-trip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export default function SearchTrip() {
}
try {
await fetchSuggestedTrips();
router.push("/(search)/2-trip-suggestions");
router.replace("/(search)/2-trip-suggestions");
} catch (error) {
Alert.alert("Error fetching trips. Please try again.");
}
Expand Down
11 changes: 6 additions & 5 deletions app/src/app/(search)/2-trip-suggestions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { useEffect, useRef } from "react";
import { useRouter } from "expo-router";
import BottomSheet from "@gorhom/bottom-sheet";
import { Text, SafeAreaView, View, Pressable } from "react-native";
import { MaterialIcons } from "@expo/vector-icons";

import Header from "@components/ui/Header";
import TripPreview from "@components/ui/TripPreview";
Expand Down Expand Up @@ -47,9 +46,10 @@ export default function SuggestedTrips() {
}
}, []);

const handleSelectTrip = (trip: TripSearch) => {
const handleSelectTrip = (trip: TripSearch, index: number) => {
setTrip(trip);
router.push("/(search)/3-trip-overview");
console.log(`Selected trip: ${trip.id} with index ${index}`);
router.replace("/(search)/3-trip-overview");
};

const handleOpenFilters = () => filterSheetRef.current?.snapToIndex(1);
Expand All @@ -70,10 +70,11 @@ export default function SuggestedTrips() {
</View>
) : (
<ScrollView className="flex-1 p-4" showsVerticalScrollIndicator={false}>
{filteredTrips.map((trip) => (
{filteredTrips.map((trip, index) => (
<Pressable
key={`${trip.id}-${filters.timeToLeave}`}
onPress={() => handleSelectTrip(trip)}
onPress={() => handleSelectTrip(trip, index)}
android_ripple={{ color: "#ccc" }}
>
<TripPreview trip={trip} timeToLeave={filters.timeToLeave} />
</Pressable>
Expand Down
17 changes: 14 additions & 3 deletions app/src/app/(social)/comments-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { getComments, addComment } from "@services/socials-service";
import Header from "@components/ui/Header";
import CommentItem from "@components/ui/CommentItem";
import PrimaryButton from "@components/ui/PrimaryButton";
import { set } from "lodash";

export default function CommentsList() {
const { user } = useSession();
Expand All @@ -18,6 +19,7 @@ export default function CommentsList() {
const [comments, setComments] = useState<CommentData[]>([]);
const [content, setContent] = useState("");
const [loading, setLoading] = useState(false);
const [isSubmitting, setIsSubmitting] = useState(false);

useEffect(() => {
async function fetchComments() {
Expand All @@ -36,14 +38,19 @@ export default function CommentsList() {
}, [tripId]);

const handleCommentSubmit = async () => {
if (!content.trim()) return;

setIsSubmitting(true);
if (!content.trim()) {
setIsSubmitting(false);
return;
}
try {
await addComment(tripId, user?.id || "", content, isGpsVerified);
const updatedComments = await getComments(tripId);
setComments(updatedComments || []);
setContent("");
setIsSubmitting(false);
} catch (error) {
setIsSubmitting(false);
console.error("Error adding comment:", error);
}
};
Expand Down Expand Up @@ -84,7 +91,11 @@ export default function CommentsList() {
className="flex-1 border border-gray-200 rounded-lg px-3"
testID="comment-input"
/>
<PrimaryButton label="Post" onPress={handleCommentSubmit} />
<PrimaryButton
label="Post"
onPress={handleCommentSubmit}
disabled={isSubmitting || !content}
/>
</View>
</View>
</SafeAreaView>
Expand Down
Loading
Loading