Repository navigation
fix: PR diffs fold Viewed files the way GitHub does, on web and mobile #37605
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
Changes from all commits
677d1a5
bfcbe48
dde18af
38bf708
1f9b1a7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,8 @@ | ||
| import { | ||
| isFileDiffCollapsed, | ||
| withFileDiffFold, | ||
| type FileDiffFoldChoices, | ||
| } from "@t3tools/client-runtime/pull-request-diff-fold"; | ||
| import { | ||
| parsePullRequestAnchor, | ||
| pullRequestAnchorMatchesUrl, | ||
|
|
@@ -130,8 +135,6 @@ import { | |
| sourceControlClients, | ||
| } from "@t3tools/client-runtime/source-control-clients"; | ||
|
|
||
| const EMPTY_IDS: readonly string[] = []; | ||
|
|
||
| function usePullRequestActivityRows(params: PullRequestParams, filter: ActivityFilter) { | ||
| const navigation = useNavigation(); | ||
| const result = useEnvironmentQuery(composerPullRequests.activity(requestTarget(params))); | ||
|
|
@@ -1088,7 +1091,26 @@ function PullRequestFileRouteContent({ route }: PullRequestFileRouteProps) { | |
| const focusIndex = focusedRows.length | ||
| ? data.rows.findIndex((row) => row.id === focusedRows[0]?.id) | ||
| : -1; | ||
| const [collapsedIds, setCollapsedIds] = useState<readonly string[]>(EMPTY_IDS); | ||
| const [foldChoices, setFoldChoices] = useState<FileDiffFoldChoices>(() => new Map()); | ||
| const [foldScope, setFoldScope] = useState(`${scopeKey}:${commit ?? "all"}`); | ||
| const [revealedFileId, setRevealedFileId] = useState<string | null>(null); | ||
| if (foldScope !== `${scopeKey}:${commit ?? "all"}`) { | ||
| setFoldScope(`${scopeKey}:${commit ?? "all"}`); | ||
| setFoldChoices(new Map()); | ||
| setRevealedFileId(null); | ||
| } | ||
| const requestedFileId = | ||
| (jumpPath ? data.files.find((file) => file.path === jumpPath)?.id : null) ?? null; | ||
| // A linked file must stay open if its Viewed response arrives after the first native draw. | ||
| if (requestedFileId !== revealedFileId) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A repeat line link does not expand a file that Viewed has folded. The guard at Native positioning does not repair this. Expand the file for each new line-link request, not only when the file ID changes. The request identity must come from the navigation, not from the file ID alone.
|
||
| setRevealedFileId(requestedFileId); | ||
| if (requestedFileId) | ||
| setFoldChoices((current) => withFileDiffFold(current, requestedFileId, false)); | ||
| } | ||
| const viewedIdSet = new Set(viewedIds); | ||
| const collapsedIds = data.files | ||
| .filter((file) => isFileDiffCollapsed(file.id, null, foldChoices, viewedIdSet.has(file.id))) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
On Android, if saved Viewed marks are available before the native view mounts, folding a file before a linked line or guide excerpt makes the initial scroll target incorrect. AGENTS.md reference: AGENTS.md:L70-L70 Useful? React with 👍 / 👎. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
On Android, opening a paginated diff at an earlier file can now prevent subsequent pages from loading when the last loaded file has a saved Viewed mark and more than 40 body rows. Android reports AGENTS.md reference: AGENTS.md:L31-L31 Useful? React with 👍 / 👎. |
||
| .map((file) => file.id); | ||
| const [visibleFileId, setVisibleFileId] = useState<string | null>(null); | ||
| const nativeView = useRef<NativeReviewDiffViewHandle>(null); | ||
| // The filter the current jump was made under. Hiding or showing test files replaces the rows, | ||
|
|
@@ -1114,7 +1136,7 @@ function PullRequestFileRouteContent({ route }: PullRequestFileRouteProps) { | |
| jumpedUnder.current = null; | ||
| const file = data.files.find((entry) => entry.path === path); | ||
| if (!file) return; | ||
| setCollapsedIds((ids) => ids.filter((id) => id !== file.id)); | ||
| setFoldChoices((current) => withFileDiffFold(current, file.id, false)); | ||
| scrollToFile(file.id); | ||
| }); | ||
| // Subscribed for the whole screen, so a pick made while the diff is still loading is kept for | ||
|
|
@@ -1138,9 +1160,14 @@ function PullRequestFileRouteContent({ route }: PullRequestFileRouteProps) { | |
| useEffect(() => { | ||
| if (!targetFile) loadMore(); | ||
| }, [targetFile, loadMore]); | ||
| const lastFileRowIndex = data.rows.findLastIndex((row) => row.kind === "file"); | ||
| const lastFileId = data.rows[lastFileRowIndex]?.fileId; | ||
| const lastShownRowIndex = | ||
| lastFileId && collapsedIds.includes(lastFileId) ? lastFileRowIndex : data.rows.length - 1; | ||
| const onDebug: NonNullable<NativeReviewDiffViewProps["onDebug"]> = (event) => | ||
| handlePullRequestDiffDebugEvent(event, { | ||
| rowCount: data.rows.length, | ||
| lastShownRowIndex, | ||
| targetFileId: targetFile?.id, | ||
| focusIndex, | ||
| isIos: Platform.OS === "ios", | ||
|
|
@@ -1155,8 +1182,8 @@ function PullRequestFileRouteContent({ route }: PullRequestFileRouteProps) { | |
| const onToggleFile: NonNullable<NativeReviewDiffViewProps["onToggleFile"]> = (event) => { | ||
| const id = event.nativeEvent.fileId; | ||
| if (!id) return; | ||
| setCollapsedIds((ids) => | ||
| ids.includes(id) ? ids.filter((value) => value !== id) : [...ids, id], | ||
| setFoldChoices((current) => | ||
| withFileDiffFold(current, id, !isFileDiffCollapsed(id, null, current, viewedIdSet.has(id))), | ||
| ); | ||
| }; | ||
| const visibleFile = data.files.find((file) => file.id === visibleFileId) ?? targetFile; | ||
|
|
@@ -1270,7 +1297,7 @@ function PullRequestFileRouteContent({ route }: PullRequestFileRouteProps) { | |
| setDiffHead({ scopeKey, sha: detail.data?.headSha ?? null }); | ||
| jumpedUnder.current = null; | ||
| setSelectedRowId(null); | ||
| setCollapsedIds(EMPTY_IDS); | ||
| setFoldChoices(new Map()); | ||
| }} | ||
| /> | ||
| </View> | ||
|
|
@@ -1311,16 +1338,7 @@ function PullRequestFileRouteContent({ route }: PullRequestFileRouteProps) { | |
| onToggleViewedFile={(event) => { | ||
| const file = data.files.find((file) => file.id === event.nativeEvent.fileId); | ||
| if (!file || (!commit && !viewed.canToggle)) return; | ||
| const wasViewed = commit | ||
| ? commitViewedPaths.has(file.path) | ||
| : viewed.isViewed(file.path); | ||
| setCollapsedIds((ids) => | ||
| wasViewed | ||
| ? ids.filter((id) => id !== file.id) | ||
| : ids.includes(file.id) | ||
| ? ids | ||
| : [...ids, file.id], | ||
| ); | ||
| setFoldChoices((current) => withFileDiffFold(current, file.id, undefined)); | ||
| if (commit) | ||
| setCommitViewedPaths((current) => { | ||
| const next = new Set(current); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Scope commit Viewed marks with the fold choices.
If this component switches from commit C1 to C2,
commitViewedPathsretains the paths viewed in C1. This reset clears onlyfoldChoices. Lines 1031-1033 then classify matching paths in C2 as viewed, and the new collapse derivation hides those unreviewed changes.Reset
commitViewedPathswhenfoldScopechanges, or store the marks by review and commit.