Vibe coding with Claude Code course · Module 11: Spotify clone
Playlists: Data First, Then the Screen
In this lesson9
The player works but the crew wants more than one queue. The bosun collects shanties for hauling ropes, the cook collects ballads for the evening, and the captain wants to see next to every track when it landed on the list. These are playlists. A playlist screen is easy to order in one request, and an agent that gets the screen before the data happily invents the data. A typical result is an "Added" column in which every track has the same date, today's.
What you will learn
- order a feature in three steps: data, screen, form;
- check that every column reads a real field from the data;
- catch dead classes and unused state that lint lets through;
- go back with
/rewindwhen a step went the wrong way.
Step 1: data
The screen shows data, so data comes first. A single request "build playlists" would produce several hundred lines in several files at once, and a field missing from the type would be patched in the view with whatever looks believable. Three small steps give three diffs, each of which you read in a few minutes, and three commits you can return to. This step touches no component and ends with a finish line, like in lesson 10_1.
Request for Claude Code (step 1):
Step 1 of 3. In types/music.ts the types Playlist, PlaylistTrack and
Library. A track on a playlist remembers the date it was added
(addedAt, an ISO string in UTC), Library holds identifiers, not copies
of objects. Add a sample playlist to lib/catalog.ts, next to the
tracks. In lib/playlist.ts the functions totalDuration and
formatAddedAt with tests. No components.
Done when: totalDuration of the sample playlist is the sum of its
track lengths, formatAddedAt("2026-11-14T23:40:00Z") returns
"15 Nov 2026", and the tests and npm run lint pass.What Claude wrote: a track with an added date
Open types/music.ts in Cursor. The added date does not belong to the track but to its place on the playlist, because the same shanty can land on two lists on different days:
export interface PlaylistTrack {
track: Track;
addedAt: string; // "2026-11-02T18:30:00Z", the added date in UTC
}addedAt is a string in ISO format, a date with a time written the way every server sends it. The letter Z at the end means UTC time, without the user's time zone. The playlist itself looks like this:
export interface Playlist {
id: string;
name: string;
description: string;
isPublic: boolean;
isCollaborative: boolean;
owner: { id: string; username: string };
tracks: PlaylistTrack[];
}isPublic says whether the whole crew sees the list, and isCollaborative whether other pirates can add tracks to it, not only the owner. A user's library has the fields likedTrackIds and followedArtistIds, the identifiers of liked tracks and followed artists. An identifier never goes stale, while a copy of the artist object would keep the old name after the artist changes it.
What Claude wrote: the total and the date
lib/playlist.ts holds two small functions. The first adds up the track lengths:
export function totalDuration(playlist: Playlist): number {
return playlist.tracks.reduce((sum, item) => sum + item.track.duration, 0);
}reduce walks the list and adds each length to a sum that starts at zero. The result goes through formatTime from lesson 10_1, not through a new formatter. The second function turns a date into text:
const addedAtFormat = new Intl.DateTimeFormat("en-GB", {
day: "numeric",
month: "short",
year: "numeric",
timeZone: "Europe/Warsaw",
});timeZone is a time zone fixed in advance. Without it the server and the browser can show a different day if they sit in different zones. Our test showed it clearly: a track added on 14 November at 23:40 UTC is already "15 Nov 2026" in Warsaw.
Step 2: the playlist screen
A commit after step 1, and only then the screen.
Request for Claude Code (step 2):
Step 2 of 3. components/PlaylistPage.tsx and the page /playlists/[id]:
a header with a gradient, name, description, owner, number of tracks
and total time, a Play button, a table with the columns #, Title,
Album, Added, Duration. Every column reads a field from the data of
step 1. A double click on a row plays that track in the MusicPlayer
from lesson 10_1. Tailwind 4. At the end lint, types, tests and build.What Claude wrote: the header and a row
Open components/PlaylistPage.tsx. The header has a background that fades from amber to grey:
<header className="rounded-t-xl bg-linear-to-b from-amber-700 to-gray-900 p-6">bg-linear-to-b is the name from the Tailwind 4 documentation: a linear gradient from top to bottom. In older tutorials and in the code of many agents you will see bg-gradient-to-b. According to our research the old name still works in Tailwind 4 but is gone from the documentation, so you stick to the new one. A table row looks like this:
<div
key={item.track.id}
role="row"
onDoubleClick={() => onPlay(i)}
className="grid grid-cols-[2rem_1fr_1fr_8rem_4rem] gap-2 rounded py-2 hover:bg-white/10"
>grid-cols-[...] makes five columns of the given widths, the same in the table header and in every row. hover:bg-white/10 lightens the row under the cursor with white at 10% opacity. Every cell is a <span role="cell">, and role="row" and role="cell" tell screen readers that this grid of div elements is a table. The "Added" cell is <span role="cell">{formatAddedAt(item.addedAt)}</span>, and "Duration" shows {formatTime(item.track.duration)}. A double click calls onPlay with the row number. The playlist page then shows the player from lesson 10_1 with key={start} and the tracks of this playlist, and a new key gives a fresh player starting at the chosen track. A double click is a shortcut for the mouse. From the keyboard, the playlist is started by the Play button in the header, which is disabled when the list has no tracks. Picking a particular row with the keyboard is a separate small request for later, not something an agent should add without being asked.
Step 3: the new playlist form
Request for Claude Code (step 3):
Step 3 of 3. components/CreatePlaylistModal.tsx opened by the
"New playlist" button on the page /playlists: a name (required),
a description, a "Public" field. The Create button is disabled
while the name is empty or only spaces. onCreate gets trimmed values.Open components/CreatePlaylistModal.tsx. The button condition is computed while rendering, with no separate state:
const canCreate = name.trim() !== "";
function handleSubmit(event: React.SubmitEvent<HTMLFormElement>) {
event.preventDefault();
if (!canCreate) return;
onCreate({ name: name.trim(), description: description.trim(), isPublic });
}trim() cuts spaces from the start and the end, so three spaces are an empty name. The button has disabled={!canCreate}, and a disabled submit button blocks Enter in the field as well. For us three spaces and Enter did nothing, and a name typed as " Night Ballads" landed on the list as "Night Ballads". React.SubmitEvent is the type of the form submit event that the current React types recommend.
Captain's review
- Dummy data. A typical agent mistake is the cell
{new Date().toLocaleDateString()}in the "Added" column. For us all three rows showed "15/11/2026", and the console in development mode reportedHydration failed because the server rendered text didn't match the client: the server drew "11/15/2026" and the browser "15/11/2026". Searchcomponents/(Cmd+Shift+F) fornew Date(: every hit in a view is a suspicion that the agent made up data. - Conflicting classes. An agent can write
hover:bg-white hover:bg-white/10, two background colours for the same situation. For us/10won regardless of the order inclassName, because the order of rules is set by Tailwind in the generated CSS. The second class is dead weight that confuses the next reader: keep only the one you want. - Unused state. A line
const [sortBy, setSortBy] = useState("addedAt")that nothing reads. For usnpm run lintprinted only the warning'sortBy' is assigned a value but never usedand finished with success. Read the warnings, not only the errors, and ask Claude whether it is a forgotten feature or junk. - Every column from data. Compare the table headers with the row cells: five headers, five cells, each with a field from
PlaylistTrack.
Next step
The crew wants to sort the list by title and by added date. That is a separate, narrow request: "In @components/PlaylistPage.tsx add sorting by title and by added date. Sort a copy of the list. Change nothing else." If the diff shows changes in files you did not ask about, or the sorting breaks the playback order, do not patch it with a third request. Type /rewind from lesson 0_6, pick the request with the sorting and restore the code. Remember the limit: /rewind undoes changes made by Claude's file editing tools, not the effects of terminal commands. Then give a smaller request. Each of the three steps ends with a commit of its own.
In the editor below a playlist is waiting, with a table and a form. Turn on the agent bug with the date and watch every row get the same day, and then try to create a playlist from spaces only.
Remember: the shanty chest must be tidy, not just pretty, and every column on the screen needs its own field in the hold of the data.
Code for this lesson: App.jsx
// Playlist in miniature: every column reads a field from the data
import { useState } from 'react';
const playlist = {
name: 'Watch Shanties',
description: 'For singing at the ropes',
isPublic: true,
owner: { username: 'redbeard' },
tracks: [
{ track: { id: 't1', title: 'Pirate Hymn', artist: 'Captain Redbeard', album: 'Songs from the Deck', duration: 125 }, addedAt: '2026-10-30T21:15:00Z' },
{ track: { id: 't3', title: 'Island Shanty', artist: 'Captain Redbeard', album: 'Songs from the Deck', duration: 150 }, addedAt: '2026-11-02T08:05:00Z' },
{ track: { id: 't4', title: "Kraken's Song", artist: 'Black Mary', album: 'Storm over Tortuga', duration: 70 }, addedAt: '2026-11-14T23:40:00Z' },
],
};
function formatTime(seconds) {
if (!Number.isFinite(seconds) || seconds < 0) return '0:00';
const whole = Math.floor(seconds);
return `${Math.floor(whole / 60)}:${String(whole % 60).padStart(2, '0')}`;
}
const addedAtFormat = new Intl.DateTimeFormat('en-GB', { day: 'numeric', month: 'short', year: 'numeric', timeZone: 'Europe/Warsaw' });
const formatAddedAt = (iso) => addedAtFormat.format(new Date(iso));
const totalDuration = (p) => p.tracks.reduce((sum, item) => sum + item.track.duration, 0);
const COLUMNS = 'grid grid-cols-[2rem_1fr_1fr_7rem_3rem] gap-2';
function CreatePlaylistModal({ onCreate, onClose, agentBug }) {
const [name, setName] = useState('');
const [description, setDescription] = useState('');
const [isPublic, setIsPublic] = useState(true);
const canCreate = agentBug ? true : name.trim() !== '';
function handleSubmit(event) {
event.preventDefault();
if (!canCreate) return;
onCreate({ name: agentBug ? name : name.trim(), description: description.trim(), isPublic });
}
return (
<div className="fixed inset-0 flex items-center justify-center bg-black/70">
<form role="dialog" aria-modal="true" onSubmit={handleSubmit} className="w-80 space-y-3 rounded-xl bg-gray-800 p-5">
<h2 className="text-xl font-bold">New playlist</h2>
<label className="block">Name
<input value={name} onChange={(e) => setName(e.target.value)} autoFocus className="mt-1 w-full rounded bg-gray-700 p-2" />
</label>
<label className="block">Description
<textarea value={description} onChange={(e) => setDescription(e.target.value)} className="mt-1 w-full rounded bg-gray-700 p-2" />
</label>
<label className="flex items-center gap-2">
<input type="checkbox" checked={isPublic} onChange={(e) => setIsPublic(e.target.checked)} /> Public
</label>
<div className="flex justify-end gap-2">
<button type="button" onClick={onClose} className="px-3 py-2">Cancel</button>
<button type="submit" disabled={!canCreate} className="rounded-full bg-green-500 px-4 py-2 font-semibold text-black disabled:opacity-40">Create</button>
</div>
</form>
</div>
);
}
export default function App() {
const [nowPlaying, setNowPlaying] = useState(null);
const [dateBug, setDateBug] = useState(false);
const [hoverBug, setHoverBug] = useState(false);
const [buttonBug, setButtonBug] = useState(false);
const [open, setOpen] = useState(false);
const [created, setCreated] = useState([]);
const rowHover = hoverBug ? 'hover:bg-white hover:bg-white/10' : 'hover:bg-white/10';
return (
<div className="min-h-screen bg-gray-950 p-4 text-white">
<div className="mx-auto max-w-2xl">
<header className="rounded-t-xl bg-linear-to-b from-amber-700 to-gray-900 p-5">
<p className="text-xs uppercase">{playlist.isPublic ? 'Public playlist' : 'Private playlist'}</p>
<h1 className="text-3xl font-bold">{playlist.name}</h1>
<p className="text-gray-200">{playlist.description}</p>
<p className="mt-1 text-sm">{playlist.owner.username} · {playlist.tracks.length} tracks · {formatTime(totalDuration(playlist))}</p>
<button type="button" onClick={() => setNowPlaying(playlist.tracks[0].track.title)} className="mt-3 rounded-full bg-green-500 px-5 py-2 font-semibold text-black">Play</button>
</header>
<div className="bg-gray-900 p-3 text-sm">
<div className={`${COLUMNS} border-b border-gray-700 pb-2 text-gray-400`}>
<span>#</span><span>Title</span><span>Album</span><span>Added</span><span>Duration</span>
</div>
{playlist.tracks.map((item, i) => (
<div key={item.track.id} onDoubleClick={() => setNowPlaying(item.track.title)} className={`${COLUMNS} rounded py-2 ${rowHover}`}>
<span>{i + 1}</span>
<span>{item.track.title}<br /><span className="text-gray-400">{item.track.artist}</span></span>
<span>{item.track.album}</span>
<span>{dateBug ? new Date().toLocaleDateString() : formatAddedAt(item.addedAt)}</span>
<span>{formatTime(item.track.duration)}</span>
</div>
))}
</div>
<p className="mt-2 text-sm text-gray-300">{nowPlaying ? `Now playing: ${nowPlaying}` : 'Double-click a row to play it.'}</p>
<div className="mt-4 space-y-1 text-sm">
<label className="flex items-center gap-2"><input type="checkbox" checked={dateBug} onChange={(e) => setDateBug(e.target.checked)} /> Agent bug: Added from new Date()</label>
<label className="flex items-center gap-2"><input type="checkbox" checked={hoverBug} onChange={(e) => setHoverBug(e.target.checked)} /> Agent bug: two hover classes</label>
<label className="flex items-center gap-2"><input type="checkbox" checked={buttonBug} onChange={(e) => setButtonBug(e.target.checked)} /> Agent bug: Create always enabled</label>
<p className="font-mono text-xs text-gray-400">Row classes: {rowHover}</p>
</div>
<div className="mt-4">
<button type="button" onClick={() => setOpen(true)} className="rounded-full bg-white px-4 py-2 font-semibold text-black">New playlist</button>
<ul className="mt-2 text-sm">
{created.map((p, i) => (
<li key={i}>"{p.name}" {p.isPublic ? '(public)' : '(private)'}{p.name.trim() === '' && <strong className="text-red-400"> playlist without a name!</strong>}</li>
))}
</ul>
</div>
{open && (
<CreatePlaylistModal
agentBug={buttonBug}
onClose={() => setOpen(false)}
onCreate={(p) => { setCreated((list) => [...list, p]); setOpen(false); }}
/>
)}
</div>
</div>
);
}Spotted a mistake in this lesson?
Check yourself
Answer the questions from this lesson. Pick an answer to see right away whether it is correct.
1. Why is addedAt in the PlaylistTrack type and not in the Track type?
2. npm run lint finishes with success but prints a warning: 'sortBy' is assigned a value but never used. What do you do?
These are 2 of 7 questions for this lesson. Solve the rest in the game.
Hands-on tasks in the game
- Click in order
Click the pieces to build the condition the Create button depends on:
- Click in order
Click the pieces to build the header of the function that handles the form submit:
- Horizontal ordering
Arrange in one line the cell of the Added column:
- Horizontal ordering
Arrange in one line the beginning of the added date formatter:
- Code editor
Playlist display component
- Click in order
Click the pieces to add up the track durations:
- Vertical ordering
Arrange the steps of building the playlists from the lesson:
- Vertical ordering
Arrange the steps when the request for sorting the playlist changed too much:
- Horizontal ordering
Arrange the tokens to read the playlist owner's name on one line:
- Vertical ordering
Arrange what happens after a click on Create with a valid name:
- Code editor
Playlist creation interface
Tasks after this lesson
- QuestionAdded date on a playlist
- QuestionWarning about unused state
- Click in orderThe Create button condition
- Click in orderThe form submit event type
- Put in orderThe Added cell from data
- Put in orderThe added date formatter
- Coding taskPractice: Playlist page
- QuestionLibrary: identifiers instead of copies
- Click in orderBuild the playlist duration sum
- Put in orderPlaylists in three steps
- QuestionTwo hover classes on one row
- Put in orderWhen the sorting goes wrong
- QuestionTime zone of the added date
- QuestionDummy date in the Added column
- Put in orderAccess the owner's name
- Put in orderCreating a playlist step by step
- Coding taskPractice: Create playlist modal
- QuestionA name of only spaces