Skip to content

Commit 18aabf4

Browse files
committed
Cleanup code
1 parent a31b328 commit 18aabf4

File tree

3 files changed

+21
-33
lines changed

3 files changed

+21
-33
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
.DS_Store
2+
.python_modules/

nepalingo-web/src/components/Card.tsx

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,22 @@ const Card: React.FC<CardProps> = ({
3131
togglePlayback();
3232
};
3333

34+
const PronunciationButton = () => {
35+
if (!PronounciationUrl) {
36+
return null;
37+
}
38+
39+
return (
40+
<button
41+
type="button"
42+
onClick={handlePronunciation}
43+
className="absolute right-4 bottom-4 z-10 text-white"
44+
>
45+
<FontAwesomeIcon icon={faVolumeHigh} />
46+
</button>
47+
);
48+
};
49+
3450
return (
3551
<div className="relative rounded-2xl overflow-hidden shadow-2xl w-[300px] h-[400px] sm:w-[300px] sm:h-[400px] md:w-[350px] md:h-[450px] lg:w-[519px] lg:h-[600px]">
3652
{/* Front View */}
@@ -60,14 +76,7 @@ const Card: React.FC<CardProps> = ({
6076
<p className="text-lg text-white sm:text-lg md:text-xl lg:text-2xl">
6177
{Pronunciation}
6278
</p>
63-
{PronounciationUrl && (
64-
<button
65-
onClick={handlePronunciation}
66-
className="absolute right-4 bottom-4 z-10 text-white"
67-
>
68-
<FontAwesomeIcon icon={faVolumeHigh} />
69-
</button>
70-
)}
79+
<PronunciationButton />
7180
</div>
7281
<div className="relative w-full h-[30%] rounded-b-2xl overflow-hidden flex items-center justify-center">
7382
{ImageUrl && (
@@ -113,14 +122,7 @@ const Card: React.FC<CardProps> = ({
113122
<p className="text-lg sm:text-lg md:text-xl lg:text-2xl">
114123
{Pronunciation}
115124
</p>
116-
{PronounciationUrl && (
117-
<button
118-
onClick={handlePronunciation}
119-
className="absolute right-4 bottom-4 z-10 text-white"
120-
>
121-
<FontAwesomeIcon icon={faVolumeHigh} />
122-
</button>
123-
)}
125+
<PronunciationButton />
124126
</div>
125127
<div className="relative h-[70%] w-full rounded-b-2xl overflow-hidden flex items-center justify-center">
126128
{ImageUrl && (

nepalingo-web/src/hooks/useAudioPlayer.ts

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ const resetAudio = (audio: HTMLAudioElement | null) => {
1111

1212
const useAudioPlayer = (audioUrl?: string) => {
1313
const [audio, setAudio] = useState<HTMLAudioElement | null>(null);
14-
const [lastUrl, setLastUrl] = useState<string | undefined>(audioUrl);
1514

1615
const clearAudio = useCallback(() => {
1716
setAudio((currentAudio) => {
@@ -30,22 +29,8 @@ const useAudioPlayer = (audioUrl?: string) => {
3029
}, [audio]);
3130

3231
useEffect(() => {
33-
if (!audioUrl) {
34-
clearAudio();
35-
if (lastUrl !== undefined) {
36-
setLastUrl(undefined);
37-
}
38-
return;
39-
}
40-
41-
if (lastUrl && lastUrl !== audioUrl) {
42-
clearAudio();
43-
}
44-
45-
if (lastUrl !== audioUrl) {
46-
setLastUrl(audioUrl);
47-
}
48-
}, [audioUrl, lastUrl, clearAudio]);
32+
clearAudio();
33+
}, [audioUrl, clearAudio]);
4934

5035
const togglePlayback = useCallback(() => {
5136
if (!audioUrl) {

0 commit comments

Comments
 (0)