Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

route useTheme's settings read/write through apiSystem instead of inline fetch

[._.]/ Adam Eivyc5e45bca014a
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.md
index 4d0c00f188..f120112e7e 100644
--- a/.changelog/NEXT.md
+++ b/.changelog/NEXT.md
@@ -38,6 +38,6 @@
- **[issue-2840] Paginate album/artist/author list endpoints** — `GET /api/albums`, `/api/artists`, and `/api/authors` now accept `limit`/`offset` via the shared `parsePagination`/`paginateArray` helpers, returning the same `{ items, total, limit, offset }` envelope the notes/mood-board/loras list endpoints use when a pagination param is present. Unparameterized requests still return the full array, so existing callers are unaffected.
- **[issue-2832] Split the boot-schema DDL into per-domain modules** — the ~1265-line inline `CREATE TABLE`/`CREATE INDEX`/trigger block in `ensureSchemaImpl()` (`server/lib/db.js`) is extracted into per-domain modules under `server/lib/db/schema/` (catalog, media, universes, writers-room, pipeline, privacy, tribe, audit, …), each exporting a statement array; `ensureSchemaImpl` is now a thin composer. Statement text and order are byte-identical, so the composed schema is unchanged.
- **[issue-2834] Split the ~1990-line `VideoGen.jsx` into hooks + subcomponents** — the client-side batch-queue orchestration moves into `useVideoGenQueue`, the pure model-memory / FFLF frame-budget / mode-compat helpers into `lib/videoGenParams.js`, and four presentational blocks into `components/videoGen/` (`RuntimeFingerprint`, `ModelRepairBanner`, `VideoPreviewPanel`, `VideoGenGallery`). The inline runtime-status `fetch()` now routes through a `getVideoGenRuntimeStatus` service wrapper, and the Seed input gains a proper `<label htmlFor>`/`id` pairing. Behavior and deep-link routing are unchanged.
-- **[issue-2838] Route inline `fetch('/api/...')` calls through the client service layer** — the Prompt Manager's 13+ raw prompt/provider calls move into a new `services/apiPrompts.js` (stages, variables, job-skills), and the stray inline `/api/` fetches in `ImageGen`, `LocalSetupPanel`, `StagePromptModelPicker`, and `GsdTab` route through existing/new `apiX.js` wrappers. Behavior-preserving; VideoGen's remaining site is deferred to its own split issue to avoid double-touching that file.
+- **[issue-2838] Route inline `fetch('/api/...')` calls through the client service layer** — the Prompt Manager's 13+ raw prompt/provider calls move into a new `services/apiPrompts.js` (stages, variables, job-skills), and the stray inline `/api/` fetches in `ImageGen`, `LocalSetupPanel`, `StagePromptModelPicker`, and `GsdTab` route through existing/new `apiX.js` wrappers. `useTheme`'s settings read/write now go through `apiSystem.getSettings`/`updateSettings` (silent, so the local-storage fallback stays the only error surface), which clears the last inline `/api/` fetch outside `services/`. Behavior-preserving; VideoGen's site was already routed through a service wrapper by the VideoGen split (#2834).
- **[issue-2835] Split the ~2875-line `ArcCanvas.jsx` into per-component files** — each of the 32 subcomponents/helpers (ArcHeader, EditorialRoadmapPanel, SeasonRow, IssueRow, VolumeCoversPanel, …) now lives in its own file under `client/src/components/pipeline/arcCanvas/`, with the shared severity-color map in `arcCanvas/shared.js`. `ArcCanvas.jsx` (default export) is now a thin 122-line composer and still re-exports `ArcRoadmapChart` so its public import path is unchanged. Pure mechanical, behavior-preserving refactor — no rendered-output change.
- **[issue-2836] Extract helpers from `generateManagedAppImprovementTaskForType()`** — the ~533-line function in `server/services/cosTaskGenerator.js` is decomposed into named metadata-building and gate-checking helpers (`buildImprovementTaskMetadata`, `resolveTaskInputHook`, `resolveClaimWorkRouting`, `applyPerpetualWorkGate`, `resolveBranchReconcileBlock`, `resolveIssueReconcileBlock`, `resolveReferenceWatchBlock`, `resolvePrWatcherBlock`), each returning a `{ skip }` / prompt-block result so the main function reads as a thin orchestrator. Prompt resolution (reviewers/author-filter/swarm directives plus the token-replacement chain) moves into `buildImprovementTaskDescription`, and the provider/model/effort pin layering into `applyProviderModelPins`. Behavior-preserving — no change to task generation, park/convergence semantics, or dispatch ordering.
diff --git a/client/src/hooks/useTheme.js b/client/src/hooks/useTheme.js
index a8d3dbcb2a..41bbc17fea 100644
--- a/client/src/hooks/useTheme.js
+++ b/client/src/hooks/useTheme.js
@@ -11,6 +11,7 @@ import {
TIME_OF_DAY_AUTO_EVENT as CITY_TIME_OF_DAY_AUTO_EVENT,
} from './useCitySettings';
import { safeReadStorage, safeWriteStorage } from '../lib/safeStorage.js';
+import { getSettings, updateSettings } from '../services/apiSystem.js';
const STORAGE_KEY = 'portos-theme';
@@ -61,8 +62,9 @@ export default function useTheme() {
useEffect(() => {
const controller = new AbortController();
- fetch('/api/settings', { signal: controller.signal })
- .then(r => r.ok ? r.json() : null)
+ // Silent — a failed read just falls back to localStorage (handled below),
+ // so the request() helper must not toast on top of our own warn.
+ getSettings({ silent: true, signal: controller.signal })
.then(settings => {
if (userPickedRef.current) return;
const serverTheme = settings?.theme ? normalizeThemeId(settings.theme) : null;
@@ -77,7 +79,9 @@ export default function useTheme() {
}
})
.catch((err) => {
- if (err.name === 'AbortError') return;
+ // request() collapses an aborted fetch into a generic error, so check
+ // the controller too — an unmount/StrictMode remount isn't a failure.
+ if (controller.signal.aborted || err.name === 'AbortError') return;
console.warn(`⚠️ Theme fetch failed, using localStorage fallback: ${err.message}`);
});
return () => controller.abort();
@@ -92,11 +96,10 @@ export default function useTheme() {
setThemeId(normalized);
safeWriteStorage(STORAGE_KEY, normalized);
resetCityTimeOfDayOverride();
- fetch('/api/settings', {
- method: 'PUT',
- headers: { 'Content-Type': 'application/json' },
- body: JSON.stringify({ theme: normalized }),
- }).catch(() => console.warn('Theme sync to server failed'));
+ // Silent — the theme is already applied locally; a failed sync only warrants
+ // a console warning, not a toast on every theme switch.
+ updateSettings({ theme: normalized }, { silent: true })
+ .catch(() => console.warn('⚠️ Theme sync to server failed'));
}, []);
const toggleMode = useCallback(() => {