Skip to content

Commit b9858e1

Browse files
authored
Merge pull request #9 from kalayciburak/feature/back-to-top-and-scroll-controls
feat: add back-to-top button and reposition sound toggle
2 parents 0a5803f + 013c5a1 commit b9858e1

3 files changed

Lines changed: 52 additions & 1 deletion

File tree

client/src/App.jsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { SoundProvider } from "./hooks/useSoundEffects";
77
import { QueryProvider } from "./providers/QueryProvider";
88
import ErrorBoundary from "./components/ErrorBoundary";
99
import SoundToggle from "./components/SoundToggle";
10+
import BackToTop from "./components/BackToTop";
1011

1112
const Login = lazy(() => import("./pages/Login"));
1213
const Dashboard = lazy(() => import("./pages/Dashboard"));
@@ -94,6 +95,7 @@ const App = () => {
9495
}}
9596
/>
9697
<SoundToggle />
98+
<BackToTop />
9799
</BrowserRouter>
98100
</SoundProvider>
99101
</QueryProvider>
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import { useState, useEffect } from "react";
2+
import { ChevronUpIcon } from "@heroicons/react/24/outline";
3+
import { useSoundEffects } from "../hooks/useSoundEffects";
4+
import { SOUND_TYPES } from "../utils/soundUtils";
5+
6+
const BackToTop = () => {
7+
const [isVisible, setIsVisible] = useState(false);
8+
const { playSound } = useSoundEffects();
9+
10+
useEffect(() => {
11+
const handleScroll = () => {
12+
// Show button when user scrolls down 300px
13+
if (window.scrollY > 300) {
14+
setIsVisible(true);
15+
} else {
16+
setIsVisible(false);
17+
}
18+
};
19+
20+
window.addEventListener("scroll", handleScroll);
21+
22+
return () => {
23+
window.removeEventListener("scroll", handleScroll);
24+
};
25+
}, []);
26+
27+
const scrollToTop = () => {
28+
playSound(SOUND_TYPES.CLICK);
29+
window.scrollTo({
30+
top: 0,
31+
behavior: "smooth",
32+
});
33+
};
34+
35+
if (!isVisible) return null;
36+
37+
return (
38+
<button
39+
onClick={scrollToTop}
40+
className="fixed bottom-6 right-6 z-50 p-3 rounded-full bg-gradient-to-br from-indigo-500/70 to-purple-600/70 hover:from-indigo-600 hover:to-purple-700 shadow-lg hover:shadow-xl backdrop-blur-sm border border-white/20 transition-all duration-300 hover:scale-110 cursor-pointer group opacity-60 hover:opacity-100"
41+
aria-label="Başa Dön"
42+
title="Başa Dön"
43+
>
44+
<ChevronUpIcon className="h-5 w-5 text-white group-hover:animate-pulse" />
45+
</button>
46+
);
47+
};
48+
49+
export default BackToTop;

client/src/components/SoundToggle.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const SoundToggle = () => {
1717
return (
1818
<button
1919
onClick={handleClick}
20-
className="fixed bottom-6 right-6 z-50 p-3 rounded-full bg-gradient-to-br from-indigo-500/70 to-purple-600/70 hover:from-indigo-600 hover:to-purple-700 shadow-lg hover:shadow-xl backdrop-blur-sm border border-white/20 transition-all duration-300 hover:scale-110 cursor-pointer group opacity-60 hover:opacity-100"
20+
className="fixed bottom-6 left-6 z-50 p-3 rounded-full bg-gradient-to-br from-indigo-500/70 to-purple-600/70 hover:from-indigo-600 hover:to-purple-700 shadow-lg hover:shadow-xl backdrop-blur-sm border border-white/20 transition-all duration-300 hover:scale-110 cursor-pointer group opacity-60 hover:opacity-100"
2121
aria-label={isSoundEnabled ? "Sesi Kapat" : "Sesi Aç"}
2222
title={isSoundEnabled ? "Sesi Kapat" : "Sesi Aç"}
2323
>

0 commit comments

Comments
 (0)