# resources/ — Livewire 4 pages and SCSS

## Views

- `views/pages/⚡homepage.blade.php` and `⚡charitydetail.blade.php` are
  Livewire v4 single-file components: an anonymous
  `new class extends Component` PHP block followed by Blade. The ⚡ prefix is
  the official v4 page-component convention — keep it. Routes reference them
  as `pages::homepage` etc. via `Route::livewire()` in routes/web.php; the
  `pages` namespace maps to this directory in config/livewire.php.
- `views/layouts/app.blade.php` is the only public layout. It injects theme
  colors as CSS custom properties from `app(App\Services\SiteColors::class)
  ->toCssCustomProperties()` (admin-editable, cached) — so "where does this
  color come from?" is often the database, not a stylesheet. Nav/dropdown
  interactivity is hand-written vanilla JS; no Alpine is authored here.
- Score breakdowns exist in **two parallel blade trees** rendering the same
  `CharityScoreCalculator` output: `views/partials/scores/` (public) and
  `views/filament/charities/scores/` (admin). A change to how a score is
  displayed usually means touching both.
- `views/components/editable.blade.php` (`<x-editable>`) wraps copy that the
  admin customizer may change. Its slot stays the default; only zones wrapped
  in it are selectable in `/admin/customizer`. Adding an editable heading is
  therefore a one-line Blade change, not an admin one. Placeholders, images and
  DB-backed labels use the `App\Support\Editable` helpers instead of the
  component. Keep icons *outside* the zone — a button wraps only its words, so
  the client can reword "Add metric" but not lose the +.
- `views/components/charity-list-detail.blade.php` is the expandable panel.
  Its three headings and every label in the second and third sections are
  `<x-editable>` zones; the 4R build-up in the first is left alone because
  those labels are the methodology. The row expander carries
  `data-cz-interactive` so the customizer lets the click through while
  selecting — otherwise the panel could never be opened to edit it.
- `views/components/columns/` holds one partial per renderer;
  `charity-list-row.blade.php` `@include`s the one the column names. Adding a
  *column* needs no code; adding a *renderer* means a partial here plus an
  entry in `ColumnTooltip::RENDERERS`, the whitelist that stops an unknown
  value reaching the view name. These were briefly inlined into one `@switch`
  because ~450 `@include`s a request cost ~12 ms — worth it before
  `Services\CharityListCache` existed, pointless after it: on a cache hit no
  Blade runs at all, and the inlined version's indentation was emitted verbatim
  into every response (196 KB -> 250 KB). Do not re-inline them.
- `views/components/documents-section.blade.php` lists everything in
  `charity_documents` for a charity on its public page, grouped by kind. The
  homepage's `columns/link.blade.php` is the same data in one cell: the newest
  document of one kind, drawn as an icon-and-year button. Its anchor carries
  `onclick="event.stopPropagation()"` — the whole row has a click handler that
  navigates to the charity page, and opening the report has to win over it.
  Neither view builds the address itself: `CharityDocument::publicUrl()` picks
  between the charity's server and a copy held here, and a row it returns null
  for is not drawn. Where a copy is served, the list shows the original
  address underneath it as a sibling anchor — a mirrored file is only
  trustworthy while you can still see where it came from.
- `views/partials/documents/` is the same document as a reference *inside* the
  description: `chip` inline, `button` on its own line, both inserted as merge
  tags (see the root CLAUDE.md) and rendered from the row. Their icons are
  masked spans rather than `<svg>` — this markup goes back through the rich
  editor's renderer, which sanitises with Symfony's `allowSafeElements()` and
  drops svg while keeping `class`. Their styles live at the bottom of
  `css/_detail-page.scss`, and the `.charity-description a` rule has to be
  overridden by name there or it underlines both in link blue.
- `views/components/` holds anonymous kebab-case components
  (`<x-charity-list>`, `<x-score-pillar>`, …).

### Adding a public page (Livewire 4 — don't use v3 syntax from memory)

1. Create `views/pages/⚡yourpage.blade.php` (the ⚡ is part of the filename)
   shaped like the existing pages: a `<?php` block containing
   `new class extends Livewire\Component { public function mount(...) {...}
   public function with(): array {...} }`, then the Blade template below the
   closing `?>`. No separate class file, no `#[Layout]` needed —
   config/livewire.php sets `component_layout => 'layouts::app'`.
2. Register it in routes/web.php:
   `Route::livewire('/your-path', 'pages::yourpage')->name('...')`.
   The component name is the filename without ⚡ or extension.

## Styles and JS

- **Switching lens does not touch the server.** Every column is rendered
  whatever the lens is; the lens only decides which start hidden, and
  `charity-list-expand.js` owns that. Each chip carries `data-lens-keys`, the
  click is intercepted in the capture phase (so `wire:click` never fires, and
  still works as the no-JS fallback), and the component's `lens` property is
  updated with `$set(..., live: false)` so the next real round trip renders the
  right one. Clicking a lens also clears that lens' stored per-visitor column
  choice — otherwise the click appears to do nothing at all.
- The list pages with a "show more" button: `⚡homepage.blade.php` holds
  `$perPage` and `loadMore()`, and anything that changes which rows are listed
  or in what order (`sort()`, `setLens()`, `updatedSearch()`) calls
  `resetPaging()`. Sorting must come back from the database over the whole set;
  re-ordering the rows already loaded would look like a ranking without being
  one. The query also carries a final `orderBy('charities.id')` so ties break
  identically between requests — without it a tied row can appear on two pages
  and another on none. **`$barMaxima` is passed into `<x-charity-list>`, not
  derived from `$charities`**: `HomepageColumns::barMaxima()` measures it over
  the whole filtered set, so the bars do not silently rescale each time more
  rows load.
- The charity list has three breakpoints in `css/_list-view.scss`: 1280px,
  1024px and `$bp-tablet` (768px). The phone block is the fiddly one, because
  the pinned name and appraisal columns are subtracted from the viewport
  before anything can scroll. Two rules there are counter-intuitive and worth
  leaving alone: the table is `min-width: max-content` (a fixed floor makes the
  name column absorb the slack, which is what broke it), and `.list-wrap`
  breaks out of the page padding with negative margins to win back 64px.
- Real styling is hand-written SCSS: `css/app.scss` `@use`s the `_*.scss`
  partials (BEM-ish naming, `.navbar__…`). Tailwind 4 is installed and in
  vite.config.js, but public pages don't use utility classes — don't
  introduce them into existing SCSS-styled markup.
- `js/app.js` pulls in Chart.js plus `score-overrides.js`, `charity-charts.js`,
  `column-tooltips.js`.
- After editing anything here run `npm run build` — `public/build/` is
  committed and deployed as-is (see root CLAUDE.md).
