Before you start
Check these off so you’re ready to upgrade.
Not today
Do not add Prisma, a database, useState, or a working Post form. Fake listings in an array are correct for Module 6. Files will be .tsx — that is normal. Do not rename them to .js.
Create the Next.js app
- 1
In the terminal, run
npx create-next-app@latest marketplace. - 2
If it asks recommended Next.js defaults, choose Yes. That creates TypeScript files (
page.tsx,layout.tsx). That is correct. - 3
Run
cd marketplacethennpm run dev. - 4
Open
http://localhost:3000and confirm the default Next.js page loads.
npx create-next-app@latest marketplace
cd marketplace
npm run devYou should see app/page.tsx and app/layout.tsx. If you have src/app/, use those same file names inside src/. Do not create a page.js.
Put the navbar in the layout
- 1
Open
app/layout.tsx. Keep the imports Next.js already added. - 2
Put the Student Marketplace
<nav>above{children}so it wraps every page. - 3
Save and confirm the blue bar appears on the home page.
<body>
<nav style={{ backgroundColor: '#1d4ed8', padding: '16px 32px' }}>
<h1 style={{ color: 'white', fontSize: '22px' }}>Student Marketplace</h1>
</nav>
{children}
</body>This is Wall 2 — write the nav once. You will not copy it into the detail page.
Build ListingCard
- 1
Create a
componentsfolder next toapp/(not inside it). - 2
Create
components/ListingCard.tsxwith props:title,price,description. - 3
Add a small
CardPropstype so the red squiggles go away. This is a label, not a new subject.
type CardProps = {
title: string;
price: number;
description: string;
};
export default function ListingCard({ title, price, description }: CardProps) {
return (
<div style={{
backgroundColor: 'white',
borderRadius: '12px',
padding: '16px',
width: '280px',
boxShadow: '0 2px 8px rgba(0,0,0,0.08)',
}}>
<img
src="https://placehold.co/300x200"
alt={title}
style={{ width: '100%', height: '180px', objectFit: 'cover', borderRadius: '8px', marginBottom: '12px' }}
/>
<h3>{title}</h3>
<p style={{ fontWeight: 'bold', color: '#16a34a' }}>₱{price}</p>
<p style={{ color: '#666' }}>{description}</p>
</div>
);
}Change the card in this one file later and every listing on the home page should follow.
Home page from an array
- 1
Replace the welcome content in
app/page.tsxwith alistingsarray of three items. - 2
Import
ListingCardand uselistings.map(...)to render a card per item. - 3
Confirm three cards appear under an “Available Listings” heading.
import ListingCard from '../components/ListingCard';
const listings = [
{ id: 1, title: 'Second-Hand Laptop', price: 8500, description: 'Good condition. Core i5. Charger included.' },
{ id: 2, title: 'Calculus Textbook', price: 250, description: 'Lightly used. No missing pages.' },
{ id: 3, title: 'HDMI Cable', price: 150, description: '1.5 meters. Works perfectly.' },
];
export default function Home() {
return (
<main style={{ padding: '32px' }}>
<h2 style={{ marginBottom: '24px' }}>Available Listings</h2>
<div style={{ display: 'flex', gap: '24px', flexWrap: 'wrap' }}>
{listings.map((item) => (
<ListingCard
key={item.id}
title={item.title}
price={item.price}
description={item.description}
/>
))}
</div>
</main>
);
}Adding a fourth object to the array should add a fourth card. You should not paste a fourth card by hand.
Detail page + Link
- 1
Create
app/listings/[id]/page.tsx. - 2
Copy the same
listingsarray into that file. Wait for the URL first:const { id } = await params, thenfindthe matching listing. - 3
On the home page, wrap each card in
next/linkpointing at/listings/+ the item id. - 4
Click a card — the detail page shows that listing, and the navbar is still there.
const listings = [
{ id: 1, title: 'Second-Hand Laptop', price: 8500, description: 'Good condition. Core i5. Charger included.' },
{ id: 2, title: 'Calculus Textbook', price: 250, description: 'Lightly used. No missing pages.' },
{ id: 3, title: 'HDMI Cable', price: 150, description: '1.5 meters. Works perfectly.' },
];
export default async function ListingDetail({
params,
}: {
params: Promise<{ id: string }>;
}) {
const { id } = await params;
const listing = listings.find((item) => item.id === parseInt(id));
if (!listing) {
return <p style={{ padding: '32px' }}>Listing not found.</p>;
}
return (
<main style={{ padding: '32px', maxWidth: '600px' }}>
<img src="https://placehold.co/600x300" alt={listing.title} style={{ width: '100%', borderRadius: '12px', marginBottom: '24px' }} />
<h1>{listing.title}</h1>
<p style={{ fontWeight: 'bold', color: '#16a34a' }}>₱{listing.price}</p>
<p>{listing.description}</p>
</main>
);
}import Link from 'next/link';
{listings.map((item) => (
<Link key={item.id} href={'/listings/' + item.id}>
<ListingCard
title={item.title}
price={item.price}
description={item.description}
/>
</Link>
))}Current Next.js makes params a Promise. Use await params. Do not use params.id by itself.
Done checklist
Tick everything before you submit.
Submit
Turn in the repo URL and two screenshots. GitHub Pages is not required — Vercel is Module 8.
| Deliverable | What to turn in |
|---|---|
| Repo | Your GitHub repository URL |
| Proof | Screenshot of the home page and a listing detail page |
Stuck on the three walls? Open the WS 101 study hub and replay Module 5 first. When this activity is done, go to Pre-final Module 7 .