Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Android - Distance - Waypoint does not change position correctly by dragging. #41378

Merged
merged 12 commits into from
May 28, 2024
7 changes: 5 additions & 2 deletions src/pages/iou/request/step/IOURequestStepDistance.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,10 @@ function IOURequestStepDistance({
const newWaypoints: WaypointCollection = {};
let emptyWaypointIndex = -1;
data.forEach((waypoint, index) => {
newWaypoints[`waypoint${index}`] = waypoints[waypoint] ?? {};
const newWaypointObj = waypoints[waypoint].keyForList
? waypoints[waypoint]
: {...waypoints[waypoint], keyForList: `${new Date().getTime()}_${Math.random().toString(36).substring(2, 15)}`};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't the keyForList be there always if added in waypoint page, why this check ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought the backend won't save the keyForList property but thats not the case. This part is not updated.

newWaypoints[`waypoint${index}`] = newWaypointObj ?? {};
// Find waypoint that BECOMES empty after dragging
if (isEmpty(newWaypoints[`waypoint${index}`]) && !isEmpty(waypoints[`waypoint${index}`] ?? {})) {
emptyWaypointIndex = index;
Expand Down Expand Up @@ -428,7 +431,7 @@ function IOURequestStepDistance({
<View style={styles.flex1}>
<DraggableList
data={waypointsList}
keyExtractor={(item) => (waypoints[item]?.address ?? '') + item || item}
keyExtractor={(item) => (waypoints[item]?.keyForList ?? waypoints[item]?.address ?? '') + item || item}
rlinoz marked this conversation as resolved.
Show resolved Hide resolved
shouldUsePortal
onDragEnd={updateWaypoints}
ref={scrollViewRef}
Expand Down
1 change: 1 addition & 0 deletions src/pages/iou/request/step/IOURequestStepWaypoint.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ function IOURequestStepWaypoint({
name: values.name ?? '',
lat: values.lat ?? 0,
lng: values.lng ?? 0,
keyForList: `${new Date().getTime()}_${Math.random().toString(36).substring(2, 15)}`,
Copy link
Contributor

@ishpaul777 ishpaul777 May 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why only when offline 🤔 if (isOffline && waypointValue) { ??

Also can we do something like keyForList: "waypoint-{Date.now()}" is there a reason to do such intensive string processing

Copy link
Contributor Author

@Krishna2323 Krishna2323 May 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can use waypoint-${Date.now()} here, but not when dragging. If there are three waypoints and we assign waypoint-${Date.now()} to keyForList, it will be the same for all three.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ignore my previous comment, I thought the backend won't save the keyForList and we will have to add again but that's not the case. The keyForList is saved and returned from the backend.

Why only when offline 🤔 if (isOffline && waypointValue) { ??

I forgot to add to selectWaypoint function, now added.

};
saveWaypoint(waypoint);
}
Expand Down
3 changes: 3 additions & 0 deletions src/types/onyx/RecentWaypoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ type RecentWaypoint = {

/** The longitude of the waypoint */
lng?: number;

/** The longitude of the waypoint */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wrong comment

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated.

keyForList?: string;
};

export default RecentWaypoint;
3 changes: 3 additions & 0 deletions src/types/onyx/Transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ type Waypoint = {

/** Address street line 2 */
street2?: string;

/** The longitude of the waypoint */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wrong comment

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated.

keyForList?: string;
};

type WaypointCollection = Record<string, RecentWaypoint | Waypoint>;
Expand Down
Loading