- lh:settings-saved CustomEvent (the lh:chat-renamed pattern, owner ruling): every writer (composer save, SetupDialog save, the settings write seam — one dispatch point carrying the section) notifies after a successful PUT; every reader re-reads its own seam: ModelControl's record read, the Agent section's slots/catalog, and chat.tsx's configured state (clearing slots mid-session now surfaces the setup CTA without a reload). Self-notifications re-read idempotently. - MenuShell now announces lh:menu-open/lh:menu-close (still placement- only); the settings dialog's content column locks (overflow-hidden, count-based) while any menu is open — wheel-scrolling with a dropdown down is dead; the re-place-on-scroll fallback stays for un-lockable surfaces. - The settings thinking menus' 'Default' noneRow is retired (owner: the unset state can't re-enter once chunk 2's auto-populate lands; no unpin is needed). - Live-caught regression from the MenuShell migration fixed: the composer's outside-click handler never learned the portaled menu body isn't a container descendant — menu-row pointerdowns counted as outside and ATE THE PICK (composer picks have been dead for pointer users since 221c99d); rows now carve out via [data-lh-menu], the settings sections' discipline. - Item 4 (resolved-level display for legacy records) deferred to chunk 2 per owner ruling — the payload omits the level for legacy no-level records and DEFAULT_THINKING_ORDER was server-only (now in the core barrel via bd68486, exactly the seam chunk 2 needs).
47 lines
2.1 KiB
TypeScript
47 lines
2.1 KiB
TypeScript
"use client";
|
|
|
|
/**
|
|
* THE cross-surface settings signal (fix wave, owner ruling 2026-09-22):
|
|
* every WRITER dispatches after a successful PUT, every READER re-reads —
|
|
* the composer reflects the strong slot the instant setup saves, the
|
|
* settings section reflects the composer's pick on its next mount... and
|
|
* so on, by construction. CustomEvent on the window, the lh:chat-renamed
|
|
* pattern: writers and readers live in different component subtrees
|
|
* (portaled dialogs included), and the app already speaks this dialect.
|
|
*
|
|
* The event carries the section name so ONE event serves all sections —
|
|
* readers filter on what they actually read.
|
|
*/
|
|
import { useEffect, useRef } from "react";
|
|
|
|
export const SETTINGS_SAVED_EVENT = "lh:settings-saved";
|
|
|
|
/** The settings sections a writer can land (the write seam's union). */
|
|
export type SettingsSection = "general" | "agent" | "models" | "appearance" | "graph";
|
|
|
|
/** Writers call this after the PUT resolves ok — never before (a failed
|
|
* write notifies nothing; the record is unchanged). */
|
|
export function notifySettingsSaved(section: SettingsSection): void {
|
|
window.dispatchEvent(
|
|
new CustomEvent(SETTINGS_SAVED_EVENT, { detail: { section } }),
|
|
);
|
|
}
|
|
|
|
/** Non-hook listener (imperative seams, tests). Returns an unsubscribe. */
|
|
export function onSettingsSaved(handler: (section: SettingsSection) => void): () => void {
|
|
const listener = (e: Event) => {
|
|
const section = (e as CustomEvent<{ section?: SettingsSection }>).detail?.section;
|
|
if (section !== undefined) handler(section);
|
|
};
|
|
window.addEventListener(SETTINGS_SAVED_EVENT, listener);
|
|
return () => window.removeEventListener(SETTINGS_SAVED_EVENT, listener);
|
|
}
|
|
|
|
/** Reader subscription: re-invokes whenever a writer lands, with the
|
|
* handler captured through a ref so callers never churn the
|
|
* subscription (and never stale-close over it either). */
|
|
export function useSettingsSaved(handler: (section: SettingsSection) => void): void {
|
|
const saved = useRef(handler);
|
|
saved.current = handler;
|
|
useEffect(() => onSettingsSaved((section) => saved.current(section)), []);
|
|
} |