mirror of
https://github.com/backnotprop/plannotator.git
synced 2026-09-14 14:17:26 +08:00
401793e35f
Adds user-editable display names and persistent config via ~/.plannotator/config.json. - ConfigStore singleton with precedence: server config file > cookie > default - Editable identity input in Settings with "Use git name" and regenerate buttons - POST /api/config endpoint for write-back across all 6 servers - getServerConfig() reads config fresh per request (no stale cache) - Eager constructor hydration so the store is safe to read before init() - vendor.sh as single source of truth for Pi extension vendoring - Vendor parity test to prevent missing generated modules Closes #396
21 lines
764 B
TypeScript
21 lines
764 B
TypeScript
/**
|
|
* React hook for consuming ConfigStore values.
|
|
*
|
|
* Uses useSyncExternalStore for concurrent-mode-safe subscriptions
|
|
* to the singleton configStore — no context provider needed.
|
|
*/
|
|
|
|
import { useCallback, useSyncExternalStore } from 'react';
|
|
import { configStore, type SettingValue } from './configStore';
|
|
import type { SettingName } from './settings';
|
|
|
|
/** Read a config value reactively. Re-renders when the store changes. */
|
|
export function useConfigValue<K extends SettingName>(key: K): SettingValue<K> {
|
|
const subscribe = useCallback(
|
|
(onStoreChange: () => void) => configStore.subscribe(onStoreChange),
|
|
[],
|
|
);
|
|
const getSnapshot = useCallback(() => configStore.get(key), [key]);
|
|
return useSyncExternalStore(subscribe, getSnapshot);
|
|
}
|