mirror of
https://github.com/alkimake/paperclip.git
synced 2026-06-18 19:50:38 +09:00
Reset scroll on issue detail navigation
This commit is contained in:
parent
1729e41179
commit
e59047187b
2 changed files with 58 additions and 0 deletions
|
|
@ -14,6 +14,7 @@ export function shouldResetScrollOnNavigation(params: {
|
|||
if (previousPathname === null) return false;
|
||||
if (previousPathname === pathname) return false;
|
||||
if (navigationType === "POP") return false;
|
||||
if (isIssueDetailPathChange(previousPathname, pathname)) return true;
|
||||
return hasSidebarScrollResetState(state);
|
||||
}
|
||||
|
||||
|
|
@ -43,3 +44,20 @@ function hasSidebarScrollResetState(state: unknown): boolean {
|
|||
if (!state || typeof state !== "object") return false;
|
||||
return (state as Record<string, unknown>).paperclipSidebarScrollReset === true;
|
||||
}
|
||||
|
||||
function isIssueDetailPathChange(previousPathname: string, pathname: string): boolean {
|
||||
const previousIssueRef = readIssueDetailPathRef(previousPathname);
|
||||
const nextIssueRef = readIssueDetailPathRef(pathname);
|
||||
return previousIssueRef !== null && nextIssueRef !== null && previousIssueRef !== nextIssueRef;
|
||||
}
|
||||
|
||||
function readIssueDetailPathRef(pathname: string): string | null {
|
||||
const segments = pathname.split("/").filter(Boolean);
|
||||
if (segments.length === 2 && segments[0] === "issues") {
|
||||
return segments[1] ?? null;
|
||||
}
|
||||
if (segments.length === 3 && segments[1] === "issues") {
|
||||
return segments[2] ?? null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue