-
Notifications
You must be signed in to change notification settings - Fork 13
Feat/library #28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Feat/library #28
Changes from all commits
a4e3baf
0cbd77c
7e9d374
c73faf3
eb02b1d
d58fca5
a8940ea
74ecc3c
5507528
67e3265
59ad350
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
|
|
||
| ## Code Rules | ||
| - Follow ESLint config defined in `./eslint.config.mjs` | ||
| - Max cyclomatic complexity per function: **5** | ||
| - Max parameters per function: **3** | ||
| - Max file length: **100 lines** — break into smaller files if exceeded | ||
| - Extract shared/common logic into utils | ||
| - Keep constants in a separate constants file | ||
| - Write proper test cases for every feature | ||
| - Build small features first before moving forward | ||
|
|
||
|
|
||
| DISTILLED_AESTHETICS_PROMPT = """ | ||
| <frontend_aesthetics> | ||
| You tend to converge toward generic, "on distribution" outputs. In frontend design, this creates what users call the "AI slop" aesthetic. Avoid this: make creative, distinctive frontends that surprise and delight. Focus on: | ||
|
|
||
| Typography: Choose fonts that are beautiful, unique, and interesting. Avoid generic fonts like Arial and Inter; opt instead for distinctive choices that elevate the frontend's aesthetics. | ||
|
|
||
| Color & Theme: Commit to a cohesive aesthetic. Use CSS variables for consistency. Dominant colors with sharp accents outperform timid, evenly-distributed palettes. Draw from Music Application themes and cultural aesthetics for inspiration. | ||
|
|
||
| Motion: Use animations for effects and micro-interactions. Prioritize CSS-only solutions for HTML. Use Motion library for React when available. Focus on high-impact moments: one well-orchestrated page load with staggered reveals (animation-delay) creates more delight than scattered micro-interactions. | ||
|
|
||
| Backgrounds: Create atmosphere and depth rather than defaulting to solid colors. Layer CSS gradients, use geometric patterns, or add contextual effects that match the overall aesthetic. | ||
|
|
||
| Avoid generic AI-generated aesthetics: | ||
| - Overused font families (Inter, Roboto, Arial, system fonts) | ||
| - Clichéd color schemes (particularly purple gradients on white backgrounds) | ||
| - Predictable layouts and component patterns | ||
| - Cookie-cutter design that lacks context-specific character | ||
|
|
||
| Interpret creatively and make unexpected choices that feel genuinely designed for the context. Vary between light and dark themes, different fonts, different aesthetics. You still tend to converge on common choices (Space Grotesk, for example) across generations. Avoid this: it is critical that you think outside the box! | ||
| </frontend_aesthetics> | ||
| """ | ||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export const DEFAULT_VOLUME = 0.7; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| import React from 'react'; | ||
| import PropTypes from 'prop-types'; | ||
| import { | ||
| StepBackwardFilled, | ||
| PlayCircleFilled, | ||
| PauseCircleFilled, | ||
| StepForwardFilled, | ||
| SoundFilled | ||
| } from '@ant-design/icons'; | ||
| import { useAudioPlayer } from './useAudioPlayer'; | ||
| import { | ||
| PlayerContainer, | ||
| NowPlayingArt, | ||
| PlayerTrackInfo, | ||
| TrackTitle, | ||
| TrackArtist, | ||
| PlayerControls, | ||
| ControlButton, | ||
| ProgressSlider, | ||
| VolumeGroup, | ||
| VolumeSlider | ||
| } from '@components/styled/playerBar'; | ||
|
|
||
| const AudioPlayer = ({ currentSong, onNext, onPrev }) => { | ||
| const player = useAudioPlayer(currentSong, onNext); | ||
|
|
||
| if (!currentSong) { | ||
| return null; | ||
| } | ||
|
|
||
| return ( | ||
| <PlayerContainer data-testid="audio-player"> | ||
| <NowPlayingArt src={currentSong.artworkUrl} alt={currentSong.trackName} /> | ||
| <PlayerTrackInfo> | ||
| <TrackTitle>{currentSong.trackName}</TrackTitle> | ||
| <TrackArtist>{currentSong.artistName}</TrackArtist> | ||
| </PlayerTrackInfo> | ||
| <PlayerControls> | ||
| <ControlButton data-testid="prev-btn" onClick={onPrev}> | ||
| <StepBackwardFilled /> | ||
| </ControlButton> | ||
| <ControlButton data-testid="play-btn" primary onClick={player.togglePlay}> | ||
| {player.isPlaying ? <PauseCircleFilled /> : <PlayCircleFilled />} | ||
| </ControlButton> | ||
| <ControlButton data-testid="next-btn" onClick={onNext}> | ||
| <StepForwardFilled /> | ||
| </ControlButton> | ||
| </PlayerControls> | ||
| <ProgressSlider | ||
| data-testid="progress-slider" | ||
| type="range" | ||
| min={0} | ||
| max={player.duration || 0} | ||
| value={player.currentTime} | ||
| onChange={(e) => player.seek(Number(e.target.value))} | ||
| style={{ '--fill': `${player.duration ? (player.currentTime / player.duration) * 100 : 0}%` }} | ||
| /> | ||
| <VolumeGroup> | ||
| <SoundFilled data-testid="volume-icon" style={{ color: '#ffff', fontSize: '1rem' }} /> | ||
| <VolumeSlider | ||
| data-testid="volume-slider" | ||
| type="range" | ||
| min={0} | ||
| max={1} | ||
| step={0.05} | ||
| value={player.volume} | ||
| onChange={(e) => player.setVolume(Number(e.target.value))} | ||
| style={{ '--fill': `${player.volume * 100}%` }} | ||
| /> | ||
| </VolumeGroup> | ||
| </PlayerContainer> | ||
| ); | ||
| }; | ||
|
|
||
| AudioPlayer.propTypes = { | ||
| currentSong: PropTypes.object, | ||
| onNext: PropTypes.func.isRequired, | ||
| onPrev: PropTypes.func.isRequired | ||
| }; | ||
|
|
||
| export default AudioPlayer; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| import React from 'react' | ||
| import { renderProvider } from '@utils/testUtils' | ||
| import AudioPlayer from '../index' | ||
|
|
||
| jest.mock('../useAudioPlayer', () => ({ | ||
| useAudioPlayer: () => ({ | ||
| isPlaying: false, | ||
| currentTime: 0, | ||
| duration: 30, | ||
| volume: 0.7, | ||
| togglePlay: jest.fn(), | ||
| seek: jest.fn(), | ||
| setVolume: jest.fn() | ||
| }) | ||
| })) | ||
|
|
||
| const mockSong = { | ||
| trackId: 1, | ||
| trackName: 'Test Song', | ||
| artistName: 'Test Artist', | ||
| artworkUrl: 'test.jpg', | ||
| previewUrl: 'test.mp3' | ||
| } | ||
|
|
||
| describe('<AudioPlayer />', () => { | ||
| const mockNext = jest.fn() | ||
| const mockPrev = jest.fn() | ||
|
|
||
| it('should render nothing when no currentSong', () => { | ||
| const { container } = renderProvider( | ||
| <AudioPlayer currentSong={null} onNext={mockNext} onPrev={mockPrev} /> | ||
| ) | ||
| expect(container.innerHTML).toBe('') | ||
| }) | ||
|
|
||
| it('should render the player when a song is provided', () => { | ||
| const { getByTestId } = renderProvider( | ||
| <AudioPlayer currentSong={mockSong} onNext={mockNext} onPrev={mockPrev} /> | ||
| ) | ||
| expect(getByTestId('audio-player')).toBeTruthy() | ||
| }) | ||
|
|
||
| it('should display track info', () => { | ||
| const { getByText } = renderProvider( | ||
| <AudioPlayer currentSong={mockSong} onNext={mockNext} onPrev={mockPrev} /> | ||
| ) | ||
| expect(getByText('Test Song')).toBeTruthy() | ||
| expect(getByText('Test Artist')).toBeTruthy() | ||
| }) | ||
|
|
||
| it('should render all control buttons', () => { | ||
| const { getByTestId } = renderProvider( | ||
| <AudioPlayer currentSong={mockSong} onNext={mockNext} onPrev={mockPrev} /> | ||
| ) | ||
| expect(getByTestId('prev-btn')).toBeTruthy() | ||
| expect(getByTestId('play-btn')).toBeTruthy() | ||
| expect(getByTestId('next-btn')).toBeTruthy() | ||
| }) | ||
|
|
||
| it('should render progress and volume sliders', () => { | ||
| const { getByTestId } = renderProvider( | ||
| <AudioPlayer currentSong={mockSong} onNext={mockNext} onPrev={mockPrev} /> | ||
| ) | ||
| expect(getByTestId('progress-slider')).toBeTruthy() | ||
| expect(getByTestId('volume-icon')).toBeTruthy() | ||
| expect(getByTestId('volume-slider')).toBeTruthy() | ||
| }) | ||
| }) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| import { renderHook, act } from '@testing-library/react' | ||
| import { useAudioPlayer } from '../useAudioPlayer' | ||
|
|
||
| const mockPlay = jest.fn().mockResolvedValue(undefined) | ||
| const mockPause = jest.fn() | ||
| let mockAudioInstance | ||
|
|
||
| beforeEach(() => { | ||
| mockPlay.mockClear() | ||
| mockPause.mockClear() | ||
| mockAudioInstance = { | ||
| play: mockPlay, | ||
| pause: mockPause, | ||
| volume: 0.7, | ||
| currentTime: 0, | ||
| duration: 0, | ||
| src: '', | ||
| addEventListener: jest.fn(), | ||
| removeEventListener: jest.fn() | ||
| } | ||
| jest.spyOn(global, 'Audio').mockImplementation(() => mockAudioInstance) | ||
| }) | ||
|
|
||
| afterEach(() => { | ||
| global.Audio.mockRestore() | ||
| }) | ||
|
|
||
| describe('useAudioPlayer', () => { | ||
| const song = { trackId: 1, previewUrl: 'http://test.mp3', trackName: 'Test' } | ||
|
|
||
| it('should initialize with default values', () => { | ||
| const { result } = renderHook(() => useAudioPlayer(null, jest.fn())) | ||
| expect(result.current.isPlaying).toBe(false) | ||
| expect(result.current.volume).toBe(0.7) | ||
| expect(result.current.currentTime).toBe(0) | ||
| expect(result.current.duration).toBe(0) | ||
| }) | ||
|
|
||
| it('should play when a song is provided', () => { | ||
| renderHook(() => useAudioPlayer(song, jest.fn())) | ||
| expect(mockAudioInstance.src).toBe(song.previewUrl) | ||
| expect(mockPlay).toHaveBeenCalled() | ||
| }) | ||
|
|
||
| it('should toggle play/pause', () => { | ||
| const { result } = renderHook(() => useAudioPlayer(song, jest.fn())) | ||
| act(() => { | ||
| result.current.togglePlay() | ||
| }) | ||
| expect(mockPause).toHaveBeenCalled() | ||
| }) | ||
|
|
||
| it('should update volume', () => { | ||
| const { result } = renderHook(() => useAudioPlayer(null, jest.fn())) | ||
| act(() => { | ||
| result.current.setVolume(0.5) | ||
| }) | ||
| expect(result.current.volume).toBe(0.5) | ||
| expect(mockAudioInstance.volume).toBe(0.5) | ||
| }) | ||
|
|
||
| it('should seek to a given time', () => { | ||
| const { result } = renderHook(() => useAudioPlayer(null, jest.fn())) | ||
| act(() => { | ||
| result.current.seek(15) | ||
| }) | ||
| expect(mockAudioInstance.currentTime).toBe(15) | ||
| }) | ||
| }) |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,71 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { useRef, useState, useEffect, useCallback } from 'react'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { DEFAULT_VOLUME } from './constants'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export const useAudioPlayer = (song, onSongEnd) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const audioRef = useRef(null); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const [isPlaying, setIsPlaying] = useState(false); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const [currentTime, setCurrentTime] = useState(0); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const [duration, setDuration] = useState(0); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const [volume, setVolumeState] = useState(DEFAULT_VOLUME); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| useEffect(() => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const audio = new Audio(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| audio.volume = DEFAULT_VOLUME; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| audioRef.current = audio; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const onTime = () => setCurrentTime(audio.currentTime); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const onLoaded = () => setDuration(audio.duration); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const onEnded = () => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| setIsPlaying(false); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (onSongEnd) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| onSongEnd(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| audio.addEventListener('timeupdate', onTime); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| audio.addEventListener('loadedmetadata', onLoaded); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| audio.addEventListener('ended', onEnded); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return () => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| audio.removeEventListener('timeupdate', onTime); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| audio.removeEventListener('loadedmetadata', onLoaded); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| audio.removeEventListener('ended', onEnded); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| audio.pause(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, []); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| useEffect(() => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (song?.previewUrl && audioRef.current) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| audioRef.current.src = song.previewUrl; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| audioRef.current.play().catch(() => {}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| setIsPlaying(true); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+38
to
+42
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When the if (song?.previewUrl && audioRef.current) {
audioRef.current.src = song.previewUrl;
audioRef.current.play().catch(() => {});
setIsPlaying(true);
} else if (audioRef.current) {
audioRef.current.pause();
audioRef.current.src = '';
setIsPlaying(false);
} |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, [song?.trackId]); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const togglePlay = useCallback(() => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (!audioRef.current?.src) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (isPlaying) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| audioRef.current.pause(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| audioRef.current.play().catch(() => {}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| setIsPlaying(!isPlaying); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+37
to
+54
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Optimistic Both the song-change effect (line 40-41) and Move 🐛 Proposed fix useEffect(() => {
if (song?.previewUrl && audioRef.current) {
audioRef.current.src = song.previewUrl;
- audioRef.current.play().catch(() => {});
- setIsPlaying(true);
+ audioRef.current.play()
+ .then(() => setIsPlaying(true))
+ .catch(() => setIsPlaying(false));
}
}, [song?.trackId]);
const togglePlay = useCallback(() => {
if (!audioRef.current?.src) {
return;
}
if (isPlaying) {
audioRef.current.pause();
setIsPlaying(false);
} else {
- audioRef.current.play().catch(() => {});
- setIsPlaying(!isPlaying);
+ audioRef.current.play()
+ .then(() => setIsPlaying(true))
+ .catch(() => {});
}
}, [isPlaying]);📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, [isPlaying]); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const seek = useCallback((time) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (audioRef.current) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| audioRef.current.currentTime = time; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, []); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const setVolume = useCallback((v) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| setVolumeState(v); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (audioRef.current) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| audioRef.current.volume = v; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, []); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return { isPlaying, currentTime, duration, volume, togglePlay, seek, setVolume }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| import React from 'react'; | ||
| import PropTypes from 'prop-types'; | ||
| import { HeartFilled, HeartOutlined } from '@ant-design/icons'; | ||
| import { HeartBtn } from '@components/styled/heartButton'; | ||
|
|
||
| const HeartButton = ({ isLiked, onClick }) => { | ||
| const handleClick = (e) => { | ||
| e.stopPropagation(); | ||
| onClick(); | ||
| }; | ||
|
|
||
| return ( | ||
| <HeartBtn | ||
| data-testid="heart-button" | ||
| isLiked={isLiked} | ||
| onClick={handleClick} | ||
| aria-label={isLiked ? 'Unlike song' : 'Like song'} | ||
| > | ||
| {isLiked ? <HeartFilled /> : <HeartOutlined />} | ||
| </HeartBtn> | ||
| ); | ||
| }; | ||
|
|
||
| HeartButton.propTypes = { | ||
| isLiked: PropTypes.bool.isRequired, | ||
| onClick: PropTypes.func.isRequired | ||
| }; | ||
|
|
||
| export default HeartButton; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Stale
onSongEndclosure — navigation will operate on mount-time state.onEndedis created once in the mount-only effect and permanently captures theonSongEndprop from that first render.onSongEndmaps tohandleNext(fromusePlaybackNav), which closes oversongsandcurrentSong. After those values change (song played, list searched, etc.),handleNextgets a new reference, but the stale closure registered on the'ended'event still calls the mount-time version — making end-of-track navigation unreliable.Use a ref to always dispatch to the latest callback without recreating the
Audioelement:🐛 Proposed fix
🤖 Prompt for AI Agents