Skip to content

Commit 7224019

Browse files
committed
fix(review): keep staging context stable and resolve threads optimistically
1 parent 37d9b28 commit 7224019

24 files changed

Lines changed: 1528 additions & 543 deletions

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

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,24 +31,18 @@ function CommentThread({
3131
}) {
3232
const target = pullRequestTarget(params);
3333
const detail = useEnvironmentQuery(composerPullRequests.detail(target));
34-
const activity = useEnvironmentQuery(composerPullRequests.activity(target));
3534
const permissions = usePullRequestPermissions(params, detail.data);
3635
const resolve = useAtomCommand(composerPullRequests.setThreadResolution, {
3736
reportFailure: false,
3837
});
39-
const [busy, setBusy] = useState(false);
4038
const first = thread.comments[0];
4139
if (!first) return null;
4240
const toggle = async () => {
43-
if (busy) return;
44-
setBusy(true);
4541
const result = await resolve({
4642
...target,
4743
input: { ...target.input, threadId: thread.id, resolved: !thread.isResolved },
4844
});
49-
setBusy(false);
5045
if (result._tag === "Failure") Alert.alert("Could not update the thread", "Try again.");
51-
else activity.refresh();
5246
};
5347
const canResolve = permissions.canResolve && thread.canResolve !== false;
5448
return (
@@ -67,7 +61,6 @@ function CommentThread({
6761
<PullRequestCommentControls
6862
params={params}
6963
comment={{ ...first, url: first.url ?? null }}
70-
disabled={busy}
7164
onResolve={canResolve && !thread.isResolved ? () => void toggle() : undefined}
7265
onUnresolve={canResolve && thread.isResolved ? () => void toggle() : undefined}
7366
render={({ actions, reactions }) => (

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

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -104,22 +104,27 @@ function Discussion({ params }: { params: PullRequestParams & { readonly discuss
104104
refresh();
105105
return response;
106106
});
107-
const toggleResolved = () =>
108-
operation(async () => {
109-
if (
110-
!thread ||
111-
!permissions.canResolve ||
112-
thread.canResolve === false ||
113-
thread.comments.some((comment) => comment.pendingReviewId)
114-
)
115-
return;
116-
const response = await resolve({
117-
...target,
118-
input: { ...target.input, threadId: thread.id, resolved: !thread.isResolved },
119-
});
120-
if (AsyncResult.isSuccess(response)) refresh();
121-
return response;
107+
const toggleResolved = async () => {
108+
if (
109+
!thread ||
110+
!permissions.canResolve ||
111+
thread.canResolve === false ||
112+
thread.comments.some((comment) => comment.pendingReviewId)
113+
)
114+
return;
115+
setError(null);
116+
setNotice(null);
117+
const response = await resolve({
118+
...target,
119+
input: { ...target.input, threadId: thread.id, resolved: !thread.isResolved },
122120
});
121+
if (response._tag === "Failure") {
122+
const cause = squashAtomCommandFailure(response);
123+
setError(
124+
cause instanceof Error ? cause.message : "The provider could not update this discussion.",
125+
);
126+
}
127+
};
123128
const nextCursor = cursor === undefined ? thread?.nextCommentsCursor : cursor;
124129
const more = () =>
125130
operation(async () => {
@@ -266,7 +271,7 @@ function Discussion({ params }: { params: PullRequestParams & { readonly discuss
266271
<ControlPill
267272
icon="checkmark"
268273
accessibilityLabel="Resolve thread"
269-
disabled={busy || activity.isPending}
274+
disabled={busy}
270275
onPress={() => void toggleResolved()}
271276
/>
272277
) : null}

0 commit comments

Comments
 (0)