Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions CLAUDE.md
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>
"""





30 changes: 30 additions & 0 deletions app/components/ArtworkPlayButton/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import React from 'react';
import PropTypes from 'prop-types';
import { PlayCircleFilled, PauseCircleFilled } from '@ant-design/icons';
import { ArtworkWrapper, Artwork, PlayOverlay } from '@components/styled/artworkPlayButton';

const ArtworkPlayButton = ({ src, alt, isPlaying, isActive, onClick }) => {
const handleClick = (e) => {
e.stopPropagation();
onClick();
};

return (
<ArtworkWrapper onClick={handleClick} data-testid="artwork-play-btn">
<Artwork src={src} alt={alt} />
<PlayOverlay isActive={isActive} data-overlay data-testid="play-overlay">
{isActive && isPlaying ? <PauseCircleFilled /> : <PlayCircleFilled />}
</PlayOverlay>
</ArtworkWrapper>
);
};

ArtworkPlayButton.propTypes = {
src: PropTypes.string.isRequired,
alt: PropTypes.string.isRequired,
isPlaying: PropTypes.bool.isRequired,
isActive: PropTypes.bool.isRequired,
onClick: PropTypes.func.isRequired
};

export default ArtworkPlayButton;
47 changes: 47 additions & 0 deletions app/components/ArtworkPlayButton/tests/index.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import React from 'react'
import { fireEvent } from '@testing-library/react'
import { renderProvider } from '@utils/testUtils'
import ArtworkPlayButton from '../index'

describe('<ArtworkPlayButton />', () => {
const defaultProps = {
src: 'art.jpg',
alt: 'Song Art',
isPlaying: false,
isActive: false,
onClick: jest.fn()
}

beforeEach(() => jest.clearAllMocks())

it('should render the artwork image', () => {
const { getByAltText } = renderProvider(
<ArtworkPlayButton {...defaultProps} />
)
expect(getByAltText('Song Art')).toBeTruthy()
})

it('should show PlayCircleFilled when not active', () => {
const { getByTestId } = renderProvider(
<ArtworkPlayButton {...defaultProps} />
)
expect(getByTestId('play-overlay')).toBeTruthy()
})

it('should show PauseCircleFilled when active and playing', () => {
const props = { ...defaultProps, isActive: true, isPlaying: true }
const { getByTestId } = renderProvider(<ArtworkPlayButton {...props} />)
expect(getByTestId('play-overlay')).toBeTruthy()
})

it('should call onClick and stop propagation', () => {
const { getByTestId } = renderProvider(
<ArtworkPlayButton {...defaultProps} />
)
const wrapper = getByTestId('artwork-play-btn')
const parentClick = jest.fn()
wrapper.parentElement.addEventListener('click', parentClick)
fireEvent.click(wrapper)
expect(defaultProps.onClick).toHaveBeenCalledTimes(1)
})
})
1 change: 1 addition & 0 deletions app/components/AudioPlayer/constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const DEFAULT_VOLUME = 0.7;
89 changes: 89 additions & 0 deletions app/components/AudioPlayer/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
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, onPlayStateChange, onRegisterToggle }) => {
const player = useAudioPlayer(currentSong, onNext, onPlayStateChange);

React.useEffect(() => {
if (onRegisterToggle) {
onRegisterToggle(player.togglePlay);
}
}, [player.togglePlay, onRegisterToggle]);

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: '#ff6b35', 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,
onPlayStateChange: PropTypes.func,
onRegisterToggle: PropTypes.func
};

export default AudioPlayer;
68 changes: 68 additions & 0 deletions app/components/AudioPlayer/tests/index.test.js
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()
})
})
69 changes: 69 additions & 0 deletions app/components/AudioPlayer/tests/useAudioPlayer.test.js
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)
})
})
Loading