Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { AnimatedBackground } from '@/components/AnimatedBackground';
import MaintenanceBanner from '@/components/layout/MaintenanceBanner';
import BackgroundMesh from '@/components/layout/BackgroundMesh';
import PageWrapper from '@/components/layout/PageWrapper';
import ScrollToTop from '@/components/layout/ScrollToTop';
import { ThemeProvider } from "@/components/providers/theme-provider";
import "./globals.css";

Expand Down Expand Up @@ -115,6 +116,7 @@ export default function RootLayout({
{children}
</PageWrapper>
<FooterWrapper />
<ScrollToTop />
</RealTimeProvider>
</GamificationProvider>
</AuthProvider>
Expand Down
49 changes: 49 additions & 0 deletions src/components/layout/ScrollToTop.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
"use client";

import { useState, useEffect } from "react";
import { ArrowUp } from "lucide-react";
import { motion, AnimatePresence } from "framer-motion";

export default function ScrollToTop() {
const [isVisible, setIsVisible] = useState(false);

useEffect(() => {
const toggleVisibility = () => {
if (window.scrollY > 300) {
setIsVisible(true);
} else {
setIsVisible(false);
}
Comment on lines +12 to +16
};

window.addEventListener("scroll", toggleVisibility);

return () => {
window.removeEventListener("scroll", toggleVisibility);
};
}, []);

const scrollToTop = () => {
window.scrollTo({
top: 0,
behavior: "smooth",
});
};

return (
<AnimatePresence>
{isVisible && (
<motion.button
initial={{ opacity: 0, scale: 0.8 }}
animate={{ opacity: 1, scale: 1 }}
exit={{ opacity: 0, scale: 0.8 }}
onClick={scrollToTop}
className="fixed bottom-8 right-8 z-50 p-3 rounded-full bg-blue-600 text-white shadow-lg hover:bg-blue-700 transition-colors duration-300 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-offset-2 dark:focus:ring-offset-slate-900"
aria-label="Scroll to top"
>
<ArrowUp className="h-6 w-6" />
</motion.button>
)}
</AnimatePresence>
);
}