ultisuite-client/hooks/use-mail-list-infinite-scroll.ts
R3D347HR4Y 5304790ed5
Some checks are pending
E2E / Playwright e2e (push) Waiting to run
feat(auth): enhance session management and identity provider settings
- Added SessionGuard component to manage session expiration and online status.
- Updated AuthProvider to streamline session fetching and handling.
- Introduced IdentityProvidersSection for managing OAuth, SAML, and LDAP identity providers.
- Implemented identity provider guides for easier configuration.
- Enhanced mail settings with infinite scroll option for improved user experience.
- Updated global styles and layout components for better consistency across the application.
2026-06-09 09:36:46 +02:00

52 lines
1.1 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"use client"
import { useEffect, type RefObject } from "react"
type UseMailListInfiniteScrollOptions = {
enabled: boolean
sentinelRef: RefObject<HTMLElement | null>
scrollRootRef: RefObject<HTMLElement | null>
hasMore: boolean
isLoadingMore: boolean
onLoadMore: () => void
/** Charge avant le bas visible pour éviter lattente au scroll. */
rootMargin?: string
}
export function useMailListInfiniteScroll({
enabled,
sentinelRef,
scrollRootRef,
hasMore,
isLoadingMore,
onLoadMore,
rootMargin = "480px",
}: UseMailListInfiniteScrollOptions) {
useEffect(() => {
if (!enabled || !hasMore) return
const sentinel = sentinelRef.current
const root = scrollRootRef.current
if (!sentinel || !root) return
const observer = new IntersectionObserver(
([entry]) => {
if (!entry?.isIntersecting || isLoadingMore) return
onLoadMore()
},
{ root, rootMargin, threshold: 0 }
)
observer.observe(sentinel)
return () => observer.disconnect()
}, [
enabled,
hasMore,
isLoadingMore,
onLoadMore,
rootMargin,
sentinelRef,
scrollRootRef,
])
}