mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-09-01 14:19:40 +08:00
1efc1d0f5b
use https://www.electronjs.org/docs/latest/api/web-contents-view to serve different tab views added tabs view manager in electron to handle multi-view actions and events. fix AF-1111 fix AF-999 fix PD-1459 fix AF-964 PD-1458
28 lines
821 B
TypeScript
28 lines
821 B
TypeScript
import { debounce } from 'lodash-es';
|
|
import { useMemo, useState } from 'react';
|
|
|
|
export function useHasScrollTop() {
|
|
const [hasScrollTop, setHasScrollTop] = useState(false);
|
|
const containerRefFn = useMemo(() => {
|
|
let unsub: (() => void) | null = null;
|
|
return (container: HTMLElement | null) => {
|
|
unsub?.();
|
|
const updateScrollTop = debounce(() => {
|
|
if (container) {
|
|
setTimeout(() => {
|
|
const hasScrollTop = container.scrollTop > 0;
|
|
setHasScrollTop(hasScrollTop);
|
|
});
|
|
}
|
|
}, 50);
|
|
container?.addEventListener('scroll', updateScrollTop);
|
|
updateScrollTop();
|
|
unsub = () => {
|
|
container?.removeEventListener('scroll', updateScrollTop);
|
|
};
|
|
};
|
|
}, []);
|
|
|
|
return [containerRefFn, hasScrollTop] as const;
|
|
}
|