I want to be able to set the theme for each workspace, not just globally and…

merged…
osebo31d ago

I want to be able to set the theme for each workspace, not just globally and it should persist

3 repliesoldestnewest
Osebotfable-5-131d ago

Today the theme (System | Light | Dark plus the palette picked on /themes) lives only in this browser's localStorage, so it is the same for every workspace and disappears with the browser. Plan:

Model: a workspace gets its own palette, stored on the server.

  • workspaces.theme jsonb (drizzle/0012): { dark: <palette id> | null, light: <palette id> | null }, same two slots the gallery already has. Only palette ids are stored; the CSS is derived at render time so a palette mapping change applies everywhere.
  • Set by the workspace owner (same tier as the open switch and the address), via PATCH /api/workspaces/[id] { theme }. Members and visitors see it: a forum gets a look of its own, like the name and the address.
  • The viewer's own System | Light | Dark switch still decides which of the two slots shows (that is a device preference, night mode etc.); the workspace palette only overrides the palette for that appearance. Where the workspace sets nothing, the viewer's browser palette / the default still applies.

Where it applies: every page that is about a workspace (/<slug>, /threads/[id], /workspaces/[id]) renders a small WorkspaceTheme component: an inline script applies the palette before the page paints (like THEME_INIT_SCRIPT in the head), and an effect keeps it in sync on soft navigation and restores the browser palette when you leave the workspace. /themes, /workspaces, /about keep the browser palette.

Picking it: /themes gets a "Saving for" control: This browser (today's behaviour) or any workspace you own (preselected to the header's current workspace). With a workspace selected, "Use" / "Back to default" write to the server and the page previews that workspace's palette live. The manage page (/workspaces/[id]) shows the current palettes with a link to /themes for that workspace.

If you'd rather have a personal per-workspace theme (my own choice for each workspace, not shared with members), say so: that would be a per-user table instead of a workspace column, and the rest of the plumbing stays the same.

Osebotfable-5-131d agothreadide@f469307

Done and pushed on thread/dc46c8c6 (threadide f469307).

What you get

  • A workspace can have its own dark and light palette, stored on the server (workspaces.theme, migration drizzle/0012). It applies to everyone reading that workspace, over whatever they picked for their own browser. Your System | Light | Dark switch still decides which of the two is showing.
  • /themes has a new Saving for control: This browser only (what it did before) or any workspace you own. It opens on the header's current workspace when you own it (or on ?workspace=<id>), so picking a tile there saves to that workspace; with a workspace selected the page shows that workspace's palettes so you see exactly what its readers get.
  • /workspaces/[id] (manage page, owner) has a Theme card naming both slots with a Change link to /themes for that workspace.
  • Pages that apply it: /<slug>, /threads/[id], /workspaces/[id]. The palette is set before first paint on a hard load (inline script, same trick as the head script) and swapped in/out on soft navigation, so going from a themed workspace to /about or /workspaces gives you your browser palette back.

Choices to be aware of

  • It is a workspace setting, owner-set and shared, like the name and the address. If you meant a personal choice per workspace (yours alone, not seen by members), say so: that is a per-user table instead of the column, everything else stays.
  • A workspace with only a dark palette set leaves light mode to the viewer's own light palette (or the default), mirroring how the gallery's two slots already work.
  • Only palette ids are stored; the CSS is derived at render time, so any future change to the palette mapping reaches every workspace.

Verified: tsc and next build pass; the inline script was run in a Node vm for forced dark / forced light with no light slot / system+OS dark; screenshots attached are the real components rendered against globals.css (the app can't run here, so the PATCH round trip and the before-paint behaviour on a live page are not exercised). Deploy needs nothing beyond the normal production build, which applies the migration.

/themes with the new "Saving for" control set to a workspace (static mock of the real component + globals.css)
/themes with the new "Saving for" control set to a workspace (static mock of the real component + globals.css)
Theme card on the workspace manage page (owner only)
Theme card on the workspace manage page (owner only)
Osebot31d ago

Merged threadide #141 by @osebo (merge, 51251ac).