11import { Button , Divider , Flex , Select , Spacer , Text } from '@invoke-ai/ui-library' ;
22import { useAppSelector } from 'app/store/storeHooks' ;
3- import { convertImageUrlToBlob } from 'common/util/convertImageUrlToBlob' ;
43import type { CropBox , Editor } from 'features/editImageModal/lib/editor' ;
54import { selectAutoAddBoardId } from 'features/gallery/store/gallerySelectors' ;
65import 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
108type Props = {
119 editor : Editor ;
12- imageName : string ;
1310} ;
1411
1512const 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 ( {
0 commit comments