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
5 changes: 3 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,8 @@ function IOURequestStepDistance({
const newWaypoints: WaypointCollection = {};
let emptyWaypointIndex = -1;
data.forEach((waypoint, index) => {
newWaypoints[`waypoint${index}`] = waypoints[waypoint] ?? {};
const newWaypointObj = waypoints[waypoint];
newWaypoints[`waypoint${index}`] = newWaypointObj ?? {};
Copy link
Contributor

@ishpaul777 ishpaul777 May 22, 2024

Choose a reason for hiding this comment

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

This change seems unnecessary

Copy link
Contributor Author

Choose a reason for hiding this comment

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

reverted.

// Find waypoint that BECOMES empty after dragging
if (isEmpty(newWaypoints[`waypoint${index}`]) && !isEmpty(waypoints[`waypoint${index}`] ?? {})) {
emptyWaypointIndex = index;
Expand Down Expand Up @@ -428,7 +429,7 @@ function IOURequestStepDistance({
<View style={styles.flex1}>
<DraggableList
data={waypointsList}
keyExtractor={(item) => item}
keyExtractor={(item) => (waypoints[item]?.keyForList ?? waypoints[item]?.address ?? '') + item || item}
shouldUsePortal
onDragEnd={updateWaypoints}
ref={scrollViewRef}
Expand Down
2 changes: 2 additions & 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: `${waypointValue as string}_${Date.now()}`,
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
keyForList: `${waypointValue as string}_${Date.now()}`,
keyForList: `${waypointValue ?? 'waypoint'}_${Date.now()}`,

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.

};
saveWaypoint(waypoint);
}
Expand All @@ -139,6 +140,7 @@ function IOURequestStepWaypoint({
lng: values.lng ?? 0,
address: values.address ?? '',
name: values.name ?? '',
keyForList: `${values.name}_${Date.now()}`,
};

Transaction.saveWaypoint(transactionID, pageIndex, waypoint, action === CONST.IOU.ACTION.CREATE);
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;

/** Key used internally by React */
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;

/** Key used internally by React */
keyForList?: string;
};

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