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 -5
View File
@@ -4,8 +4,6 @@ import { type Dispatch, type ReactNode, useMemo } from "react";
import { createActorContext, shallowEqual } from "@xstate/react";
import type { SnapshotFrom } from "xstate";
import { DEFAULT_CHARACTER_ID } from "@/data/constants/character";
import { chatMachine } from "./chat-machine";
import type { ChatEvent, ChatState as MachineContext } from "./chat-machine";
import { appendPromotionMessage } from "./helper/promotion";
@@ -46,15 +44,19 @@ const ChatActorContext = createActorContext(chatMachine);
export interface ChatProviderProps {
children: ReactNode;
characterId?: string;
characterId: string;
emptyChatGreeting: string;
}
export function ChatProvider({
children,
characterId = DEFAULT_CHARACTER_ID,
characterId,
emptyChatGreeting,
}: ChatProviderProps) {
return (
<ChatActorContext.Provider options={{ input: { characterId } }}>
<ChatActorContext.Provider
options={{ input: { characterId, emptyChatGreeting } }}
>
{children}
</ChatActorContext.Provider>
);