* chore * chore * feat: paginated event types * fix: event types page * fix: k bar * fix: event type order * fix: type error * chore: remove commented code * chore: type err * chore: type err and feedback * feat: add old component * chore: missing import * fix: add isInfiniteScrollEnabled prop * chore: type err * chore: type error * feat: auto fetch next page when button is in view * Update packages/lib/server/repository/eventType.ts * Update packages/lib/server/repository/eventType.ts * chore: feedback * fix: managed event types * fix: Review fixes for event-types-infinite-scroll (#16047) * Review fixes * chore: missing import --------- Co-authored-by: Udit Takkar <53316345+Udit-takkar@users.noreply.github.com> Co-authored-by: Udit Takkar <udit222001@gmail.com> * chore: type error * chore * fix: delete event type * fix: create event dialog * fix: create and duplicate dialog * chore: simplify return type * fix: type * chore: invalidate query * chore: remove query * fix duplicated event not showing. --------- Co-authored-by: Peer Richelsen <peeroke@gmail.com> Co-authored-by: Hariom Balhara <hariombalhara@gmail.com>
44 lines
1.1 KiB
TypeScript
44 lines
1.1 KiB
TypeScript
import React from "react";
|
|
|
|
const isInteractionObserverSupported = typeof window !== "undefined" && "IntersectionObserver" in window;
|
|
|
|
export const useInViewObserver = (onInViewCallback: () => void, root?: Element | Document | null) => {
|
|
const [node, setRef] = React.useState<HTMLElement | null>(null);
|
|
|
|
const onInViewCallbackRef = React.useRef(onInViewCallback);
|
|
onInViewCallbackRef.current = onInViewCallback;
|
|
|
|
React.useEffect(() => {
|
|
if (!isInteractionObserverSupported) {
|
|
// Skip interaction check if not supported in browser
|
|
return;
|
|
}
|
|
|
|
let observer: IntersectionObserver;
|
|
if (node && node.parentElement) {
|
|
observer = new IntersectionObserver(
|
|
([entry]) => {
|
|
if (entry.isIntersecting) {
|
|
onInViewCallbackRef.current();
|
|
}
|
|
},
|
|
{
|
|
// We want to accept null as root
|
|
root: root !== undefined ? root : document.body,
|
|
}
|
|
);
|
|
observer.observe(node);
|
|
}
|
|
|
|
return () => {
|
|
if (observer) {
|
|
observer.disconnect();
|
|
}
|
|
};
|
|
}, [node]);
|
|
|
|
return {
|
|
ref: setRef,
|
|
};
|
|
};
|