Skip to content

Commit fee8bd8

Browse files
committed
fix(mobile): Edit description waits for checkbox saves
Opening Edit description while a checkbox save ran let a queued tap's body overwrite the manual edit. Both Edit description entries are now disabled while checkbox saves run, as on web.
1 parent 5ec617d commit fee8bd8

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

‎apps/mobile/src/features/pull-requests/PullRequestRouteScreen.tsx‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,7 @@ function PullRequestOverview(props: {
302302
readonly onDescriptionCollapse: () => void;
303303
readonly descriptionExpanded: boolean;
304304
readonly onDescriptionExpandedChange: (expanded: boolean) => void;
305+
readonly onTaskSavingChange: (saving: boolean) => void;
305306
}) {
306307
const { pr } = props;
307308
const permissions = usePullRequestPermissions(props.params, pr);
@@ -333,12 +334,14 @@ function PullRequestOverview(props: {
333334
if (AsyncResult.isFailure(result)) {
334335
nextTaskBody.current = null;
335336
setTaskEdit(null);
337+
props.onTaskSavingChange(false);
336338
// An earlier save in the run may have landed.
337339
refreshDetail();
338340
return;
339341
}
340342
}
341343
setTaskEdit((edit) => edit && { ...edit, saving: false });
344+
props.onTaskSavingChange(false);
342345
refreshDetail();
343346
};
344347
const toggleTask = (input: { markerOffset: number | null; checked: boolean }) => {
@@ -354,7 +357,9 @@ function PullRequestOverview(props: {
354357
const stale = taskEdit !== null && shownBody !== pr.body ? [...taskEdit.stale, shownBody] : [];
355358
setTaskEdit({ stale: [...stale, pr.body], to: body, saving: true });
356359
nextTaskBody.current = body;
357-
if (!saving) void saveTasks();
360+
if (saving) return;
361+
props.onTaskSavingChange(true);
362+
void saveTasks();
358363
};
359364
return (
360365
<View className="gap-5">
@@ -409,6 +414,8 @@ export function PullRequestRouteScreen({ route }: StaticScreenProps<PullRequestP
409414
const requestedSection = useRef(chosenSection);
410415
const [listAnimationsReady, setListAnimationsReady] = useState(false);
411416
const [descriptionExpanded, setDescriptionExpanded] = useState(false);
417+
// A manual description save racing a checkbox save could land first and be overwritten.
418+
const [taskSaving, setTaskSaving] = useState(false);
412419
const filesContent = usePullRequestFilesSection(params);
413420
const guidesEnabled = useReviewGuidesEnabled(params);
414421
// The guide tab goes away while guides are off and overview stands in. The pick is kept, so
@@ -575,6 +582,7 @@ export function PullRequestRouteScreen({ route }: StaticScreenProps<PullRequestP
575582
accessibilityLabel: "Edit description",
576583
icon: "doc.text" as const,
577584
overflowOnly: true,
585+
disabled: taskSaving,
578586
onPress: () =>
579587
navigation.navigate("PullRequestEdit", { ...params, field: "body" }),
580588
},
@@ -668,6 +676,7 @@ export function PullRequestRouteScreen({ route }: StaticScreenProps<PullRequestP
668676
{permissions.canEditChangeRequest ? (
669677
<Toolbar.MenuAction
670678
icon="doc.text"
679+
disabled={taskSaving}
671680
onPress={() => navigation.navigate("PullRequestEdit", { ...params, field: "body" })}
672681
>
673682
<Toolbar.Label>Edit description</Toolbar.Label>
@@ -829,6 +838,7 @@ export function PullRequestRouteScreen({ route }: StaticScreenProps<PullRequestP
829838
onDescriptionCollapse={() => {
830839
pendingDescriptionJump.current = true;
831840
}}
841+
onTaskSavingChange={setTaskSaving}
832842
/>
833843
) : summary ? (
834844
<PullRequestOverviewLoading

0 commit comments

Comments
 (0)