Fixed issues

This commit is contained in:
2026-02-14 22:08:43 +01:00
parent 8dc205d54a
commit 821ba82ecc
9 changed files with 159 additions and 237 deletions

View File

@@ -55,77 +55,3 @@ export function useScrollAnimation<T extends HTMLElement = HTMLDivElement>(
reset,
};
}
export function useCountUp(
end: number,
duration: number = 2000,
start: number = 0,
) {
const [count, setCount] = useState(start);
const [isAnimating, setIsAnimating] = useState(false);
const countRef = useRef(start);
const startAnimation = useCallback(() => {
if (isAnimating) return;
setIsAnimating(true);
const startTime = Date.now();
const range = end - start;
const animate = () => {
const elapsed = Date.now() - startTime;
const progress = Math.min(elapsed / duration, 1);
const easeOut = 1 - Math.pow(1 - progress, 3);
const currentCount = Math.floor(start + range * easeOut);
countRef.current = currentCount;
setCount(currentCount);
if (progress < 1) {
requestAnimationFrame(animate);
} else {
setCount(end);
setIsAnimating(false);
}
};
requestAnimationFrame(animate);
}, [end, duration, start, isAnimating]);
const reset = useCallback(() => {
setCount(start);
setIsAnimating(false);
}, [start]);
return { count, startAnimation, reset, isAnimating };
}
export function useParallax(speed: number = 0.5) {
const ref = useRef<HTMLDivElement>(null);
const [offset, setOffset] = useState(0);
useEffect(() => {
if (typeof window === "undefined") return;
const handleScroll = () => {
if (!ref.current) return;
const rect = ref.current.getBoundingClientRect();
const scrolled = window.scrollY;
const elementTop = rect.top + scrolled;
const relativeScroll = scrolled - elementTop + window.innerHeight;
setOffset(relativeScroll * speed * 0.1);
};
window.addEventListener("scroll", handleScroll, { passive: true });
handleScroll();
return () => {
window.removeEventListener("scroll", handleScroll);
};
}, [speed]);
return { ref, offset };
}

View File

@@ -1,11 +1,11 @@
"use client";
import { useState } from "react";
import { useEffect, useState } from "react";
import { useTheme as useNextTheme } from "next-themes";
export function useTheme() {
const { theme, resolvedTheme, setTheme } = useNextTheme();
const [mounted] = useState(true);
const [mounted, setMounted] = useState(true);
const currentTheme = resolvedTheme ?? theme ?? "light";