Skip to content

Commit

Permalink
join trip
Browse files Browse the repository at this point in the history
  • Loading branch information
agjini committed Jun 6, 2024
1 parent 2b91e02 commit d9c73d2
Show file tree
Hide file tree
Showing 20 changed files with 162 additions and 125 deletions.
1 change: 0 additions & 1 deletion app/native-modules/geolocation/android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ export class AndroidService implements LianeGeolocation {
const status = await request(
this.Platform.Version === 29 ? PERMISSIONS.ANDROID.ACCESS_BACKGROUND_LOCATION : PERMISSIONS.ANDROID.ACCESS_FINE_LOCATION
);
//console.log(status);
if (status === "granted") {
return true;
} else {
Expand Down
16 changes: 8 additions & 8 deletions app/src/api/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { AppStorage as CommonAppStorage, AuthResponse, AuthUser, FullUser, Geolo
export type AppSettings = Readonly<{
"map.lianeTrafficAsWidth": boolean;
"map.lianeTrafficAsColor": boolean;
geolocation: GeolocationLevel | null;
geolocation?: GeolocationLevel;
}>;

export class ReactNativeStorage implements CommonAppStorage {
Expand Down Expand Up @@ -139,15 +139,15 @@ export class ReactNativeStorage implements CommonAppStorage {
}

getSettings() {
return this.retrieveAsync<AppSettings>("settings", { "map.lianeTrafficAsWidth": false, "map.lianeTrafficAsColor": false, geolocation: null });
return this.retrieveAsync<AppSettings>("settings", {
"map.lianeTrafficAsWidth": false,
"map.lianeTrafficAsColor": false,
geolocation: undefined
});
}

async getSetting<T extends keyof AppSettings>(name: T): Promise<AppSettings[T]> {
const setting = (await this.getSettings())?.[name];
if (setting === undefined) {
throw new Error("Setting not found: " + name);
}
return setting;
async getSetting<T extends keyof AppSettings>(name: T): Promise<AppSettings[T] | undefined> {
return (await this.getSettings())?.[name];
}

async saveSetting<T extends keyof AppSettings>(name: T, value: AppSettings[T]) {
Expand Down
3 changes: 0 additions & 3 deletions app/src/components/WheelPicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ export const WheelPicker: React.FC<Props> = ({
let index = Math.floor(Math.floor(offsetY) / itemHeight);

if (index <= 0 && offsetY <= 0) {
// console.log("shouldT", options.length, oldVal.current, index);
oldVal.current = options.length;
flatListRef.current?.scrollToOffset({
animated: false,
Expand Down Expand Up @@ -149,9 +148,7 @@ export const WheelPicker: React.FC<Props> = ({
* This ensures that what the user sees as selected in the picker always corresponds to the value state.
*/
useEffect(() => {
// console.log(selectedIndex, oldVal.current, "->", options.length);
if (selectedIndex !== oldVal.current) {
// console.log("o");
flatListRef.current?.scrollToIndex({
index: selectedIndex,
animated: true
Expand Down
1 change: 0 additions & 1 deletion app/src/components/map/AppMapView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ const AppMapView = forwardRef(
const b = await mapRef.current?.getVisibleBounds()!;
const ne = await mapRef.current?.getPointInView(b[0])!;
const sw = await mapRef.current?.getPointInView(b[1])!;
//console.log(ne, sw);
return mapRef.current?.queryRenderedFeaturesInRect([sw[1] * scale, ne[0] * scale, 0, 0], filter, layersId);
}
},
Expand Down
1 change: 0 additions & 1 deletion app/src/components/map/layers/LianeMatchRouteLayer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ export const LianeMatchRouteLayer = (props: { match: LianeMatch; to?: RallyingPo
return trip.wayPoints; //.slice(trip.departureIndex, trip.arrivalIndex + 1);
}, [fromPoint, match, toPoint]);

//console.log(to, from, wayPoints);
const { data, isLoading } = useQuery(["match", from?.id, to?.id!, match.trip.id!], () => {
const wp = [...(isSamePickup ? [] : [from!.location]), ...wayPoints.map(w => w.rallyingPoint.location), ...(isSameDeposit ? [] : [to!.location])];

Expand Down
48 changes: 39 additions & 9 deletions app/src/components/trip/TripSurveyView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@ import { ActivityIndicator, View } from "react-native";
import { AppText } from "@/components/base/AppText.tsx";
import { AppColorPalettes, AppColors, ContextualColors } from "@/theme/colors.ts";
import { AppLocalization } from "@/api/i18n.ts";
import { capitalize, CoLiane, Liane, MessageContentTrip, TypedLianeMessage } from "@liane/common";
import React, { useContext, useMemo } from "react";
import { capitalize, CoLiane, Liane, LianeMessage, TripMessage } from "@liane/common";
import React, { useCallback, useContext, useMemo } from "react";
import { Column, Row } from "@/components/base/AppLayout.tsx";
import { UserPicture } from "@/components/UserPicture.tsx";
import { AppIcon } from "@/components/base/AppIcon.tsx";
import { AppPressableOverlay } from "@/components/base/AppPressable.tsx";
import { WayPointView } from "@/components/trip/WayPointsView.tsx";
import { useQuery } from "react-query";
import { LianeDetailQueryKey } from "@/screens/user/MyTripsScreen.tsx";
import { useQuery, useQueryClient } from "react-query";
import { JoinRequestsQueryKey, LianeDetailQueryKey } from "@/screens/user/MyTripsScreen.tsx";
import { AppContext } from "@/components/context/ContextProvider.tsx";
import { AppStorage } from "@/api/storage.ts";

const LoadedTripSurveyView = ({ coLiane, trip }: { coLiane: CoLiane; trip: Liane }) => {
const members = useMemo(() => {
Expand Down Expand Up @@ -44,7 +45,8 @@ const LoadedTripSurveyView = ({ coLiane, trip }: { coLiane: CoLiane; trip: Liane
</>
);
};
export const TripSurveyView = ({ survey, coLiane }: { survey: TypedLianeMessage<MessageContentTrip>; coLiane: CoLiane }) => {

export const TripSurveyView = ({ survey, coLiane }: { survey: LianeMessage<TripMessage>; coLiane: CoLiane }) => {
const date = useMemo(() => {
return capitalize(AppLocalization.formatMonthDay(new Date(survey.createdAt!)));
}, [survey.createdAt]);
Expand All @@ -63,24 +65,52 @@ export const TripSurveyView = ({ survey, coLiane }: { survey: TypedLianeMessage<
}
});

const joinRequest = useQuery({
queryKey: JoinRequestsQueryKey,
queryFn: async () => {
const joinRequests = (await services.liane.listJoinRequests()).data;
return joinRequests.find(j => j.targetTrip.id === survey.content.value);
}
});

const queryClient = useQueryClient();

const handleJoinTrip = useCallback(async () => {
if (!trip.data) {
return;
}
if (trip.data.isMember) {
return;
}

const geolocationLevel = await AppStorage.getSetting("geolocation");
const query = { liane: coLiane.id!, trip: trip.data.liane.id!, geolocationLevel };
console.log("Joining trip", query);
await services.community.joinTrip(query);
await queryClient.invalidateQueries(JoinRequestsQueryKey);
}, [queryClient, coLiane.id, services.community, trip.data]);

return (
<View style={{ backgroundColor: AppColors.backgroundColor, borderRadius: 16, padding: 8 }}>
{trip.isLoading && <ActivityIndicator />}
{(trip.isLoading || joinRequest.isLoading) && <ActivityIndicator />}
{trip.isError && <AppText>Erreur de chargement</AppText>}
{!!trip.data && (
<>
<AppText style={{ fontWeight: "600", color: AppColorPalettes.gray[500], fontSize: 16 }}>
<AppText style={{ fontWeight: "bold", color: AppColorPalettes.gray[500], fontSize: 16 }}>
{trip.data?.createdBy?.user.pseudo} propose le trajet pour{" "}
</AppText>
<AppText style={{ fontWeight: "bold", fontSize: 18 }}>{date}</AppText>
<LoadedTripSurveyView coLiane={coLiane} trip={trip.data.liane} />
{trip.data.isMember && <AppText style={{ fontStyle: "italic", color: AppColorPalettes.gray[500] }}>En attente de membres</AppText>}
{!trip.data.isMember && (
{!trip.data.isMember && joinRequest.data && (
<AppText style={{ fontStyle: "italic", color: AppColorPalettes.gray[500] }}>Demande en attente</AppText>
)}
{!trip.data.isMember && !joinRequest.data && (
<Row spacing={6}>
<AppPressableOverlay
backgroundStyle={{ backgroundColor: AppColors.primaryColor, borderRadius: 8 }}
style={{ paddingHorizontal: 12, paddingVertical: 6 }}
onPress={() => {}}>
onPress={handleJoinTrip}>
<Row style={{ alignItems: "center" }} spacing={6}>
<AppIcon name={"thumb-up"} color={AppColors.white} size={28} />
<AppText style={{ color: AppColors.white, fontWeight: "bold", fontSize: 18 }}>Participer</AppText>
Expand Down
44 changes: 23 additions & 21 deletions app/src/screens/communities/CommunitiesChatScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,10 @@ import {
LianeMessage,
MatchGroup,
MatchSingle,
MessageContentTrip,
PaginatedResponse,
Ref,
ResolvedLianeRequest,
TypedLianeMessage,
UnionUtils,
TripMessage,
User
} from "@liane/common";
import React, { useContext, useEffect, useMemo, useState } from "react";
Expand Down Expand Up @@ -105,9 +103,13 @@ export const CommunitiesChatScreen = () => {
const [request, setRequest] = useState<CoLianeRequest | ResolvedLianeRequest | undefined>(undefined);
const [tripModalVisible, setTripModalVisible] = useState(false);

const members: { [k: string]: User } | undefined = useMemo(
() => chat?.currentGroup?.members?.reduce((a: { [k: string]: User }, b) => ((a[b.user.id!] = b.user), a), {}),
[chat?.currentGroup?.members, liane]
const members = useMemo(
() =>
chat?.currentGroup?.members?.reduce((acc, b) => {
acc[b.user.id!] = b.user;
return acc;
}, {} as { [k: string]: User }),
[chat?.currentGroup?.members]
);

const sendMessage = async (value: string) => {
Expand Down Expand Up @@ -140,7 +142,7 @@ export const CommunitiesChatScreen = () => {

if (lianeTemp && lianeTemp.id) {
try {
const updatedLianeRequest = await services.community.sendMessage(lianeTemp.id, {
await services.community.sendMessage(lianeTemp.id, {
type: "Text",
value: value
});
Expand All @@ -155,7 +157,7 @@ export const CommunitiesChatScreen = () => {
} else {
if (lianeTemp && lianeTemp.id && value && value.length > 0) {
try {
const updatedLianeRequest = await chat?.send({
await chat?.send({
type: "Text",
value: value
});
Expand Down Expand Up @@ -195,12 +197,12 @@ export const CommunitiesChatScreen = () => {
}
};

if (liane) {
const me = liane.members.find(m => m.user.id === user!.id)!;
const todayIndex = (new Date().getDay() + 6) % 7;
const x = me.lianeRequest.weekDays.substring(todayIndex).concat(me.lianeRequest.weekDays.substring(0, todayIndex)).indexOf("1");
console.log(todayIndex, x, me.lianeRequest.weekDays);
}
// if (liane) {
// const me = liane.members.find(m => m.user.id === user!.id)!;
// const todayIndex = (new Date().getDay() + 6) % 7;
// const x = me.lianeRequest.weekDays.substring(todayIndex).concat(me.lianeRequest.weekDays.substring(0, todayIndex)).indexOf("1");
// console.log(todayIndex, x, me.lianeRequest.weekDays);
// }
const me = useMemo(() => liane?.members.find(m => m.user.id === user!.id), [liane?.members, user]);

const nextDayIndex = useMemo(() => {
Expand All @@ -227,7 +229,7 @@ export const CommunitiesChatScreen = () => {
const addDays = (nextDayIndex - todayIndex + 7) % 7;
const departureTime = addSeconds(time[0], addDays * 3600 * 24).toISOString();
const returnTime = time[1] ? addSeconds(time[1], addDays * 3600 * 24).toISOString() : undefined;
console.log(time[0], nextDayIndex, todayIndex, addDays, departureTime);
//console.log(time[0], nextDayIndex, todayIndex, addDays, departureTime);

const created = await services.liane.post({
departureTime,
Expand Down Expand Up @@ -267,7 +269,7 @@ export const CommunitiesChatScreen = () => {
}
};

console.log("PARAMS", route.params);
// console.log("PARAMS", route.params);
if (route.params.liane) {
// Lorsqu'on arrive directement par une liane
setLiane(route.params.liane);
Expand All @@ -285,7 +287,7 @@ export const CommunitiesChatScreen = () => {
//TODO recup Liane
fetchLiane(route.params.lianeId).then();
}
}, [route.params]);
}, [route.params, services.community]);

useEffect(() => {
if (liane && liane.id) {
Expand All @@ -310,6 +312,7 @@ export const CommunitiesChatScreen = () => {
});
}
};
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [liane, services.realTimeHub]);

const sendButton = (
Expand All @@ -325,7 +328,7 @@ export const CommunitiesChatScreen = () => {
</View>
);

console.debug(JSON.stringify(messages));
// console.debug(JSON.stringify(messages));
return (
<View style={{ backgroundColor: AppColors.lightGrayBackground, justifyContent: "flex-end", flex: 1 }}>
{chat && (
Expand All @@ -335,9 +338,9 @@ export const CommunitiesChatScreen = () => {
keyExtractor={m => m.id!}
renderItem={({ item, index }) =>
members ? (
UnionUtils.isInstanceOf(item.content, "Trip") && !!liane ? (
item.content.type === "Trip" && !!liane ? (
<View style={{ marginHorizontal: 24, marginVertical: 16 }}>
<TripSurveyView survey={item as TypedLianeMessage<MessageContentTrip>} coLiane={liane!} />
<TripSurveyView survey={item as LianeMessage<TripMessage>} coLiane={liane!} />
</View>
) : (
!!members[item.createdBy!] && (
Expand Down Expand Up @@ -504,7 +507,6 @@ const LaunchTripModal = ({
const launch = () => {
launchTrip(selectedTime);
};
console.log(weekdays);
return (
<SimpleModal visible={tripModalVisible} setVisible={setTripModalVisible} backgroundColor={AppColors.white} hideClose>
<Column spacing={8}>
Expand Down
1 change: 0 additions & 1 deletion app/src/screens/home/HomeBottomSheet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ export const HomeBottomSheetContainer = (
machine.off(transitionListener);
};
}, []);
//console.log(Platform.OS, h, insets, StatusBar.currentHeight, bottomSpace);

if (props.display === "none") {
return <View />;
Expand Down
1 change: 0 additions & 1 deletion app/src/screens/home/HomeScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ const HomeScreenView = ({ displaySource }: { displaySource: Observable<[FeatureC
return true;
}}
onSelectFeature={placeFeature => {
console.log("place selected", JSON.stringify(placeFeature));
if (placeFeature.bbox) {
appMapRef.current?.fitBounds(
getBoundingBox(
Expand Down
1 change: 0 additions & 1 deletion app/src/screens/home/LianeMatchDetailView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,6 @@ export const LianeMatchDetailView = () => {
setStep(firstEdit ? step + 1 : 3);
}, [firstEdit, step]);
useEffect(() => {
//console.log(step, isSeatsStep, isReturnStep);
if (step === 1 && !isSeatsStep) {
nextStep();
} else if (step === 2 && !isReturnStep) {
Expand Down
5 changes: 2 additions & 3 deletions app/src/screens/home/TripGeolocationWizard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ export const TripGeolocationWizard = WithFullscreenModal(
const allowed = permission !== GeolocationPermission.Denied;
AppStorage.getSetting("geolocation")
.then(setting => {
//console.log("setting", setting);
if (setting) {
const settingAllowed = setting !== "None";
setPage(!allowed && settingAllowed ? 1 : 2);
Expand Down Expand Up @@ -79,7 +78,7 @@ export const TripGeolocationWizard = WithFullscreenModal(
<Page3
next={endTutorial}
prev={() => {
AppStorage.saveSetting("geolocation", null).then(prev);
AppStorage.saveSetting("geolocation", undefined).then(prev);
}}
/>
)}
Expand Down Expand Up @@ -200,7 +199,7 @@ const Page1 = (props: { next: () => void; showAs: "driver" | "passenger" }) => (
const Page3 = (props: { next: () => void; prev: () => void }) => {
const { route } = useAppNavigation<"TripGeolocationWizard">();
const [loading, setLoading] = useState(false);
const [trackedLevel, setTrackedLevel] = useState<GeolocationLevel | null>(null);
const [trackedLevel, setTrackedLevel] = useState<GeolocationLevel>();
useEffect(() => {
AppStorage.getSetting("geolocation").then(setTrackedLevel);
}, []);
Expand Down
3 changes: 0 additions & 3 deletions app/src/screens/publish/PublishScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,6 @@ export const PublishScreenView = () => {
const isOverviewStep = state.matches("overview");
const isSubmittingStep = state.matches("submitting");

//console.log("[PublishScreen] State Value:", state.value);
//console.log("[PublishScreen] State Request:", state.context.request);

const step = useSharedValue(0);
const { width } = useWindowDimensions();
const stepperIndicatorStyle = useAnimatedStyle(() => {
Expand Down
1 change: 0 additions & 1 deletion app/src/screens/user/RallyingPointRequestsScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ export function NewRallyingPointRequestScreen() {
const [showConfirmation, setShowConfirmation] = useState(false);

const onSubmit: SubmitHandler<FormValues> = async data => {
console.log("xc");
AppLogger.debug("RALLYING_POINT", "Submitting...");
setLoading(true);
try {
Expand Down
6 changes: 3 additions & 3 deletions app/src/screens/user/SettingsScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ const geolocationValues = {
Hidden: "Activée (position masquée)"
} as const;
export const SettingsScreen = () => {
const [geoloc, setGeoloc] = useState<GeolocationLevel | null>(null);
const [geoloc, setGeoloc] = useState<GeolocationLevel>();
const { navigation } = useAppNavigation();
const focused = useIsFocused();
useEffect(() => {
if (!focused) {
return;
}
AppStorage.getSetting("geolocation").then(s => setGeoloc(s));
AppStorage.getSetting("geolocation").then(setGeoloc);
}, [focused]);
return (
<View style={styles.container}>
Expand All @@ -35,7 +35,7 @@ export const SettingsScreen = () => {
<AppPressableOverlay
style={{ paddingHorizontal: 24 }}
onPress={() => {
AppStorage.saveSetting("geolocation", null).then(() =>
AppStorage.saveSetting("geolocation", undefined).then(() =>
navigation.navigate("TripGeolocationWizard", { showAs: null, lianeId: undefined })
);
}}>
Expand Down
Loading

0 comments on commit d9c73d2

Please sign in to comment.