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)
})
})
11 changes: 11 additions & 0 deletions app/components/AudioPlayer/audioSingleton.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { DEFAULT_VOLUME } from './constants';

let audioInstance = null;

export const getAudioInstance = () => {
if (!audioInstance) {
audioInstance = new Audio();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

The Audio constructor is a browser-only API. In a Next.js environment, this code will execute on the server during pre-rendering and throw a ReferenceError: Audio is not defined. You should add a check for the window object before instantiation.

Suggested change
audioInstance = new Audio();
audioInstance = typeof window !== 'undefined' ? new Audio() : null;

audioInstance.volume = DEFAULT_VOLUME;
}
return audioInstance;
Comment on lines +5 to +10

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🏁 Script executed:

# Find the audioSingleton.js file and examine its contents
find . -name "audioSingleton.js" -type f 2>/dev/null | head -5

Repository: wednesday-solutions/nextjs-template

Length of output: 125


🏁 Script executed:

# Search for all calls to getAudioInstance to see the usage patterns
rg -n "getAudioInstance" --type js --type jsx --type ts --type tsx -A 3 -B 3 2>/dev/null | head -100

Repository: wednesday-solutions/nextjs-template

Length of output: 61


🏁 Script executed:

# Check if this is a Next.js project
ls -la | grep -E "next.config|package.json" && head -30 package.json 2>/dev/null

Repository: wednesday-solutions/nextjs-template

Length of output: 1411


🏁 Script executed:

# Read the audioSingleton.js file
cat -n ./app/components/AudioPlayer/audioSingleton.js

Repository: wednesday-solutions/nextjs-template

Length of output: 400


🏁 Script executed:

# Search more broadly for getAudioInstance, audioInstance, or AudioPlayer imports
rg "getAudioInstance|audioInstance|audioSingleton" --type js --type jsx --type ts --type tsx 2>/dev/null

Repository: wednesday-solutions/nextjs-template

Length of output: 61


🏁 Script executed:

# Check what's in the AudioPlayer directory
ls -la ./app/components/AudioPlayer/

Repository: wednesday-solutions/nextjs-template

Length of output: 573


🏁 Script executed:

# Check useAudioSetup.js
cat -n ./app/components/AudioPlayer/useAudioSetup.js

Repository: wednesday-solutions/nextjs-template

Length of output: 1520


🏁 Script executed:

# Check useAudioPlayer.js
cat -n ./app/components/AudioPlayer/useAudioPlayer.js

Repository: wednesday-solutions/nextjs-template

Length of output: 1983


🏁 Script executed:

# Check the main index.js component
cat -n ./app/components/AudioPlayer/index.js

Repository: wednesday-solutions/nextjs-template

Length of output: 3369


🏁 Script executed:

# Search for dynamic imports or 'use client' directives
rg "dynamic|'use client'|\"use client\"|ssr: false" app/components/AudioPlayer --type js --type jsx

Repository: wednesday-solutions/nextjs-template

Length of output: 106


🏁 Script executed:

# Check if AudioPlayer is imported dynamically anywhere
rg "AudioPlayer|audioSingleton" --type js --type jsx -B 2 | head -50

Repository: wednesday-solutions/nextjs-template

Length of output: 106


🏁 Script executed:

# Search for dynamic imports and 'use client' with correct file types
rg "dynamic|use client|ssr:" app/components/AudioPlayer --type js -B 2

Repository: wednesday-solutions/nextjs-template

Length of output: 61


🏁 Script executed:

# Broader search for AudioPlayer imports in the codebase
rg "AudioPlayer|from.*audioSingleton" --type js -B 1 -A 1

Repository: wednesday-solutions/nextjs-template

Length of output: 8269


getAudioInstance() triggers ReferenceError: Audio is not defined during SSR — the proposed fix is incomplete.

Audio is a browser-only Web API. Next.js renders components server-side, and getAudioInstance() is called at render time (line 5 of useAudioSetup), outside any useEffect. This means AudioPlayer will execute on the server whenever rendered in TrackDetail, Library, or Music pages.

The proposed fix (if (typeof window === 'undefined') return null;) prevents the immediate error but introduces a secondary failure: useAudioSetup immediately accesses properties on the result without null checks (lines 7–10: audio.paused, audio.currentTime, audio.duration, audio.volume), causing Cannot read property 'paused' of null.

A complete fix requires one of these approaches:

  1. Move the call inside useEffect in useAudioSetup — this defers initialization to client-side only.
  2. Guard the function AND add null handling — return null from getAudioInstance() and guard all property accesses in useAudioSetup (and any other callers).
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@app/components/AudioPlayer/audioSingleton.js` around lines 5 - 10,
getAudioInstance currently calls the browser-only Audio constructor during
render causing SSR crashes; move the client-only initialization into a useEffect
inside useAudioSetup so getAudioInstance (and the Audio constructor) is only
invoked on the client, or if you prefer to keep a synchronous getter, make
getAudioInstance return null when window is undefined and update useAudioSetup
to guard all accesses to audio.paused/currentTime/duration/volume (and any other
callers) against null; reference getAudioInstance, useAudioSetup, audioInstance
and the Audio constructor when making the change.

};
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()
})
})
84 changes: 84 additions & 0 deletions app/components/AudioPlayer/tests/useAudioPlayer.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import { renderHook, act } from '@testing-library/react'

const mockPlay = jest.fn().mockResolvedValue(undefined)
const mockPause = jest.fn()
let mockAudioInstance

jest.mock('../audioSingleton', () => ({
getAudioInstance: () => mockAudioInstance
}))

const { useAudioPlayer } = require('../useAudioPlayer')

beforeEach(() => {
mockPlay.mockClear()
mockPause.mockClear()
mockAudioInstance = {
play: mockPlay,
pause: mockPause,
volume: 0.7,
currentTime: 0,
duration: 0,
src: '',
paused: true,
addEventListener: jest.fn(),
removeEventListener: jest.fn()
}
})

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 new song is selected', () => {
const { rerender } = renderHook(({ s }) => useAudioPlayer(s, jest.fn()), {
initialProps: { s: null }
})
rerender({ s: song })
expect(mockAudioInstance.src).toBe(song.previewUrl)
expect(mockPlay).toHaveBeenCalled()
})

it('should not auto-play on remount with same song', () => {
renderHook(() => useAudioPlayer(song, jest.fn()))
expect(mockPlay).not.toHaveBeenCalled()
})

it('should toggle play/pause', () => {
const { result, rerender } = renderHook(
({ s }) => useAudioPlayer(s, jest.fn()),
{
initialProps: { s: null }
}
)
rerender({ s: song })
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