Vibe coding with Claude Code course · Module 7: LinkedIn clone

The job board: filters in the address and one offer model

7 min read
In this lesson6

Crew Connections has more and more notices. A pirate from Tortuga wants to see only the contracts in his port, and then send a link to a friend from the crew so that he sees the same list. Filters kept in component state vanish after a refresh and cannot be passed on to anyone. That is why the filter will be part of the address: /jobs?type=contract&location=Tortuga. In lesson 6_3 you did this with a single phrase in the network of connections, here two selection lists join in.

The second matter is order on deck. An offer already has its type JobPost from lesson 6_2, the JobCard card and the list of job types jobTypes. The board should use them, not build everything anew.

Request for Claude Code:

Add filters to the /jobs page: job type (type), port (location) and a
phrase (q) in the title, ship or description, all in the address, e.g.
/jobs?type=contract&location=Tortuga. Use the JobPost type, the
jobTypes list and the JobCard component, do not create a new offer
model. Filtering as pure functions in lib/job-filters.ts:
parseJobFilters (an unknown type from the address = no filter) and
filterJobs, case-insensitive; tests first. The form through next/form.
Add three offers to the seed data so there is something to filter. At
the end run tests, lint, types and build.

Before you accept the plan, check one thing: whether Claude is not planning a new Job interface next to JobPost. It is a common agent mistake: given the task "job board", it starts from zero. Two models of the same offer soon drift apart, for example one knows three job types and the other four, and nobody knows which is the true one.

What Claude wrote: filters from the address

Open lib/job-filters.ts in Cursor. The JobFilters type has an optional type (a value from JobType) and the texts location and q. SearchParams is the shape of address parameters in Next.js: every value is a text, an array of texts (when the parameter repeats) or missing. The first function translates the address into filters with the help of two small helpers from the same file:

export function parseJobFilters(params: SearchParams): JobFilters {
  return {
    type: isJobType(params.type) ? params.type : undefined,
    location: text(params.location),
    q: text(params.q),
  };
}

isJobType checks the value against the same jobTypes array the Zod schema from lesson 6_2 uses, so the list of job types still lives in one place. text returns a trimmed text, or an empty string when the parameter is missing or repeated. The address is user input: someone can type ?type=part-time-pirate and the page must neither fall over nor show an empty list. An unknown value simply means "no filter".

What Claude wrote: the result computed from the full list

The second function, in the same file, returns the offers that match all the set filters at once:

const lower = (value: string) => value.toLocaleLowerCase("en-US");

export function filterJobs(jobs: JobPost[], filters: JobFilters): JobPost[] {
  const phrase = lower(filters.q);
  return jobs.filter(
    (job) =>
      (!filters.type || job.type === filters.type) &&
      (!filters.location || lower(job.location) === lower(filters.location)) &&
      (!phrase || lower(`${job.title} ${job.company} ${job.description}`).includes(phrase)),
  );
}

Each line is one filter, and an empty filter lets everything through. filter creates a new array, so the full list does not change, and you compute the result from scratch every time. There is no separate state with the filtered offers and no useEffect to synchronise it: one truth from which everything follows. toLocaleLowerCase("en-US") lowercases the phrase and the text the same way, as in the contact search. The tests in lib/job-filters.test.ts check cases like this:

it("combines filters: contracts in Tortuga", () => {
  expect(ids(filterJobs(jobs, parseJobFilters({ type: "contract", location: "tortuga" })))).toEqual(["j3"]);
});

jobs is three test offers, and ids turns the result into a list of identifiers so the comparison is short. Next to it stand tests of an unknown job type, of the phrase "SWAN", which finds the ship "Swan", and of the full list, which still has three offers after filtering.

What Claude wrote: the page reads the address

Open app/jobs/page.tsx. It is a Server Component, so it filters on the server and the browser gets a ready list:

export default async function JobsPage({ searchParams }: PageProps<"/jobs">) {
  const filters = parseJobFilters(await searchParams);
  const allJobs = await getJobs();
  const jobs = filterJobs(allJobs, filters);
  const locations = [...new Set(allJobs.map((job) => job.location))].toSorted((a, b) => a.localeCompare(b, "en"));
  // below: <JobFilters filters={filters} locations={locations} />, the counter and the cards
}

searchParams in Next.js 16 is a promise, so the page waits for it with await, as in lessons 4_5 and 6_3. The list of ports is built from the offers, and Set removes repeats. Below, the page shows "Jobs found: 1 of 5" and draws each offer with the same JobCard as in lesson 6_2. Look at the result of npm run build: before this lesson /jobs had the mark ○, because the build rendered the list once, and now it has ƒ, because the page reads the address of every request.

What Claude wrote: a form that changes the address

The filters are drawn by components/jobs/JobFilters.tsx. Instead of a plain <form> it uses the Form component from next/form, which on submit turns the fields into address parameters (classes and labels omitted):

<Form action="/jobs">
  <input key={filters.q} id="q" name="q" defaultValue={filters.q} />
  <select key={filters.location} id="location" name="location" defaultValue={filters.location}>
    <option value="">All ports</option>
    {/* ports from the offers */}
  </select>
  {/* job type: the same pattern, options from jobTypes and labels from lib/job-labels.ts */}
  <button>Filter</button>
</Form>

After you click Filter, Form goes to the new address without a full page reload. In our run, after choosing Tortuga and a contract, the address looked like this: /jobs?q=&location=Tortuga&type=contract. An empty field also lands in the address, and parseJobFilters treats it as no filter. Next to the button stands a plain <Link href="/jobs"> with the text "Clear filters". The browser's Back button returns to the previous filter, because every filter is a separate address in the history.

Captain's review

  1. Fields that remember the old address. A typical agent mistake is fields without key. We checked: without key, after clicking "Clear filters" the list showed 5 of 5 offers, while the selection lists still said "Tortuga" and "contract", so the next "Filter" brought the old filter back. defaultValue works only when the field is created, and a navigation that changes only the address parameters leaves the old fields in place. A key with the value from the address creates the field anew. You put it on the fields, not on Form.
  2. Two offer models. In Cursor search the whole project for interface Job and type Job . The only offer model should be JobPost in types/job.ts.
  3. Junk in the address. Open /jobs?type=abc. In our run the page showed all five offers, with no error and no empty list.
  4. Letter case. Open /jobs?location=tortuga. In our run three offers from Tortuga came out, although in the data the port starts with a capital letter.

Next step

When the review passes, ask for a commit, for example "Job board with filters in the address". Start the dev server in the background as in lesson 6_4, so you can check addresses in the browser and the session stays free. Then a small step with a test:

Add a minimum salary filter (?min=8000): an offer without a salary
range does not match when the filter is set, and a value that is not
a number means no filter. First the tests of filterJobs, then the code.

In the editor below waits a job board with a pretend address bar. Set a filter, click Back and watch the address, then turn off the fields with key, clear the filters and see what stays in the selection lists.

Remember: one board, one offer model and one truth, and the address in the bar is a map you may pass on.

Code for this lesson: App.jsx
// Job board in miniature: filters live in the address, and the list is computed from the full list.
// The bar at the top pretends to be the browser: the form changes the address, and the "page" reads the filters from it,
// like app/jobs/page.tsx reads searchParams. Back returns to the previous address.
import { useState } from 'react';

const jobTypes = ['full-time', 'part-time', 'contract', 'temporary'];
const jobTypeLabels = { 'full-time': 'full-time', 'part-time': 'part-time', contract: 'contract', temporary: 'one voyage' };

const jobs = [
  { id: 'j5', title: 'Navigator for one voyage', company: "Queen Anne's Revenge", location: 'Tortuga', type: 'temporary', description: 'Through the reefs to Nassau and back.' },
  { id: 'j2', title: 'Expedition cartographer', company: "Queen Anne's Revenge", location: 'Nassau', type: 'contract', description: 'Coastal maps and a log of measurements.' },
  { id: 'j3', title: 'Ship carpenter', company: 'Swan', location: 'Tortuga', type: 'contract', description: 'Repairing the hull after the storm.' },
  { id: 'j1', title: 'First mate', company: 'Black Pearl', location: 'Tortuga', type: 'full-time', description: 'Night watch on Caribbean waters.' },
  { id: 'j4', title: 'Ship cook', company: 'Black Pearl', location: 'Port Royal', type: 'part-time', description: 'Three meals a day for the crew.' },
];
const locations = [...new Set(jobs.map((job) => job.location))].sort((a, b) => a.localeCompare(b, 'en'));

// The address is user input: an unknown job type means "no filter".
function parseJobFilters(params) {
  const type = params.get('type');
  return {
    type: jobTypes.includes(type) ? type : undefined,
    location: (params.get('location') ?? '').trim(),
    q: (params.get('q') ?? '').trim(),
  };
}

const lower = (value) => value.toLocaleLowerCase('en-US');

function filterJobs(list, filters) {
  const phrase = lower(filters.q);
  return list.filter(
    (job) =>
      (!filters.type || job.type === filters.type) &&
      (!filters.location || lower(job.location) === lower(filters.location)) &&
      (!phrase || lower(job.title + ' ' + job.company + ' ' + job.description).includes(phrase))
  );
}

function JobsPage({ search, navigate, keyed }) {
  const filters = parseJobFilters(new URLSearchParams(search));
  const found = filterJobs(jobs, filters);
  const key = (value) => (keyed ? value : undefined);

  // next/form does the same: the form fields become parameters of the address.
  const submit = (event) => {
    event.preventDefault();
    navigate('?' + new URLSearchParams(new FormData(event.currentTarget)).toString());
  };

  return (
    <div className="space-y-3">
      <form onSubmit={submit} className="grid gap-2 rounded-lg border border-gray-200 bg-white p-3 text-sm sm:grid-cols-3">
        <label className="font-semibold">
          Search
          <input key={key(filters.q)} name="q" defaultValue={filters.q} placeholder="e.g. cartographer" className="mt-1 w-full rounded-lg border border-gray-300 px-2 py-1 font-normal" />
        </label>
        <label className="font-semibold">
          Port
          <select key={key(filters.location)} name="location" defaultValue={filters.location} className="mt-1 w-full rounded-lg border border-gray-300 px-2 py-1 font-normal">
            <option value="">All ports</option>
            {locations.map((location) => <option key={location} value={location}>{location}</option>)}
          </select>
        </label>
        <label className="font-semibold">
          Job type
          <select key={key(filters.type ?? '')} name="type" defaultValue={filters.type ?? ''} className="mt-1 w-full rounded-lg border border-gray-300 px-2 py-1 font-normal">
            <option value="">Any</option>
            {jobTypes.map((type) => <option key={type} value={type}>{jobTypeLabels[type]}</option>)}
          </select>
        </label>
        <div className="flex items-center gap-3 sm:col-span-3">
          <button className="rounded-full bg-blue-600 px-4 py-1 font-semibold text-white">Filter</button>
          <button type="button" onClick={() => navigate('')} className="text-blue-700 underline">Clear filters</button>
        </div>
      </form>
      <p className="text-sm text-gray-600">Jobs found: {found.length} of {jobs.length}</p>
      {found.map((job) => (
        <article key={job.id} className="rounded-lg border border-gray-200 bg-white p-3">
          <h2 className="font-bold text-blue-700">{job.title}</h2>
          <p className="text-sm text-gray-600">{job.company} · {job.location} · {jobTypeLabels[job.type]}</p>
        </article>
      ))}
    </div>
  );
}

export default function App() {
  const [history, setHistory] = useState(['']);
  const [keyed, setKeyed] = useState(true);
  const search = history[history.length - 1];
  const navigate = (next) => setHistory((current) => [...current, next]);
  const back = () => setHistory((current) => (current.length > 1 ? current.slice(0, -1) : current));

  return (
    <div className="min-h-screen bg-gray-100 p-4 text-gray-900">
      <div className="mx-auto max-w-2xl space-y-3">
        <div className="flex items-center gap-2 rounded-lg border border-gray-200 bg-white p-2 text-sm">
          <button onClick={back} disabled={history.length < 2} className="rounded border border-gray-300 px-2 disabled:opacity-40">Back</button>
          <code className="flex-1 truncate rounded bg-gray-100 px-2 py-1">/jobs{search}</code>
        </div>
        <label className="flex items-center gap-2 text-sm">
          <input type="checkbox" checked={keyed} onChange={(e) => setKeyed(e.target.checked)} />
          Fields with key (turn off to see the typical mistake)
        </label>
        <JobsPage search={search} navigate={navigate} keyed={keyed} />
      </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. 1. What will the page /jobs?type=abc show?

  2. 2. How does the /jobs page choose the offers to show?

These are 2 of 10 questions for this lesson. Solve the rest in the game.

Hands-on tasks in the game

  • Horizontal ordering

    Arrange in one line the address of the job board: /jobs?type=contract&location=Tortuga&q=carpenter

  • Vertical ordering

    Order what happens after you click Filter:

  • Horizontal ordering

    Arrange in one line the path of the skill file from lesson 6_1: .claude/skills/new-form/SKILL.md

  • Vertical ordering

    Order the chat check that Claude runs with the server in the background:

  • Click in order

    Arrange the cleanup of the effect in useChat: return () => source.close()

  • Click in order

    Arrange reading the filters on the /jobs page: parseJobFilters(await searchParams)

  1. QuestionQuiz: An unknown job type in the address
  2. QuestionQuiz: Filtering offers (filterJobs)
  3. Put in orderSorting: An address with filters
  4. Put in orderSorting: From Filter to the list of offers
  5. QuestionQuiz: Skill or CLAUDE.md
  6. Put in orderSorting: The skill path
  7. QuestionQuiz: disable-model-invocation
  8. QuestionQuiz: What Ctrl+B does
  9. Put in orderSorting: Testing the chat with a background server
  10. QuestionQuiz: Background work (/tasks)
  11. Click in orderSorting: Cleaning up the stream in the browser
  12. QuestionQuiz: cancel in the server stream
  13. QuestionQuiz: The message sender
  14. Click in orderSorting: Filters from the address
  15. QuestionQuiz: Filters in the address
  16. QuestionQuiz: key on a filter field
  17. Project to submitSend Crew Connections to the mentor
  18. VideoModule summary

Useful articles