refactor(characters): drive shared UI from active character

This commit is contained in:
2026-07-17 19:33:59 +08:00
parent 8bb1e21886
commit 7bd5defa5e
42 changed files with 335 additions and 118 deletions
+7 -6
View File
@@ -2,13 +2,10 @@
import { createContext, type ReactNode, useContext } from "react";
import {
DEFAULT_CHARACTER,
type CharacterProfile,
} from "@/data/constants/character";
import type { CharacterProfile } from "@/data/constants/character";
import { getCharacterRoutes, type CharacterRoutes } from "@/router/routes";
const CharacterContext = createContext<CharacterProfile>(DEFAULT_CHARACTER);
const CharacterContext = createContext<CharacterProfile | null>(null);
export interface CharacterProviderProps {
character: CharacterProfile;
@@ -27,7 +24,11 @@ export function CharacterProvider({
}
export function useActiveCharacter(): CharacterProfile {
return useContext(CharacterContext);
const character = useContext(CharacterContext);
if (!character) {
throw new Error("useActiveCharacter must be used within CharacterProvider.");
}
return character;
}
export function useActiveCharacterRoutes(): CharacterRoutes {