better api

This commit is contained in:
Aakansha Doshi 2023-09-22 11:22:39 +05:30
parent 8654958aba
commit e1b0b559f5
3 changed files with 7 additions and 19 deletions

View File

@ -1192,10 +1192,7 @@ class App extends React.Component<AppProps, AppState> {
> >
{this.props.children} {this.props.children}
{this.state.activeTool.type === "mermaid" && ( {this.state.activeTool.type === "mermaid" && (
<MermaidToExcalidraw <MermaidToExcalidraw />
appState={this.state}
elements={this.scene.getNonDeletedElements()}
/>
)} )}
</LayerUI> </LayerUI>
@ -3107,7 +3104,7 @@ class App extends React.Component<AppProps, AppState> {
} }
}); });
private setActiveTool = ( public setActiveTool = (
tool: tool:
| { | {
type: type:

View File

@ -1,7 +1,6 @@
import { useState, useRef, useEffect, useDeferredValue } from "react"; import { useState, useRef, useEffect, useDeferredValue } from "react";
import { AppState, BinaryFiles } from "../types"; import { BinaryFiles } from "../types";
import { updateActiveTool } from "../utils"; import { useApp } from "./App";
import { useApp, useExcalidrawSetAppState } from "./App";
import { Button } from "./Button"; import { Button } from "./Button";
import { Dialog } from "./Dialog"; import { Dialog } from "./Dialog";
import { DEFAULT_EXPORT_PADDING, DEFAULT_FONT_SIZE } from "../constants"; import { DEFAULT_EXPORT_PADDING, DEFAULT_FONT_SIZE } from "../constants";
@ -65,13 +64,7 @@ const ErrorComp = ({ error }: { error: string }) => {
); );
}; };
const MermaidToExcalidraw = ({ const MermaidToExcalidraw = () => {
appState,
elements,
}: {
appState: AppState;
elements: readonly NonDeletedExcalidrawElement[];
}) => {
const mermaidToExcalidrawLib = useRef<{ const mermaidToExcalidrawLib = useRef<{
parseMermaidToExcalidraw: ( parseMermaidToExcalidraw: (
defination: string, defination: string,
@ -174,11 +167,8 @@ const MermaidToExcalidraw = ({
renderExcalidrawPreview(); renderExcalidrawPreview();
}, [deferredText]); }, [deferredText]);
const setAppState = useExcalidrawSetAppState();
const onClose = () => { const onClose = () => {
const activeTool = updateActiveTool(appState, { type: "selection" }); app.setActiveTool({ type: "selection" });
setAppState({ activeTool });
saveMermaidDataToStorage(text); saveMermaidDataToStorage(text);
}; };

View File

@ -533,6 +533,7 @@ export type AppClassProperties = {
addFiles: App["addFiles"]; addFiles: App["addFiles"];
setSelection: App["setSelection"]; setSelection: App["setSelection"];
addElementsFromPasteOrLibrary: App["addElementsFromPasteOrLibrary"]; addElementsFromPasteOrLibrary: App["addElementsFromPasteOrLibrary"];
setActiveTool: App["setActiveTool"];
}; };
export type PointerDownState = Readonly<{ export type PointerDownState = Readonly<{