Vibe coding with Claude Code course ยท Module 13: Twitch clone
The Crew Book: Channel Page, Following and Support
In this lesson8
The player and the chat work but a viewer who lands on a channel does not yet know whose deck it is. A streamer needs a business card: a banner, an avatar, a description and a number of followers. A viewer wants two buttons: Follow, so as not to lose the channel, and Support, to chip in for the voyages. On top of that, the channel does not broadcast around the clock, so the page needs a sensible offline state. In this lesson Claude builds all of it, and you watch two things where the agent likes to guess: tabs and money.
What you will learn
- write two conventions in
CLAUDE.mdbefore Claude writes the first line of the channel page; - read one shared tabs component instead of a fifth copy of the same code;
- build a support window that charges nothing and says so plainly;
- check the offline state and the support window in the browser, including the Esc key.
Conventions first, code second
You have built tabs several times already: on the YouTube channel in lesson 5_3, in the Reddit guilds, in the chronicle. Every further copy is a place where a fix lands on one page while the old bug stays on another. The agent does not remember earlier projects and gladly writes tabs from scratch, straight in the page. Lesson 1_7 gave you a tool for such repetitions: CLAUDE.md, the file Claude reads at the start of every session. Open it in Cursor and add two lines to the conventions section:
- Tabs only through components/Tabs.tsx. The active tab lives in the address (?tab=), as in lesson 5_3. Do not copy tab code into pages.
- We do not implement payments. Keep support tiers and prices only in lib/support.ts.The first line turns a habit into a rule. The second closes the topic where guessing is the most expensive. Real payments are a contract with a provider, refunds, taxes and card data, not a single button. Until they exist, the support window only shows what you plan.
Request for Claude Code
Request for Claude Code:
Extend the page /channel/[handle]: above the player a channel header
(banner, avatar, name, number of followers), buttons Follow and
Support, under it tabs Home, Videos and About. Read CLAUDE.md and
follow the conventions. Follow only toggles a state in the browser for
now. Support opens a window with the tiers from lib/support.ts and an
inactive button "Soon", with no request to a server. When the channel
is offline, the Home tab shows a message and a link to the videos
instead of the player and the chat. Done when npm run lint,
npx tsc --noEmit and npm run build pass without errors.The request repeats the rule from CLAUDE.md in one sentence and adds what the file does not say: what each button does and what an offline channel looks like.
What Claude wrote: one tabs component
Open components/Tabs.tsx. It is a Server Component with no state, because the tabs are links, like on the channel from lesson 5_3:
// components/Tabs.tsx
export function pickTab<K extends string>(tabs: readonly Tab<K>[], value: unknown): K {
return tabs.find((tab) => tab.key === value)?.key ?? tabs[0].key;
}K is a type parameter: the component does not know the tab names in advance, it takes them from the page. pickTab turns whatever arrived in the address into a known tab. An address ?tab=anything gives the first tab instead of an empty page. The bar itself is a list of links with aria-current="page" on the active one and a border-transparent border on the others, known from lesson 5_3. The channel page supplies only the list:
// app/channel/[handle]/page.tsx
const CHANNEL_TABS = [
{ key: "home", label: "Home" },
{ key: "videos", label: "Videos" },
{ key: "about", label: "About" },
] as const;as const freezes the keys as exact strings, so active has the type "home" | "videos" | "about", and a typo in active === "vidoes" will not get past tsc. Without as const the keys would become a plain string and a comparison with any text would compile without a word. Further down, the page reads tab through await searchParams, computes const active = pickTab(CHANNEL_TABS, tab) and draws <Tabs tabs={CHANNEL_TABS} active={active} basePath={...} />.
What Claude wrote: support without a fake payment
Open lib/support.ts. Three support tiers are described by one type:
// lib/support.ts
// Support tiers in our clone. We set the names and prices ourselves: these are not Twitch prices.
export interface SupportTier {
level: 1 | 2 | 3;
name: string;
priceUsd: number;
perks: string[];
}The agent likes to describe every tier with a separate type, which is the same shape three times. One type with a level field says the same thing once. Under the type stands the SUPPORT_TIERS array with the names Deckhand, Bosun and Captain, and a formatPrice function that uses Intl.NumberFormat("en-US", { style: "currency", currency: "USD" }). The prices are invented for the clone and live in one file. If you change them tomorrow, you change them in one place. Now the window, components/SupportDialog.tsx:
// components/SupportDialog.tsx
<button type="button" disabled className="mt-2 rounded bg-zinc-700 px-3 py-1 text-sm text-zinc-400">
Soon
</button>The button by every tier is disabled, and under the list stands the sentence "Payments do not work yet. Nothing will be charged." The window is opened by dialogRef.current?.showModal(). MDN describes that showModal() shows the window above the rest of the page, with a ::backdrop behind it, and the rest of the page stops reacting. The Esc key closes the window because, according to MDN, it is a close request that fires the cancel event. The window has the class m-auto because Tailwind 4 zeroes margins. In our run, without it the window stood in the top left corner of the page.
What Claude wrote: the offline channel
An offline channel has live: null in the data, the type from lesson 12_1. Claude moved the player and the chat into a LivePanel component, so the page picks the view with one condition:
// app/channel/[handle]/page.tsx
{active === "home" &&
(channel.live ? <LivePanel channel={channel} /> : <OfflinePanel channel={channel} />)}OfflinePanel has the same proportions as the player (aspect-video), so the layout does not jump when a channel starts or stops broadcasting. It shows the channel name, a sentence about the break and a link to the Videos tab. The type LiveStream | null does good work here: an offline channel cannot have a viewer count or a broadcast title, because there is nothing to read.
The Follow button is components/FollowButton.tsx with a single useState and the aria-pressed attribute, which according to MDN describes the state of a toggle button: pressed or not. The state lives only in this browser tab. Saving on the server for a logged-in viewer is a job for later, with the login from lesson 8_5.
Captain's review
- One set of tabs. Search the project for
aria-current. The result should point atcomponents/Tabs.tsx, not at the channel page. A typical agent mistake is a fifth copy of the tabs written straight into the page despite the convention. When you find it, answer: "Read CLAUDE.md and use Tabs". - No payment requests. Search for
fetch(incomponents/. The agent can addfetch("/api/pay")to a route that does not exist and a message "Thank you for your support!". That is a lie to the viewer. - Prices in one place. Search for
$andpriceUsd. The numbers should stand only inlib/support.ts. - Numbers in your locale.
Intl.NumberFormat("en-US")wrote 12480 as "12,480" for us, and 3120 as "3,120", and a price of 10 as "$10.00". English groups four-digit numbers too. That is not a bug, it is the rule of the format. - The browser.
npm run dev, then/channel/captain-redbeard: open the support window, check that it stands in the middle, and close it with the Esc key. Then/channel/parrot-pollyand the offline state. In our run the window closed after Esc, and the network request list showed nofetchcall.
Next step
When the review passes, ask for a commit "Channel page with tabs and a support window". Then a small step: "Add a Schedule tab with the channel's broadcast days, through Tabs". If Claude reaches for Tabs by itself, the convention works. If not, add an even shorter version of the rule to CLAUDE.md. In the editor below waits a miniature channel page, with an online and offline switch and the support window.
Remember: the crew book says who stands on the deck, and the treasury stays locked until a real treasurer arrives; a guessing ghost does not get the key.
Code for this lesson: App.tsx
// Channel page in miniature: one tabs component, an offline state and a support window without payments
import { useRef, useState } from 'react';
// Support tiers in our clone. We set the names and prices ourselves: these are not Twitch prices.
interface SupportTier {
level: 1 | 2 | 3;
name: string;
priceUsd: number;
perks: string[];
}
const SUPPORT_TIERS: SupportTier[] = [
{ level: 1, name: 'Deckhand', priceUsd: 10, perks: ['Badge next to your name in chat'] },
{ level: 2, name: 'Bosun', priceUsd: 25, perks: ['Badge next to your name in chat', 'Extra emotes'] },
{ level: 3, name: 'Captain', priceUsd: 60, perks: ['Badge next to your name in chat', 'Extra emotes', 'Name in the end credits'] },
];
const priceFormat = new Intl.NumberFormat('en-US', { style: 'currency', currency: 'USD' });
const countFormat = new Intl.NumberFormat('en-US');
interface Tab<K extends string> {
key: K;
label: string;
}
// The editor has no address bar, so the tab lives in the parent's state (lesson 5_3)
function Tabs<K extends string>({ tabs, active, onSelect }: { tabs: readonly Tab<K>[]; active: K; onSelect: (key: K) => void }) {
return (
<nav aria-label="Tabs" className="flex gap-1 border-b border-zinc-800">
{tabs.map((tab) => (
<button
key={tab.key}
type="button"
onClick={() => onSelect(tab.key)}
aria-current={tab.key === active ? 'page' : undefined}
className={tab.key === active ? 'border-b-2 border-purple-500 px-4 py-2 font-semibold' : 'border-b-2 border-transparent px-4 py-2 text-zinc-400'}
>
{tab.label}
</button>
))}
</nav>
);
}
const CHANNEL_TABS = [
{ key: 'home', label: 'Home' },
{ key: 'videos', label: 'Videos' },
{ key: 'about', label: 'About' },
] as const;
type ChannelTab = (typeof CHANNEL_TABS)[number]['key'];
function SupportDialog({ channelName }: { channelName: string }) {
const dialogRef = useRef<HTMLDialogElement>(null);
return (
<>
<button type="button" onClick={() => dialogRef.current?.showModal()} className="rounded bg-zinc-100 px-4 py-2 font-semibold text-zinc-900">
Support
</button>
<dialog ref={dialogRef} aria-labelledby="support-title" className="m-auto w-full max-w-md rounded-lg bg-zinc-900 p-5 text-zinc-100 backdrop:bg-black/70">
<h2 id="support-title" className="text-lg font-bold">Support the channel {channelName}</h2>
<ul className="mt-4 space-y-3">
{SUPPORT_TIERS.map((tier) => (
<li key={tier.level} className="rounded border border-zinc-700 p-3">
<p className="font-semibold">{tier.name} ยท {priceFormat.format(tier.priceUsd)} per month</p>
<p className="text-sm text-zinc-400">{tier.perks.join(', ')}</p>
<button type="button" disabled className="mt-2 rounded bg-zinc-700 px-3 py-1 text-sm text-zinc-400">
Soon
</button>
</li>
))}
</ul>
<p className="mt-4 text-sm text-zinc-400">Payments do not work yet. Nothing will be charged.</p>
<button type="button" onClick={() => dialogRef.current?.close()} className="mt-4 rounded bg-zinc-700 px-4 py-2">
Close
</button>
</dialog>
</>
);
}
export default function App() {
const [active, setActive] = useState<ChannelTab>('home');
const [live, setLive] = useState(true);
const [following, setFollowing] = useState(false);
return (
<div className="min-h-screen space-y-4 bg-zinc-950 p-4 text-zinc-100">
<div className="aspect-[6/1] rounded-lg bg-linear-to-r from-sky-700 to-amber-500" />
<div className="flex flex-wrap items-center gap-3">
<div className="size-16 rounded-full bg-amber-600" />
<div className="mr-auto">
<h1 className="text-xl font-bold">Captain Redbeard</h1>
<p className="text-sm text-zinc-400">{countFormat.format(12480)} followers</p>
</div>
<button
type="button"
aria-pressed={following}
onClick={() => setFollowing((f) => !f)}
className={following ? 'rounded bg-zinc-700 px-4 py-2 font-semibold' : 'rounded bg-purple-600 px-4 py-2 font-semibold'}
>
{following ? 'Following' : 'Follow'}
</button>
<SupportDialog channelName="Captain Redbeard" />
</div>
<Tabs tabs={CHANNEL_TABS} active={active} onSelect={setActive} />
{active === 'home' &&
(live ? (
<section className="grid aspect-video place-content-center rounded-lg bg-black text-center">
<span className="mx-auto rounded bg-red-600 px-2 py-1 text-xs font-bold">LIVE</span>
<p className="mt-2">Voyage across the Sea of Code: building the chat</p>
</section>
) : (
<section className="grid aspect-video place-content-center gap-3 rounded-lg bg-zinc-900 p-6 text-center">
<p className="text-lg font-semibold">Captain Redbeard is offline now</p>
<p className="text-zinc-400">The crew is resting after the voyage. Watch the recordings of earlier broadcasts.</p>
<button type="button" onClick={() => setActive('videos')} className="text-purple-400 underline">
Go to the videos
</button>
</section>
))}
{active === 'videos' && <p className="text-zinc-400">Voyage 1: player and chat</p>}
{active === 'about' && <p>Daily voyages through code: we build app clones with Claude Code.</p>}
<label className="flex items-center gap-2 text-sm">
<input type="checkbox" checked={live} onChange={(e) => setLive(e.target.checked)} />
The channel is broadcasting (uncheck to see the offline state)
</label>
</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. Where in Live from the Deck do the names and prices of the support tiers live?
2. What does the button by a support tier in the Support window do while payments do not exist?
These are 2 of 6 questions for this lesson. Solve the rest in the game.
Hands-on tasks in the game
- Click in order
Build the call that opens the support window as a modal dialog
- Vertical ordering
Arrange the parts of the channel page from the top of the page:
- Vertical ordering
Arrange the work on the channel page from the lesson:
- Code editor
Build a streamer channel page
- Click in order
Build the channel page line that turns the tab parameter from the address into a known tab
- Code editor
Create a live stream card
Tasks after this lesson
- QuestionQuiz: where the prices live
- QuestionQuiz: the Soon button
- Click in orderBuild: opening the support window
- Put in orderOrder: the channel page from the top
- Put in orderOrder: convention before code
- Coding taskPractice: Channel page
- QuestionQuiz: as const on the tabs
- QuestionQuiz: an unknown tab in the address
- Click in orderBuild: the tab from the address
- Coding taskPractice: Stream card
- QuestionQuiz: the offline state of a channel
- QuestionQuiz: the window in the corner