Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

useEnvironmentTheme.ts

24 lines820 Bytes

1import { useAtomValue } from "@effect/atom-react";
2​
3import { subscribeAtomChanges } from "../rpc/atomRegistry";
4import {
5 environmentThemeDefinitionsAtom,
6 storePublishedEnvironmentThemes,
7 type ThemeDefinition,
8} from "../themePalette";
9import { refreshTheme } from "./useTheme";
10​
11export function useEnvironmentThemeDefinitions(): ReadonlyArray<ThemeDefinition> {
12 return useAtomValue(environmentThemeDefinitionsAtom);
14​
15/**
16 * The palette is painted from a snapshot taken when the theme last changed, so new colors
17 * only land if the active theme is re-applied.
18 */
19export function startEnvironmentThemeRepaint(): () => void {
20 return subscribeAtomChanges(environmentThemeDefinitionsAtom, (definitions) => {
21 storePublishedEnvironmentThemes(definitions);
22 refreshTheme({ preservePreview: true });
23 });