WS 101 study hub

WS 101 · Module 6 · after midterm · ~60–90 min

Student Marketplace → Next.js

Same marketplace, better home. Navbar once, reusable card, home + detail routes. This is an upgrade — not a restart.

Your progress

0 / 10

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.

STEP 1

Create the Next.js app

  1. 1

    In the terminal, run npx create-next-app@latest marketplace.

  2. 2

    If it asks recommended Next.js defaults, choose Yes. That creates TypeScript files (page.tsx, layout.tsx). That is correct.

  3. 3

    Run cd marketplace then npm run dev.

  4. 4

    Open http://localhost:3000 and confirm the default Next.js page loads.

terminalcreate + run
npx create-next-app@latest marketplace
cd marketplace
npm run dev

You 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.

STEP 2

Put the navbar in the layout

  1. 1

    Open app/layout.tsx. Keep the imports Next.js already added.

  2. 2

    Put the Student Marketplace <nav> above {children} so it wraps every page.

  3. 3

    Save and confirm the blue bar appears on the home page.

app/layout.tsxadd nav only
<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.

STEP 3

Build ListingCard

  1. 1

    Create a components folder next to app/ (not inside it).

  2. 2

    Create components/ListingCard.tsx with props: title, price, description.

  3. 3

    Add a small CardProps type so the red squiggles go away. This is a label, not a new subject.

components/ListingCard.tsxprops + type
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.

STEP 4

Home page from an array

  1. 1

    Replace the welcome content in app/page.tsx with a listings array of three items.

  2. 2

    Import ListingCard and use listings.map(...) to render a card per item.

  3. 3

    Confirm three cards appear under an “Available Listings” heading.

app/page.tsxmap over data
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.

STEP 5

Detail page + Link

  1. 1

    Create app/listings/[id]/page.tsx.

  2. 2

    Copy the same listings array into that file. Wait for the URL first: const { id } = await params, then find the matching listing.

  3. 3

    On the home page, wrap each card in next/link pointing at /listings/ + the item id.

  4. 4

    Click a card — the detail page shows that listing, and the navbar is still there.

app/listings/[id]/page.tsxawait params
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>
  );
}
app/page.tsxwrap cards with Link
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.

DeliverableWhat to turn in
RepoYour GitHub repository URL
ProofScreenshot 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 .