Skip to content

Commit 4829975

Browse files
feat(ui): make the editor components not care about the image
1 parent 49da4e0 commit 4829975

File tree

3 files changed

+11
-27
lines changed

3 files changed

+11
-27
lines changed

invokeai/frontend/web/src/features/editImageModal/components/EditorContainer.tsx

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
import { Button, Divider, Flex, Select, Spacer, Text } from '@invoke-ai/ui-library';
22
import { useAppSelector } from 'app/store/storeHooks';
3-
import { convertImageUrlToBlob } from 'common/util/convertImageUrlToBlob';
43
import type { CropBox, Editor } from 'features/editImageModal/lib/editor';
54
import { selectAutoAddBoardId } from 'features/gallery/store/gallerySelectors';
65
import React, { useCallback, useEffect, useRef, useState } from 'react';
7-
import { useGetImageDTOQuery, useUploadImageMutation } from 'services/api/endpoints/images';
8-
import type { ImageDTO } from 'services/api/types';
6+
import { useUploadImageMutation } from 'services/api/endpoints/images';
97

108
type Props = {
119
editor: Editor;
12-
imageName: string;
1310
};
1411

1512
const CROP_ASPECT_RATIO_MAP: Record<string, number> = {
@@ -35,21 +32,19 @@ export const getAspectRatioString = (ratio: number | null) => {
3532
return 'free';
3633
};
3734

38-
export const EditorContainer = ({ editor, imageName }: Props) => {
35+
export const EditorContainer = ({ editor }: Props) => {
3936
const containerRef = useRef<HTMLDivElement>(null);
4037
const [zoom, setZoom] = useState(100);
4138
const [cropInProgress, setCropInProgress] = useState(false);
4239
const [cropBox, setCropBox] = useState<CropBox | null>(null);
4340
const [cropApplied, setCropApplied] = useState(false);
4441
const [aspectRatio, setAspectRatio] = useState<string>('free');
45-
const { data: imageDTO } = useGetImageDTOQuery(imageName);
4642
const autoAddBoardId = useAppSelector(selectAutoAddBoardId);
4743

4844
const [uploadImage] = useUploadImageMutation({ fixedCacheKey: 'editorContainer' });
4945

5046
const setup = useCallback(
51-
async (imageDTO: ImageDTO, container: HTMLDivElement) => {
52-
console.log('Setting up editor');
47+
(container: HTMLDivElement) => {
5348
editor.init(container);
5449
editor.onZoomChange((zoom) => {
5550
setZoom(zoom);
@@ -80,25 +75,18 @@ export const EditorContainer = ({ editor, imageName }: Props) => {
8075
// setIsCropping(false);
8176
// setHasCropBbox(false);
8277
});
83-
const blob = await convertImageUrlToBlob(imageDTO.image_url);
84-
if (!blob) {
85-
console.error('Failed to convert image to blob');
86-
return;
87-
}
8878
setAspectRatio(getAspectRatioString(editor.getCropAspectRatio()));
89-
await editor.loadImage(imageDTO.image_url);
9079
editor.fitToContainer();
9180
},
9281
[editor]
9382
);
9483

9584
useEffect(() => {
9685
const container = containerRef.current;
97-
if (!container || !imageDTO) {
86+
if (!container) {
9887
return;
9988
}
100-
editor.init(container);
101-
setup(imageDTO, container);
89+
setup(container);
10290
const handleResize = () => {
10391
editor.resize(container.clientWidth, container.clientHeight);
10492
};
@@ -108,7 +96,7 @@ export const EditorContainer = ({ editor, imageName }: Props) => {
10896
return () => {
10997
resizeObserver.disconnect();
11098
};
111-
}, [editor, imageDTO, setup]);
99+
}, [editor, setup]);
112100

113101
const handleStartCrop = useCallback(() => {
114102
editor.startCrop();
@@ -146,7 +134,7 @@ export const EditorContainer = ({ editor, imageName }: Props) => {
146134

147135
const handleExport = useCallback(async () => {
148136
try {
149-
const blob = await editor.exportImage('blob', { withCropOverlay: true });
137+
const blob = await editor.exportImage('blob');
150138
const file = new File([blob], 'image.png', { type: 'image/png' });
151139

152140
await uploadImage({

invokeai/frontend/web/src/features/editImageModal/store/index.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,21 @@ import { atom } from 'nanostores';
44
type EditImageModalState =
55
| {
66
isOpen: false;
7-
imageName: null;
87
editor: null;
98
}
109
| {
1110
isOpen: true;
12-
imageName: string;
1311
editor: Editor;
1412
};
1513

1614
export const $editImageModalState = atom<EditImageModalState>({
1715
isOpen: false,
18-
imageName: null,
1916
editor: null,
2017
});
2118

22-
export const openEditImageModal = (imageName: string, editor: Editor) => {
19+
export const openEditImageModal = (editor: Editor) => {
2320
$editImageModalState.set({
2421
isOpen: true,
25-
imageName,
2622
editor,
2723
});
2824
};
@@ -32,7 +28,6 @@ export const closeEditImageModal = () => {
3228
editor?.destroy();
3329
$editImageModalState.set({
3430
isOpen: false,
35-
imageName: null,
3631
editor: null,
3732
});
3833
};

invokeai/frontend/web/src/features/settingsAccordions/components/VideoSettingsAccordion/StartingFrameImage.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export const StartingFrameImage = () => {
4444
[dispatch]
4545
);
4646

47-
const edit = useCallback(() => {
47+
const edit = useCallback(async () => {
4848
if (!originalImageDTO) {
4949
return;
5050
}
@@ -76,7 +76,8 @@ export const StartingFrameImage = () => {
7676
)
7777
);
7878
});
79-
openEditImageModal(originalImageDTO.image_name, editor);
79+
await editor.loadImage(originalImageDTO.image_url);
80+
openEditImageModal(editor);
8081
}, [dispatch, originalImageDTO, startingFrameImage?.crop, uploadImage]);
8182

8283
const fitsCurrentAspectRatio = useMemo(() => {

0 commit comments

Comments
 (0)