GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — refactor(mobile): pull request diffs page with main's pager again · pingdotgg/t3code@b0670fd

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • apps/mobile/src/features/pull-requests
    • PullRequestRouteScreen.tsx
    • guide
      • PullRequestGuideScreen.tsx
    • pullRequestDiffPages.test.ts
    • pullRequestDiffPages.ts
    • usePullRequestDiff.ts
    • usePullRequestFileFilter.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

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

Copy file name to clipboardExpand all lines: apps/mobile/src/features/pull-requests/PullRequestRouteScreen.tsx
+10-10Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import { usePullRequestFilesViewed } from "./usePullRequestFilesViewed";
3535
import { usePullRequestPermissions } from "./usePullRequestPermissions";
3636
import { usePullRequestAction } from "./usePullRequestAction";
3737
import { annotatePullRequestDiff, reviewPosition } from "./pullRequestDiffComments";
38-
import { usePullRequestFileFilter, usePullRequestHideTestFiles } from "./usePullRequestFileFilter";
38+
import { usePullRequestFileFilter } from "./usePullRequestFileFilter";
3939
import {
4040
handlePullRequestDiffDebugEvent,
4141
pullRequestDiffInitialPosition,
@@ -896,15 +896,11 @@ function PullRequestFileRouteContent({ route }: PullRequestFileRouteProps) {
896896
const terminology = sourceControlClients.get(
897897
(detail.data ?? route.params.initialSummary)?.provider,
898898
).changeRequest;
899-
const [jumpPath, setJumpPath] = useState(route.params.path);
900-
const includePath = route.params.focus ? route.params.path : undefined;
901-
const hideTestFiles = usePullRequestHideTestFiles();
902-
// Pages on past pages the filter empties, so the screen has a file to open at.
903-
const result = usePullRequestDiff(route.params, terminology, jumpPath ? [jumpPath] : [], {
904-
hideTestFiles,
905-
includePath,
906-
});
907-
const filter = usePullRequestFileFilter(result.parsed, includePath);
899+
const result = usePullRequestDiff(route.params, terminology);
900+
const filter = usePullRequestFileFilter(
901+
result.parsed,
902+
route.params.focus ? route.params.path : undefined,
903+
);
908904
const { refresh: refreshDetail } = detail;
909905
useFocusEffect(refreshDetail);
910906
const { loadMore } = result;
@@ -975,6 +971,7 @@ function PullRequestFileRouteContent({ route }: PullRequestFileRouteProps) {
975971
code: row.content ?? "",
976972
});
977973
};
974+
const [jumpPath, setJumpPath] = useState(route.params.path);
978975
const requestedFile =
979976
result.parsed.kind === "files"
980977
? result.parsed.files.find((file) => file.path === jumpPath)
@@ -1032,6 +1029,9 @@ function PullRequestFileRouteContent({ route }: PullRequestFileRouteProps) {
10321029
canHighlight: true,
10331030
});
10341031
const [NativeDiffView] = useState(() => resolveNativeReviewDiffView());
1032+
useEffect(() => {
1033+
if (!targetFile) loadMore();
1034+
}, [targetFile, loadMore]);
10351035
const onDebug: NonNullable<NativeReviewDiffViewProps["onDebug"]> = (event) =>
10361036
handlePullRequestDiffDebugEvent(event, {
10371037
rowCount: data.rows.length,
Collapse file

‎apps/mobile/src/features/pull-requests/guide/PullRequestGuideScreen.tsx‎

Copy file name to clipboardExpand all lines: apps/mobile/src/features/pull-requests/guide/PullRequestGuideScreen.tsx
+6-2Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { Toolbar } from "../../../components/ui/Toolbar";
33
import { parsePatchFiles } from "@pierre/diffs/utils/parsePatchFiles";
44
import type { FileDiffMetadata } from "@pierre/diffs";
55
import { StackActions, useNavigation, type StaticScreenProps } from "@react-navigation/native";
6+
import { useEffect } from "react";
67
import { Platform, Pressable, View } from "react-native";
78
import { AndroidScreenHeader } from "../../../components/ui/AndroidScreenHeader";
89
import { useSafeAreaInsets } from "react-native-safe-area-context";
@@ -101,17 +102,20 @@ export function PullRequestGuideStopScreen({ route }: StaticScreenProps<GuideSto
101102
const { guide, stale } = reviewGuideState(state.data);
102103
const position = Math.max(0, Math.min(route.params.position, (guide?.stops.length ?? 1) - 1));
103104
const stop = guide?.stops[Math.max(0, position)];
104-
const wanted = stop ? stopFilePaths(stop) : [];
105105
const diff = usePullRequestDiff(
106106
route.params,
107107
sourceControlClients.get((detail.data ?? route.params.initialSummary)?.provider).changeRequest,
108-
state.enabled ? wanted : [],
109108
);
110109
const excerptFiles = diffFilesByPath(diff.patch);
110+
const wanted = stop ? stopFilePaths(stop) : [];
111111
const loadedPaths = new Set(
112112
diff.parsed.kind === "files" ? diff.parsed.files.map((file) => file.path) : [],
113113
);
114114
const missing = wanted.some((path) => !loadedPaths.has(path));
115+
const { error: diffError, loadMore } = diff;
116+
useEffect(() => {
117+
if (state.enabled && missing && !diffError) loadMore();
118+
}, [state.enabled, missing, diffError, loadMore]);
115119
const insets = useSafeAreaInsets();
116120
const changedGuide =
117121
guide !== null &&
Collapse file

‎apps/mobile/src/features/pull-requests/pullRequestDiffPages.test.ts‎

Copy file name to clipboardExpand all lines: apps/mobile/src/features/pull-requests/pullRequestDiffPages.test.ts
+22-119Lines changed: 22 additions & 119 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,7 @@ import * as reviewModel from "../review/reviewModel";
66
import {
77
combinePullRequestDiffPages,
88
getCachedPullRequestDiffPages,
9-
requestPullRequestDiffPaths,
10-
createPullRequestDiffPagesMemory,
11-
walkPullRequestDiffPages,
12-
type PullRequestDiffPage,
9+
retainPullRequestDiffPage,
1310
} from "./pullRequestDiffPages";
1411

1512
const GITHUB = sourceControlClients.get("github").changeRequest;
@@ -129,10 +126,11 @@ describe("paged mobile pull request diffs", () => {
129126
const first = { ...diff("first.ts"), nextCursor: "second" };
130127
const withheld = withheldDiff();
131128
const cache = new WeakMap<PullRequestDiffResult, ReviewParsedDiff>();
132-
const pages = [
133-
{ cursor: null, result: first },
134-
{ cursor: "second", result: withheld },
135-
];
129+
const pages = retainPullRequestDiffPage(
130+
retainPullRequestDiffPage([], null, first),
131+
"second",
132+
withheld,
133+
);
136134
const before = combinePullRequestDiffPages(pages, cache, "pr", GITHUB);
137135
if (before.kind !== "files") throw new Error("Expected structured diff");
138136
expect(before.files.map((file) => [file.path, file.additions, file.deletions])).toEqual([
@@ -142,16 +140,10 @@ describe("paged mobile pull request diffs", () => {
142140
expect(before.additions).toBe(3001);
143141
expect(before.deletions).toBe(1801);
144142

145-
const refreshed = [
146-
pages[0]!,
147-
{
148-
cursor: "second",
149-
result: {
150-
...withheld,
151-
omittedFileStats: [{ path: "large.ts", additions: 4000, deletions: 2000 }],
152-
},
153-
},
154-
];
143+
const refreshed = retainPullRequestDiffPage(pages, "second", {
144+
...withheld,
145+
omittedFileStats: [{ path: "large.ts", additions: 4000, deletions: 2000 }],
146+
});
155147
const after = combinePullRequestDiffPages(refreshed, cache, "pr", GITHUB);
156148
if (after.kind !== "files") throw new Error("Expected structured diff");
157149
expect(after.files[0]).toBe(before.files[0]);
@@ -163,106 +155,17 @@ describe("paged mobile pull request diffs", () => {
163155
expect(before.additions).toBe(3001);
164156
});
165157

166-
it("pages on until the wanted files load, then stops", () => {
167-
const answers = new Map<string | null, PullRequestDiffResult>([
168-
[null, { ...diff("a.ts"), nextCursor: "2" }],
169-
["2", { ...diff("b.ts"), nextCursor: "3" }],
170-
["3", { ...diff("c.ts"), nextCursor: "4" }],
171-
["4", diff("d.ts")],
172-
]);
173-
const read = (cursor: string | null) => answers.get(cursor) ?? null;
174-
const paths = (page: PullRequestDiffPage) => [page.result.patch.split(" ")[2]!.slice(2)];
175-
const walk = (count: number, wanted: readonly string[]) => {
176-
const { pages, frontier } = walkPullRequestDiffPages(read, count, wanted, paths);
177-
return { cursors: pages.map((page) => page.cursor), frontier };
178-
};
179-
180-
expect(walk(1, [])).toEqual({ cursors: [null], frontier: null });
181-
expect(walk(1, ["c.ts"])).toEqual({ cursors: [null, "2", "3"], frontier: "3" });
182-
expect(walk(4, [])).toEqual({ cursors: [null, "2", "3", "4"], frontier: "4" });
183-
expect(walk(1, ["gone.ts"])).toEqual({ cursors: [null, "2", "3", "4"], frontier: "4" });
184-
answers.delete("3");
185-
expect(walk(1, ["d.ts"])).toEqual({ cursors: [null, "2"], frontier: "3" });
186-
});
187-
188-
it("holds a later page from before an earlier page changed until it reloads", () => {
189-
const answers = new Map<string | null, PullRequestDiffResult>([
190-
[null, { ...diff("a.ts"), nextCursor: "2" }],
191-
["2", { ...diff("b.ts"), nextCursor: "3" }],
192-
["3", diff("c.ts")],
193-
]);
194-
const read = (cursor: string | null) => answers.get(cursor) ?? null;
195-
const known = createPullRequestDiffPagesMemory();
196-
const walk = () => walkPullRequestDiffPages(read, 3, [], () => [], undefined, known);
197-
198-
expect(walk().pages).toHaveLength(3);
199-
answers.set(null, { ...diff("a2.ts"), nextCursor: "2" });
200-
expect(walk()).toMatchObject({ frontier: "2", reload: "2" });
201-
const held = walk();
202-
expect([held.frontier, held.reload]).toEqual(["2", undefined]);
203-
answers.set("2", { ...diff("b2.ts"), nextCursor: "3" });
204-
expect(walk()).toMatchObject({ frontier: "3", reload: "3" });
205-
answers.set("3", diff("c.ts"));
206-
const { pages } = walk();
207-
expect(pages.map((page) => page.result.patch)).toEqual([
208-
answers.get(null)!.patch,
209-
answers.get("2")!.patch,
210-
diff("c.ts").patch,
211-
]);
212-
});
213-
214-
it("pages past test-only pages until a file the screen shows loads", () => {
215-
const answers = new Map<string | null, PullRequestDiffResult>([
216-
[null, { ...diff("a.test.ts"), nextCursor: "2" }],
217-
["2", { ...diff("b.test.ts"), nextCursor: "3" }],
218-
["3", { ...diff("c.ts"), nextCursor: "4" }],
219-
["4", diff("d.ts")],
220-
]);
221-
const read = (cursor: string | null) => answers.get(cursor) ?? null;
222-
const paths = (page: PullRequestDiffPage) => [page.result.patch.split(" ")[2]!.slice(2)];
223-
const cursors = (shown?: (path: string) => boolean) =>
224-
walkPullRequestDiffPages(read, 1, [], paths, shown).pages.map((page) => page.cursor);
225-
226-
expect(cursors()).toEqual([null]);
227-
expect(cursors((path) => !path.includes(".test."))).toEqual([null, "2", "3"]);
228-
expect(cursors(() => false)).toEqual([null, "2", "3", "4"]);
229-
});
230-
231-
it("keeps pages loaded while seeking one file when the wanted file moves to an earlier page", () => {
232-
const answers = new Map<string | null, PullRequestDiffResult>([
233-
[null, { ...diff("a.ts"), nextCursor: "2" }],
234-
["2", { ...diff("b.ts"), nextCursor: "3" }],
235-
["3", { ...diff("c.ts"), nextCursor: "4" }],
236-
["4", diff("d.ts")],
237-
]);
238-
const read = (cursor: string | null) => answers.get(cursor) ?? null;
239-
const paths = (page: PullRequestDiffPage) => [page.result.patch.split(" ")[2]!.slice(2)];
240-
const shown = (request: { count: number; wanted: readonly string[] }) =>
241-
walkPullRequestDiffPages(read, request.count, request.wanted, paths).pages.map(
242-
(page) => page.cursor,
243-
);
244-
245-
const opened = requestPullRequestDiffPaths({ key: "pr", count: 1, wanted: [] }, "pr", ["c.ts"]);
246-
expect(shown(opened)).toEqual([null, "2", "3"]);
247-
const jumped = requestPullRequestDiffPaths(opened, "pr", ["a.ts"]);
248-
expect(shown(jumped)).toEqual([null, "2", "3"]);
249-
expect(requestPullRequestDiffPaths(jumped, "pr", ["a.ts"])).toBe(jumped);
250-
expect(requestPullRequestDiffPaths(jumped, "other", ["a.ts"])).toEqual({
251-
key: "other",
252-
count: 1,
253-
wanted: ["a.ts"],
254-
});
255-
});
256-
257-
it("drops later pages when a refreshed page points elsewhere, and stops on a cursor loop", () => {
258-
const answers = new Map<string | null, PullRequestDiffResult>([
259-
[null, { ...diff("a.ts"), nextCursor: "2" }],
260-
["2", { ...diff("b.ts"), nextCursor: "2" }],
261-
]);
262-
const read = (cursor: string | null) => answers.get(cursor) ?? null;
263-
expect(walkPullRequestDiffPages(read, 5, [], () => []).pages).toHaveLength(2);
264-
answers.set(null, diff("changed.ts"));
265-
const { pages } = walkPullRequestDiffPages(read, 5, [], () => []);
266-
expect(pages.map((page) => page.result.patch)).toEqual([diff("changed.ts").patch]);
158+
it("discards later pages when a refreshed page changes", () => {
159+
const first = diff("first.ts");
160+
const pages = retainPullRequestDiffPage(
161+
retainPullRequestDiffPage([], null, first),
162+
"second",
163+
diff("second.ts"),
164+
);
165+
expect(retainPullRequestDiffPage(pages, null, first)).toBe(pages);
166+
expect(retainPullRequestDiffPage(pages, null, { ...first })).toBe(pages);
167+
const refreshed = retainPullRequestDiffPage(pages, null, diff("changed.ts"));
168+
expect(refreshed).toHaveLength(1);
169+
expect(refreshed[0]?.result.patch).toContain("changed.ts");
267170
});
268171
});

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.