added seed data; image uploads via server actions; infinite article grid

This commit is contained in:
2025-03-14 20:48:17 +01:00
parent 7135e34699
commit 37233db0ec
73 changed files with 4578 additions and 1137 deletions
@@ -0,0 +1,44 @@
"use client";
import React from "react";
export function useInfiniteItemsObserver({
bottomObserverRef,
fetchNextPage,
hasNextPage,
isFetchingNextPage,
}: {
bottomObserverRef: React.RefObject<HTMLLIElement>;
fetchNextPage: () => void;
hasNextPage: boolean;
isFetchingNextPage: boolean;
}) {
const bottomObserver = React.useCallback(
(entries: IntersectionObserverEntry[]) => {
const [entry] = entries;
if (entry?.isIntersecting && hasNextPage && !isFetchingNextPage) {
fetchNextPage();
}
},
[fetchNextPage, hasNextPage, isFetchingNextPage],
);
// Setup bottom observer
React.useEffect(() => {
const bottomObserverElement = bottomObserverRef.current;
// Bottom observer
const observerBottom = new IntersectionObserver(bottomObserver, {
root: null,
rootMargin: "100px",
threshold: 0.1,
});
if (bottomObserverElement) observerBottom.observe(bottomObserverElement);
return () => {
if (bottomObserverElement)
observerBottom.unobserve(bottomObserverElement);
};
}, [bottomObserver, bottomObserverRef]);
}