Skip to content

Commit 1d00bba

Browse files
Added google analytics and fixed bug on sound slider
1 parent 8d76c3b commit 1d00bba

File tree

3 files changed

+35
-11
lines changed

3 files changed

+35
-11
lines changed

app/entry.client.tsx

+22-1
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,34 @@
55
*/
66

77
import { RemixBrowser } from "@remix-run/react";
8-
import { startTransition, StrictMode } from "react";
8+
import { startTransition, StrictMode, useEffect } from "react";
99
import { hydrateRoot } from "react-dom/client";
1010

11+
12+
function GoogleAnalytics() {
13+
useEffect(() => {
14+
15+
const script = document.createElement("script");
16+
script.async = true;
17+
script.src = `https://www.googletagmanager.com/gtag/js?id=G-RY5T39HZT9`;
18+
document.head.appendChild(script);
19+
20+
const script2 = document.createElement("script");
21+
script2.innerHTML = `
22+
window.dataLayer = window.dataLayer || [];
23+
function gtag(){dataLayer.push(arguments);}
24+
gtag('js', new Date());
25+
gtag('config', 'G-RY5T39HZT9');
26+
`;
27+
document.head.appendChild(script2);
28+
}, []);
29+
return null;
30+
}
1131
startTransition(() => {
1232
hydrateRoot(
1333
document,
1434
<StrictMode>
35+
<GoogleAnalytics />
1536
<RemixBrowser />
1637
</StrictMode>
1738
);

app/routes/components/AudioPlayerContext.jsx

+11-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export const AudioPlayerProvider = ({ children }) => {
1616
}
1717
];
1818

19+
const [volume, setVolume] = useState(80);
1920
const [isPlaying, setIsPlaying] = useState(false);
2021
const [currentTrackIndex, setCurrentTrackIndex] = useState(0);
2122
const audioRef = useRef(null);
@@ -47,9 +48,18 @@ export const AudioPlayerProvider = ({ children }) => {
4748
setCurrentTrackIndex(nextIndex);
4849
};
4950

51+
const handleVolumeChange = (event) => {
52+
const newVolume = event.target.value;
53+
setVolume(newVolume);
54+
if (audioRef.current) {
55+
audioRef.current.volume = newVolume / 100; // Update volume
56+
}
57+
};
58+
5059
return (
5160
<AudioPlayerContext.Provider
52-
value={{ isPlaying, handlePlayPause, handleNext, currentTrackIndex, audioList }}
61+
value={{ isPlaying, handlePlayPause, handleNext, volume,
62+
handleVolumeChange, currentTrackIndex, audioList }}
5363
>
5464
{children}
5565
</AudioPlayerContext.Provider>

app/routes/components/ControlCenter.jsx

+2-9
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,14 @@ const connectivity =[
2323
{id:3, Icon1: <AirDropIcon />, textbig: "Airdrop",textsmall: "Contacts Only" },
2424
]
2525

26-
const [volume, setVolume] = useState(70);
2726
const audioRef = useRef(null);
2827
const [selectedItems, setSelectedItems] = useState({});
2928
const [brightness, setBrightness] = useState(100);
3029
const {fullScreenSelected, toggleFullScreen } = useContext(FullScreenContext);
31-
const { isPlaying, handlePlayPause, handleNext, currentTrackIndex, audioList } = useContext(AudioPlayerContext);
30+
const { isPlaying, handlePlayPause, handleNext, volume,
31+
handleVolumeChange, currentTrackIndex, audioList } = useContext(AudioPlayerContext);
3232

3333

34-
const handleVolumeChange = (e) => {
35-
const newVolume = e.target.value;
36-
setVolume(newVolume);
37-
if (audioRef.current) {
38-
audioRef.current.volume = newVolume / 100;
39-
}
40-
};
4134

4235

4336
const handleLofiWebsite = () =>{

0 commit comments

Comments
 (0)