Files
artcraft/app/contexts/EngineProvider.tsx
T
wilandwil d5e3b9af97 Scene - Save Load - v2.0 (#303)
Saving and Loading of Scenes:
- loading scenes from URL (aka the scenetoken) is fixed
- URL changes according to the changing of loaded scene
- scene signal is created for storing the metadata of a scene
- editor can hydrate the scene signal data
- options in the file menu changes states according to scene status

Editor Changes and Fixes:
- fixes the way Editor Engine is constructed and initialized for
stability
- fixes typing issues on all that is passed to Editor Engine from
react-land

Other Fixes, Bells & Whistles:
- changed "back to dashboard" button to "back to editor", and the
correct behavior of it
- cleaned up routes and page files so routes designation are actually
mutually exclusive

Co-authored-by: wil <wil@storyteller.ai>
2024-05-02 22:55:00 -04:00

42 lines
1.1 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 {
children: ReactNode;
}
export const EngineProvider = ({
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]);
return (
<EngineContext.Provider value={editor}>{children}</EngineContext.Provider>
);
};