All files / client/src/utils scrollToTop.ts

90.9% Statements 10/11
50% Branches 2/4
100% Functions 3/3
90.9% Lines 10/11

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27          356x     356x     247x 247x 124x 124x         356x 3x 3x 3x        
// A smooth window.scrollTo gets cancelled when the virtualizer measures rows
// mounting above the viewport and adjusts the scroll position, so the
// virtualized program list registers its own scrollToOffset here as an
// override for the scroll-to-top button
 
let override: (() => void) | null = null;
 
// Returns an unregister function for the effect cleanup
export const registerScrollToTopOverride = (
  scrollToTopOverride: () => void,
): (() => void) => {
  override = scrollToTopOverride;
  return () => {
    Eif (override === scrollToTopOverride) {
      override = null;
    }
  };
};
 
export const scrollToTop = (): void => {
  Eif (override) {
    override();
    return;
  }
  window.scrollTo({ top: 0, behavior: "smooth" });
};