Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
agjini committed Oct 17, 2024
1 parent 58c3246 commit e522c23
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 25 deletions.
16 changes: 8 additions & 8 deletions app/src/components/map/layers/PickupDestinationsDisplayLayer.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AppEnv, RallyingPoint, Ref } from "@liane/common";
import { AppEnv, DayOfWeekFlag, RallyingPoint, Ref } from "@liane/common";
import React, { useEffect, useMemo, useState } from "react";
import { useAppMapViewController } from "@/components/map/AppMapView";
import MapLibreGL from "@maplibre/maplibre-react-native";
Expand All @@ -8,22 +8,22 @@ import { AppLogger } from "@/api/logger";
import { RNAppEnv } from "@/api/env";

export type PickupDestinationsDisplayLayerProps = {
date?: Date;
weekDays?: DayOfWeekFlag;
onSelect?: (rp: RallyingPoint) => void;
point: Ref<RallyingPoint>;
type: "pickup" | "deposit";
};

export const PickupDestinationsDisplayLayer = ({ date = new Date(), onSelect, point, type }: PickupDestinationsDisplayLayerProps) => {
const dateArg = useMemo(() => AppEnv.getLayerDateParams(date), [date]);
export const PickupDestinationsDisplayLayer = ({ weekDays, onSelect, point, type }: PickupDestinationsDisplayLayerProps) => {
const params = useMemo(() => AppEnv.getLianeDisplayParams(weekDays), [weekDays]);
const [sourceId, setSourceId] = useState("");
useEffect(() => {
setSourceId("segmentsFiltered" + dateArg + point + type);
AppLogger.debug("MAP", "tile source", dateArg, type, point);
}, [dateArg, point, type]);
setSourceId("segmentsFiltered" + params + point + type);
AppLogger.debug("MAP", "tile source", params, type, point);
}, [params, point, type]);

const controller = useAppMapViewController();
const url = RNAppEnv.lianeFilteredTilesUrl + "?" + dateArg + `&${type}=` + point;
const url = RNAppEnv.lianeFilteredTilesUrl + "?" + params + `&${type}=` + point;

const updateIdentifier = Math.floor(new Date().getTime() / 1000 / 3600); // update map every hour
return (
Expand Down
6 changes: 3 additions & 3 deletions app/src/screens/home/HomeMap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ export const HomeMap = React.forwardRef<AppMapViewController, HomeMapProps>(
appMapRef.current?.setCenter({ lat: center[1], lng: center[0] }, zoom + 0.01, 50); //state.context.filter.from!.location
});
});
}, [state.context.filter.to?.id, state.context.filter.targetTime?.dateTime, isPointState]);
}, [state.context.filter.to?.id, state.context.filter.weekDays, isPointState]);

const onRegionChanged = async (payload: { zoomLevel: number; isUserInteraction: boolean; visibleBounds: Position[] }) => {
if (onZoomChanged) {
Expand Down Expand Up @@ -206,7 +206,7 @@ export const HomeMap = React.forwardRef<AppMapViewController, HomeMapProps>(
ref={appMapRef}>
{state.matches("map") && (
<LianeDisplayLayer
date={state.context.filter.targetTime?.dateTime}
weekDays={state.context.filter.weekDays}
onSelect={rp => {
if (rp) {
machine.send("SELECT", { data: rp });
Expand All @@ -219,7 +219,7 @@ export const HomeMap = React.forwardRef<AppMapViewController, HomeMapProps>(
)}
{state.matches("point") && (
<PickupDestinationsDisplayLayer
date={state.context.filter.targetTime?.dateTime}
weekDays={state.context.filter.weekDays}
point={(state.context.filter.to || state.context.filter.from)!.id!}
type={state.context.filter.from ? "pickup" : "deposit"}
onSelect={rp => {
Expand Down
21 changes: 7 additions & 14 deletions app/src/screens/home/StateMachine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ import {
} from "xstate";
import {
BoundingBox,
DayOfWeekFlag,
EmptyFeatureCollection,
Liane,
LianeMatch,
LianeMatchDisplay,
LianeSearchFilter,
RallyingPoint,
Ref,
TargetTimeDirection,
Trip
} from "@liane/common";

Expand All @@ -37,13 +37,9 @@ export type HomeMapMachineStateKeys = "map" | "form" | "point" | "match" | "deta

export const getSearchFilter = (filter: Partial<InternalLianeMatchFilter>) => {
return <LianeSearchFilter>{
availableSeats: -1, //TODO
availableSeats: -1,
to: filter.to!.id!,
from: filter.from!.id!,
targetTime: {
direction: filter.targetTime?.direction ?? "Departure",
dateTime: (filter.targetTime?.dateTime ?? new Date()).toISOString()
}
from: filter.from!.id!
};
};

Expand All @@ -52,10 +48,7 @@ export const filterHasFullTrip = (filter: Partial<InternalLianeMatchFilter>): bo
type InternalLianeMatchFilter = {
to: RallyingPoint;
from: RallyingPoint;
targetTime: {
dateTime: Date;
direction: TargetTimeDirection;
};
weekDays?: DayOfWeekFlag;
availableSeats: number;
};

Expand Down Expand Up @@ -141,7 +134,7 @@ const createState = <T>(
},
onError: {
target: "failed",
actions: assign({ error: (context, event) => event.data })
actions: assign({ error: (context, e: any) => e.data })
}
};
}
Expand Down Expand Up @@ -412,10 +405,10 @@ export const HomeMapMachine = (services: {
updateFilter: assign<HomeMapContext, UpdateFilterEvent>({
filter: (context, event) => {
const availableSeats = (Object.hasOwn(event.data, "availableSeats") ? event.data.availableSeats : context.filter.availableSeats) || -1;
const targetTime = Object.hasOwn(event.data, "targetTime") ? event.data.targetTime : context.filter.targetTime;
const weekDays = Object.hasOwn(event.data, "weekDays") ? event.data.weekDays : context.filter.weekDays;
return {
...context.filter,
targetTime: { direction: targetTime?.direction || "Departure", dateTime: targetTime?.dateTime || new Date() },
weekDays,
availableSeats
};
}
Expand Down

0 comments on commit e522c23

Please sign in to comment.