feat: add 'Stop All Sounds' button to Player component for improved sound control
Some checks failed
Frontend CI / lint (push) Failing after 20s
Frontend CI / build (push) Has been skipped

This commit is contained in:
JSC
2025-09-20 15:50:47 +02:00
parent 7c3a8aab64
commit da4566c789

View File

@@ -16,6 +16,7 @@ import {
type PlayerState, type PlayerState,
playerService, playerService,
} from '@/lib/api/services/player' } from '@/lib/api/services/player'
import { soundsService } from '@/lib/api/services/sounds'
import { PLAYER_EVENTS, playerEvents } from '@/lib/events' import { PLAYER_EVENTS, playerEvents } from '@/lib/events'
import { cn } from '@/lib/utils' import { cn } from '@/lib/utils'
import { formatDuration } from '@/utils/format-duration' import { formatDuration } from '@/utils/format-duration'
@@ -216,6 +217,16 @@ export function Player({ className, onPlayerModeChange }: PlayerProps) {
} }
}, [state.current_sound]) }, [state.current_sound])
const handleStopAllSounds = useCallback(async () => {
try {
await soundsService.stopSounds()
toast.success('All sounds stopped')
} catch (error) {
console.error('Failed to stop all sounds:', error)
toast.error('Failed to stop all sounds')
}
}, [])
const getModeIcon = () => { const getModeIcon = () => {
switch (state.mode) { switch (state.mode) {
case 'continuous': case 'continuous':
@@ -529,6 +540,16 @@ export function Player({ className, onPlayerModeChange }: PlayerProps) {
{/* Header */} {/* Header */}
<div className="p-4 border-b flex items-center justify-between"> <div className="p-4 border-b flex items-center justify-between">
<h2 className="text-lg font-semibold">Now Playing</h2> <h2 className="text-lg font-semibold">Now Playing</h2>
<div className="flex items-center gap-2">
<Button
size="sm"
variant="ghost"
onClick={handleStopAllSounds}
className="text-red-600 hover:text-red-700 hover:bg-red-50 dark:text-red-400 dark:hover:text-red-300 dark:hover:bg-red-950/50"
>
<Square className="h-4 w-4 mr-2 fill-current" />
Stop All Sounds
</Button>
<Button <Button
size="sm" size="sm"
variant="ghost" variant="ghost"
@@ -538,6 +559,7 @@ export function Player({ className, onPlayerModeChange }: PlayerProps) {
Exit Fullscreen Exit Fullscreen
</Button> </Button>
</div> </div>
</div>
<div className="flex-1 flex"> <div className="flex-1 flex">
{/* Main Player Area */} {/* Main Player Area */}