1
1
import { Button , Divider , Flex , Select , Spacer , Text } from '@invoke-ai/ui-library' ;
2
2
import { useAppSelector } from 'app/store/storeHooks' ;
3
- import { convertImageUrlToBlob } from 'common/util/convertImageUrlToBlob' ;
4
3
import type { CropBox , Editor } from 'features/editImageModal/lib/editor' ;
5
4
import { selectAutoAddBoardId } from 'features/gallery/store/gallerySelectors' ;
6
5
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' ;
9
7
10
8
type Props = {
11
9
editor : Editor ;
12
- imageName : string ;
13
10
} ;
14
11
15
12
const CROP_ASPECT_RATIO_MAP : Record < string , number > = {
@@ -35,21 +32,19 @@ export const getAspectRatioString = (ratio: number | null) => {
35
32
return 'free' ;
36
33
} ;
37
34
38
- export const EditorContainer = ( { editor, imageName } : Props ) => {
35
+ export const EditorContainer = ( { editor } : Props ) => {
39
36
const containerRef = useRef < HTMLDivElement > ( null ) ;
40
37
const [ zoom , setZoom ] = useState ( 100 ) ;
41
38
const [ cropInProgress , setCropInProgress ] = useState ( false ) ;
42
39
const [ cropBox , setCropBox ] = useState < CropBox | null > ( null ) ;
43
40
const [ cropApplied , setCropApplied ] = useState ( false ) ;
44
41
const [ aspectRatio , setAspectRatio ] = useState < string > ( 'free' ) ;
45
- const { data : imageDTO } = useGetImageDTOQuery ( imageName ) ;
46
42
const autoAddBoardId = useAppSelector ( selectAutoAddBoardId ) ;
47
43
48
44
const [ uploadImage ] = useUploadImageMutation ( { fixedCacheKey : 'editorContainer' } ) ;
49
45
50
46
const setup = useCallback (
51
- async ( imageDTO : ImageDTO , container : HTMLDivElement ) => {
52
- console . log ( 'Setting up editor' ) ;
47
+ ( container : HTMLDivElement ) => {
53
48
editor . init ( container ) ;
54
49
editor . onZoomChange ( ( zoom ) => {
55
50
setZoom ( zoom ) ;
@@ -80,25 +75,18 @@ export const EditorContainer = ({ editor, imageName }: Props) => {
80
75
// setIsCropping(false);
81
76
// setHasCropBbox(false);
82
77
} ) ;
83
- const blob = await convertImageUrlToBlob ( imageDTO . image_url ) ;
84
- if ( ! blob ) {
85
- console . error ( 'Failed to convert image to blob' ) ;
86
- return ;
87
- }
88
78
setAspectRatio ( getAspectRatioString ( editor . getCropAspectRatio ( ) ) ) ;
89
- await editor . loadImage ( imageDTO . image_url ) ;
90
79
editor . fitToContainer ( ) ;
91
80
} ,
92
81
[ editor ]
93
82
) ;
94
83
95
84
useEffect ( ( ) => {
96
85
const container = containerRef . current ;
97
- if ( ! container || ! imageDTO ) {
86
+ if ( ! container ) {
98
87
return ;
99
88
}
100
- editor . init ( container ) ;
101
- setup ( imageDTO , container ) ;
89
+ setup ( container ) ;
102
90
const handleResize = ( ) => {
103
91
editor . resize ( container . clientWidth , container . clientHeight ) ;
104
92
} ;
@@ -108,7 +96,7 @@ export const EditorContainer = ({ editor, imageName }: Props) => {
108
96
return ( ) => {
109
97
resizeObserver . disconnect ( ) ;
110
98
} ;
111
- } , [ editor , imageDTO , setup ] ) ;
99
+ } , [ editor , setup ] ) ;
112
100
113
101
const handleStartCrop = useCallback ( ( ) => {
114
102
editor . startCrop ( ) ;
@@ -146,7 +134,7 @@ export const EditorContainer = ({ editor, imageName }: Props) => {
146
134
147
135
const handleExport = useCallback ( async ( ) => {
148
136
try {
149
- const blob = await editor . exportImage ( 'blob' , { withCropOverlay : true } ) ;
137
+ const blob = await editor . exportImage ( 'blob' ) ;
150
138
const file = new File ( [ blob ] , 'image.png' , { type : 'image/png' } ) ;
151
139
152
140
await uploadImage ( {
0 commit comments