fix: double image dialog shown on insert (#7152)

This commit is contained in:
David Luzar 2023-10-16 00:19:46 +02:00 committed by GitHub
parent 44d9d5fcac
commit aaf73c8ff3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 26 additions and 50 deletions

View file

@ -1188,7 +1188,6 @@ class App extends React.Component<AppProps, AppState> {
>
<LayerUI
canvas={this.canvas}
interactiveCanvas={this.interactiveCanvas}
appState={this.state}
files={this.files}
setAppState={this.setAppState}
@ -1205,7 +1204,6 @@ class App extends React.Component<AppProps, AppState> {
this.state.zenModeEnabled
}
UIOptions={this.props.UIOptions}
onImageAction={this.onImageAction}
onExportImage={this.onExportImage}
renderWelcomeScreen={
!this.state.isLoading &&
@ -3135,9 +3133,13 @@ class App extends React.Component<AppProps, AppState> {
setActiveTool = (
tool:
| {
type: ToolType;
}
| (
| { type: Exclude<ToolType, "image"> }
| {
type: Extract<ToolType, "image">;
insertOnCanvasDirectly?: boolean;
}
)
| { type: "custom"; customType: string },
) => {
const nextActiveTool = updateActiveTool(this.state, tool);
@ -3153,7 +3155,10 @@ class App extends React.Component<AppProps, AppState> {
this.setState({ suggestedBindings: [] });
}
if (nextActiveTool.type === "image") {
this.onImageAction();
this.onImageAction({
insertOnCanvasDirectly:
(tool.type === "image" && tool.insertOnCanvasDirectly) ?? false,
});
}
this.setState((prevState) => {
@ -7353,9 +7358,11 @@ class App extends React.Component<AppProps, AppState> {
}
};
private onImageAction = async (
{ insertOnCanvasDirectly } = { insertOnCanvasDirectly: false },
) => {
private onImageAction = async ({
insertOnCanvasDirectly,
}: {
insertOnCanvasDirectly: boolean;
}) => {
try {
const clientX = this.state.width / 2 + this.state.offsetLeft;
const clientY = this.state.height / 2 + this.state.offsetTop;