feat(characters): support character-scoped conversations
This commit is contained in:
@@ -4,6 +4,8 @@ import type { Dispatch, ReactNode } from "react";
|
||||
import { createActorContext, shallowEqual } from "@xstate/react";
|
||||
import type { SnapshotFrom } from "xstate";
|
||||
|
||||
import { DEFAULT_CHARACTER_ID } from "@/data/constants/character";
|
||||
|
||||
import { privateRoomMachine } from "./private-room-machine";
|
||||
import type {
|
||||
PrivateRoomEvent,
|
||||
@@ -11,6 +13,7 @@ import type {
|
||||
} from "./private-room-machine";
|
||||
|
||||
export interface PrivateRoomContextState {
|
||||
characterId: string;
|
||||
status: string;
|
||||
items: MachineContext["items"];
|
||||
creditBalance: number;
|
||||
@@ -31,11 +34,17 @@ const PrivateRoomActorContext = createActorContext(privateRoomMachine);
|
||||
|
||||
export interface PrivateRoomProviderProps {
|
||||
children: ReactNode;
|
||||
characterId?: string;
|
||||
}
|
||||
|
||||
export function PrivateRoomProvider({ children }: PrivateRoomProviderProps) {
|
||||
export function PrivateRoomProvider({
|
||||
children,
|
||||
characterId = DEFAULT_CHARACTER_ID,
|
||||
}: PrivateRoomProviderProps) {
|
||||
return (
|
||||
<PrivateRoomActorContext.Provider>{children}</PrivateRoomActorContext.Provider>
|
||||
<PrivateRoomActorContext.Provider options={{ input: { characterId } }}>
|
||||
{children}
|
||||
</PrivateRoomActorContext.Provider>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -58,6 +67,7 @@ function selectPrivateRoomState(
|
||||
state: PrivateRoomSnapshot,
|
||||
): PrivateRoomContextState {
|
||||
return {
|
||||
characterId: state.context.characterId,
|
||||
status: String(state.value),
|
||||
items: state.context.items,
|
||||
creditBalance: state.context.creditBalance,
|
||||
|
||||
Reference in New Issue
Block a user