Skip to content
Apps— browse docs
On this page

Step 5: A live directory

Every document the world holds, grouped by type — the same rows the pinboard reads, sorted differently.

The pinboard shows what someone chose. A directory shows what's there — every document, grouped by type, biggest group first. No new capability: it's the same docs array from useWorldQuery, just grouped with a plain Map:

const byType = useMemo(() => {
  const groups = new Map<string, typeof docs>()
  for (const d of docs) groups.set(d.documentType, [...(groups.get(d.documentType) ?? []), d])
  return [...groups.entries()].sort((a, b) => b[1].length - a[1].length)
}, [docs])

Render one section per group. Then replace the flat list with those sections, and show pinned documents as chips above them — the directory now lists everything, so the pinboard only needs the pins:

A live directory
src/app.tsx Lines 29 to 33, 59 to 70 and 72 to 92 highlighted.

Edit and the example re-runs. Tab indents; press Escape to leave the editor.

Running · your edits, live
Starting the example…

You should see: the flat list turns into one section headed "card · 2" — this playground's fixture world only has two documents, both cards, so that's the only group there is to show. Pin "Aria of the North" first, and it now also shows as a chip above the sections; the row underneath stays exactly where it was.

Note:

Your own world won't be this uniform — maps, tables, notes, whatever else it holds each get their own section, biggest first. Run this for real (Step 6) and you'll see it.

Next steps