-
-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathplayer-play-button.tsx
More file actions
54 lines (50 loc) · 1.23 KB
/
player-play-button.tsx
File metadata and controls
54 lines (50 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
"use client";
import { Button } from "@/components/ui/button";
import { useContext, useEffect } from "react";
import { FaCirclePause, FaPlay } from "react-icons/fa6";
import { PlayerContext } from "@/components/player-context";
import type { PodcastQueryResult } from "@/sanity/types";
export default function PlayerPlayButton({
podcast,
}: {
podcast: NonNullable<PodcastQueryResult>;
}) {
const {
setPodcast,
audio,
audioRef,
setIsOpen,
podcast: currentPodcast,
} = useContext(PlayerContext);
const setCurrent = () => {
setIsOpen(true);
if (
audioRef?.current &&
podcast?.spotify?.enclosures?.at(0)?.url === audio.src
) {
audioRef.current.play();
return;
}
setPodcast(() => podcast);
};
if (!audioRef) return null;
return (
<>
{currentPodcast?._id === podcast?._id && audio?.isPlaying ? (
<Button
variant="default"
onClick={() => audioRef.current?.pause()}
className="flex gap-2"
>
<FaCirclePause className="h-5 w-5" />
<div className="text-xl">Pause Episode</div>
</Button>
) : (
<Button variant="default" onClick={setCurrent} className="flex gap-2">
<FaPlay className="h-5 w-5" />
<div className="text-xl">Play Episode</div>
</Button>
)}
</>
);
}