Initial open-source self-hosted Songs2YT edition

This commit is contained in:
Songs2YT
2026-07-17 02:23:59 +02:00
commit 2aa8a84781
134 changed files with 17758 additions and 0 deletions
+40
View File
@@ -0,0 +1,40 @@
"use client";
import { useEffect, useRef, useState } from "react";
type Options = {
threshold?: number;
rootMargin?: string;
once?: boolean;
};
export function useInView<T extends HTMLElement = HTMLDivElement>({
threshold = 0.15,
rootMargin = "0px 0px -40px 0px",
once = true,
}: Options = {}) {
const ref = useRef<T>(null);
const [inView, setInView] = useState(false);
useEffect(() => {
const el = ref.current;
if (!el) return;
const observer = new IntersectionObserver(
([entry]) => {
if (entry.isIntersecting) {
setInView(true);
if (once) observer.unobserve(el);
} else if (!once) {
setInView(false);
}
},
{ threshold, rootMargin },
);
observer.observe(el);
return () => observer.disconnect();
}, [threshold, rootMargin, once]);
return { ref, inView };
}