mirror of
https://github.com/alkimake/paperclip.git
synced 2026-06-18 11:40:39 +09:00
Refine issue workflow surfaces and live updates
This commit is contained in:
parent
b4a58ba8a6
commit
03dff1a29a
48 changed files with 2800 additions and 1163 deletions
45
ui/src/lib/navigation-scroll.ts
Normal file
45
ui/src/lib/navigation-scroll.ts
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
export type NavigationType = "POP" | "PUSH" | "REPLACE";
|
||||
|
||||
export const SIDEBAR_SCROLL_RESET_STATE = {
|
||||
paperclipSidebarScrollReset: true,
|
||||
} as const;
|
||||
|
||||
export function shouldResetScrollOnNavigation(params: {
|
||||
previousPathname: string | null;
|
||||
pathname: string;
|
||||
navigationType: NavigationType;
|
||||
state: unknown;
|
||||
}): boolean {
|
||||
const { previousPathname, pathname, navigationType, state } = params;
|
||||
if (previousPathname === null) return false;
|
||||
if (previousPathname === pathname) return false;
|
||||
if (navigationType === "POP") return false;
|
||||
return hasSidebarScrollResetState(state);
|
||||
}
|
||||
|
||||
export function resetNavigationScroll(mainElement: HTMLElement | null): void {
|
||||
mainElement?.scrollTo?.({ top: 0, left: 0, behavior: "auto" });
|
||||
|
||||
if (mainElement) {
|
||||
mainElement.scrollTop = 0;
|
||||
mainElement.scrollLeft = 0;
|
||||
}
|
||||
|
||||
const scrollingElement = document.scrollingElement ?? document.documentElement;
|
||||
if (scrollingElement) {
|
||||
scrollingElement.scrollTop = 0;
|
||||
scrollingElement.scrollLeft = 0;
|
||||
}
|
||||
|
||||
if (document.body) {
|
||||
document.body.scrollTop = 0;
|
||||
document.body.scrollLeft = 0;
|
||||
}
|
||||
|
||||
window.scrollTo({ top: 0, left: 0, behavior: "auto" });
|
||||
}
|
||||
|
||||
function hasSidebarScrollResetState(state: unknown): boolean {
|
||||
if (!state || typeof state !== "object") return false;
|
||||
return (state as Record<string, unknown>).paperclipSidebarScrollReset === true;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue