Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit f4ed9ae

Browse files
committed
Add pagination mechanism to SpaceHierarchy based on IntersectionObserver
1 parent 259627f commit f4ed9ae

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

src/components/structures/SpaceHierarchy.tsx

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ const SpaceHierarchy = ({
377377

378378
const [selected, setSelected] = useState(new Map<string, Set<string>>()); // Map<parentId, Set<childId>>
379379

380-
const { loading, rooms, hierarchy } = useSpaceSummary(space);
380+
const { loading, rooms, hierarchy, loadMore } = useSpaceSummary(space);
381381

382382
const filteredRoomSet = useMemo<Set<IHierarchyRoom>>(() => {
383383
if (!rooms.length) return new Set();
@@ -408,6 +408,29 @@ const SpaceHierarchy = ({
408408
const [removing, setRemoving] = useState(false);
409409
const [saving, setSaving] = useState(false);
410410

411+
const handleObserver = (entries: IntersectionObserverEntry[]) => {
412+
const target = entries[0];
413+
if (target.isIntersecting) {
414+
loadMore();
415+
}
416+
};
417+
418+
const observerRef = useRef<IntersectionObserver>();
419+
const loaderRef = (element: HTMLDivElement) => {
420+
if (observerRef.current) {
421+
observerRef.current.disconnect();
422+
} else if (element) {
423+
observerRef.current = new IntersectionObserver(handleObserver, {
424+
root: element.parentElement,
425+
rootMargin: "0px 0px 600px 0px",
426+
});
427+
}
428+
429+
if (observerRef.current && element) {
430+
observerRef.current.observe(element);
431+
}
432+
};
433+
411434
if (!loading && hierarchy.noSupport) {
412435
return <p>{ _t("Your server does not support showing space hierarchies.") }</p>;
413436
}
@@ -542,6 +565,10 @@ const SpaceHierarchy = ({
542565
}}
543566
/>
544567
</>;
568+
569+
loader = <div ref={loaderRef}>
570+
<Spinner />
571+
</div>;
545572
} else {
546573
results = <div className="mx_SpaceHierarchy_noResults">
547574
<h3>{ _t("No results found") }</h3>

0 commit comments

Comments
 (0)