← Build · all briefsBrief 8 · spare · after "Connect the market" · demo next class
Brief 8 · spare

Load more

Forty stalls are coming next month. The vendor list loads four at a time with ?limit=4&page=n, shows how many there are in total, and has a Load more button that appends the next page, until there isn't one. ★★☆

“Do I really have to scroll past all the food to get to the records?”

You'll demo (next class): the first four, "4 of 10". Load more twice: twelve requested, ten shown, the button gone. Click Food: back to page 1 of the food stalls.

The core (start in class if you've connected, the minimum for the demo)

Four things, on top of your connected market. They count when they work with chaos on (control page).

The full feature (finish at home)

What has to work for the demo next class, not how. The core above is part of it.

Requests

  • GET /api/stalls?limit=4&page=1, then page 2, 3…
  • The total from the X-Total-Count header; whether there's a next page from the Link header.
  • Changing the filter starts again from page 1 (the server filters: &tag=food).

States

  • "Showing 8 of 10".
  • Load more shows its own loading state; the cards already there stay.
  • No Load more button on the last page.

Errors

  • A failed page keeps the cards you have and offers Retry for that page only.
  • A double click on Load more never loads the same page twice.
  • Changing the filter while a page is loading never mixes the two lists.

New tool: Reading a header: response.headers.get("Link"). The format is described on MDN · Link.

The endpoints you need

MethodPathAnswers
GET/api/stalls?limit=&page=&tag=200 · X-Total-Count · Link: <…&page=3>; rel="next"

Edge cases (with chaos on, minutes 38–43)

Stretch, if you're done early

Stuck? One hint at a time

Network panel first: is the request sent, with what, and what came back? Then a hint.

Hint 1

Your getJSON returns only the body. Where do the headers go?

Hint 2

Two lists in flight, one for All and one for Food: which may append?

Traps

Open when something behaves strangely

Before you start

This brief assumes Connect the market is done: api.js works, the stalls come from the API, loading and errors are handled. Then: ?limit=4&page=1 in the Network panel, and the X-Total-Count header read in the console.

Demo · next class, 3 minutes

Your 3 minutes
  1. The happy path, with the Network panel open next to the page.
  2. Chaos on: the loading state, one failure, and how the page recovers.
  3. One request in code: the call, the status codes you handle, where the state changes.
  4. One bug you hit, and the panel or the message that showed it to you.