refactor(characters): drive shared UI from active character
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user