Files
artcraft/app/contexts/EngineProvider.tsx
T
wilandwil ad2677a575 Scene - Save Load - v2.1 (#305)
Saving and Loading of Scenes
- Save New scene to server implemented
- Retrieving sceneToken from new scene and refreshes URL, which brings
the editor to state of editing an existing Scene
- Optimized scene reloading when URL changes
- Save Existing scene to server implemented
- Rename scene to server implemented
- Optimized Scene Renaming Component and Endpoint Operation

Editor Changes and Fixes:
- changed the way the api_manager retrieve session tokens
- changed the way api_manager uses a fetcher for the operations in
saving scenes

Co-authored-by: wil <wil@storyteller.ai>
2024-05-03 13:03:06 -04:00

52 lines
1.3 KiB
TypeScript

import { ReactNode, useEffect, useContext, useState } from "react";
import { AuthenticationContext } from "~/contexts/Authentication";
import { AppUiContext } from "~/contexts/AppUiContext";
import { EngineContext } from "./EngineContext";
import { signalScene } from "~/store";
import Editor from "~/pages/PageEnigma/js/editor";
interface Props {
sceneToken?: string
children: ReactNode;
}
export const EngineProvider = ({
sceneToken,
children,
}: Props) => {
const [editor, setEditor] = useState<Editor | null>(null);
const [, dispatchAppUiState] = useContext(AppUiContext);
const {authState} = useContext(AuthenticationContext);
useEffect(() => {
setEditor((curr) => {
if (curr !== null) {
console.warn("Editor Engine already exist");
return curr;
} else if (authState.sessionToken && authState.userInfo ){
return new Editor({
dispatchAppUiState,
authState,
signalScene,
});
}
return curr;
});
// }
}, [dispatchAppUiState, authState]);
useEffect(() => {
if (editor && editor.can_initialize) {
editor.initialize({
sceneToken: sceneToken || ""}
);
}
}, [editor, sceneToken]);
return (
<EngineContext.Provider value={editor}>{children}</EngineContext.Provider>
);
};