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