-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
eabf860
commit 2f62f0d
Showing
12 changed files
with
200 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
'use client' | ||
import { useEffect, useRef, useState } from 'react'; | ||
|
||
const AutoPlayAudio = () => { | ||
const audioRef = useRef<HTMLAudioElement>(null); | ||
const [isPlaying, setIsPlaying] = useState(false); | ||
|
||
const handlePlay = async () => { | ||
if (audioRef.current) { | ||
try { | ||
await audioRef.current.play(); | ||
setIsPlaying(true); | ||
} catch (err) { | ||
console.error('Failed to play audio:', err); | ||
} | ||
} | ||
}; | ||
|
||
const handlePause = () => { | ||
if (audioRef.current) { | ||
audioRef.current.pause(); | ||
setIsPlaying(false); | ||
} | ||
}; | ||
|
||
useEffect(() => { | ||
handlePlay(); | ||
}, []); | ||
|
||
return ( | ||
<div> | ||
<audio ref={audioRef} src="/background-audio.mp3" /> | ||
{isPlaying ? ( | ||
<button onClick={handlePause}>Pause</button> | ||
) : ( | ||
<button onClick={handlePlay}>Play</button> | ||
)} | ||
</div> | ||
); | ||
}; | ||
|
||
export default AutoPlayAudio; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,47 @@ | ||
'use client' | ||
import { useEffect, useState } from 'react'; | ||
"use client"; | ||
import { useEffect, useState } from "react"; | ||
|
||
const CurrentTime: React.FC = () => { | ||
const [currentTime, setCurrentTime] = useState<string>(''); | ||
const [currentTime, setCurrentTime] = useState<string>(""); | ||
const [curDay, setCurDay] = useState<string>(""); | ||
|
||
useEffect(() => { | ||
const updateTime = () => { | ||
const now = new Date(); | ||
const formattedTime = new Intl.DateTimeFormat('en-US', { | ||
weekday: 'short', | ||
era: 'long', | ||
hour: 'numeric', | ||
minute:"numeric", | ||
hour12: true , | ||
dayPeriod: 'short', | ||
const formattedTime = new Intl.DateTimeFormat("en-US", { | ||
hour: "2-digit", | ||
hour12: true, | ||
dayPeriod: "short", | ||
|
||
}).format(now); | ||
setCurrentTime(formattedTime); | ||
}; | ||
|
||
updateTime(); // Initial call to set the time immediately | ||
const intervalId = setInterval(updateTime, 1000); // Update time every second | ||
|
||
return () => clearInterval(intervalId); // Cleanup interval on component unmount | ||
}, []); | ||
|
||
return <div | ||
className='font-bold' | ||
>{currentTime}</div>; | ||
useEffect(() => { | ||
const updateDay = () => { | ||
const now = new Date(); | ||
const formattedDay = new Intl.DateTimeFormat("en-US", { | ||
weekday: 'short', | ||
}).format(now); | ||
setCurDay(formattedDay); | ||
}; | ||
updateDay(); // Initial call to set the day immediately | ||
const intervalId = setInterval(updateDay, 1000); // Update day every second | ||
return () => clearInterval(intervalId); // Cleanup interval on component unmount | ||
}, []); | ||
return ( | ||
<> | ||
<div className="flex gap-1"> | ||
<div className="font-bold sm:text-2xl">{curDay}</div> | ||
<div className="font-bold sm:text-4xl">{currentTime}</div> | ||
</div> | ||
</> | ||
); | ||
}; | ||
|
||
export default CurrentTime; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.