@@ -4,14 +4,14 @@ import { containsFiles, getFiles } from '@atlaskit/pragmatic-drag-and-drop/exter
4
4
import { preventUnhandled } from '@atlaskit/pragmatic-drag-and-drop/prevent-unhandled' ;
5
5
import type { SystemStyleObject } from '@invoke-ai/ui-library' ;
6
6
import { Box , Flex , Heading } from '@invoke-ai/ui-library' ;
7
+ import { logger } from 'app/logging/logger' ;
7
8
import { getStore } from 'app/store/nanostores/store' ;
8
9
import { useAppSelector } from 'app/store/storeHooks' ;
9
10
import { DndDropOverlay } from 'features/dnd/DndDropOverlay' ;
10
11
import type { DndTargetState } from 'features/dnd/types' ;
11
12
import { selectAutoAddBoardId } from 'features/gallery/store/gallerySelectors' ;
12
- import { selectMaxImageUploadCount } from 'features/system/store/configSlice' ;
13
13
import { toast } from 'features/toast/toast' ;
14
- import { memo , useCallback , useEffect , useMemo , useRef , useState } from 'react' ;
14
+ import { memo , useCallback , useEffect , useRef , useState } from 'react' ;
15
15
import { useTranslation } from 'react-i18next' ;
16
16
import { uploadImages } from 'services/api/endpoints/images' ;
17
17
import { useBoardName } from 'services/api/hooks/useBoardName' ;
@@ -20,6 +20,7 @@ import { z } from 'zod';
20
20
21
21
const ACCEPTED_IMAGE_TYPES = [ 'image/png' , 'image/jpg' , 'image/jpeg' ] ;
22
22
const ACCEPTED_FILE_EXTENSIONS = [ '.png' , '.jpg' , '.jpeg' ] ;
23
+ const log = logger ( 'paste' ) ;
23
24
24
25
// const MAX_IMAGE_SIZE = 4; //In MegaBytes
25
26
// const sizeInMB = (sizeInBytes: number, decimalsNum = 2) => {
@@ -66,17 +67,18 @@ const sx = {
66
67
} ,
67
68
} satisfies SystemStyleObject ;
68
69
70
+ const maxImageUploadCount = undefined ;
71
+
69
72
export const FullscreenDropzone = memo ( ( ) => {
70
73
const { t } = useTranslation ( ) ;
71
74
const ref = useRef < HTMLDivElement > ( null ) ;
72
- const maxImageUploadCount = useAppSelector ( selectMaxImageUploadCount ) ;
73
- const [ dndState , setDndState ] = useState < DndTargetState > ( 'idle' ) ;
74
75
75
- const uploadFilesSchema = useMemo ( ( ) => getFilesSchema ( maxImageUploadCount ) , [ maxImageUploadCount ] ) ;
76
+ const [ dndState , setDndState ] = useState < DndTargetState > ( 'idle' ) ;
76
77
77
78
const validateAndUploadFiles = useCallback (
78
79
( files : File [ ] ) => {
79
80
const { getState } = getStore ( ) ;
81
+ const uploadFilesSchema = getFilesSchema ( maxImageUploadCount ) ;
80
82
const parseResult = uploadFilesSchema . safeParse ( files ) ;
81
83
82
84
if ( ! parseResult . success ) {
@@ -105,7 +107,7 @@ export const FullscreenDropzone = memo(() => {
105
107
106
108
uploadImages ( uploadArgs ) ;
107
109
} ,
108
- [ maxImageUploadCount , t , uploadFilesSchema ]
110
+ [ maxImageUploadCount , t ]
109
111
) ;
110
112
111
113
useEffect ( ( ) => {
@@ -144,24 +146,59 @@ export const FullscreenDropzone = memo(() => {
144
146
} , [ validateAndUploadFiles ] ) ;
145
147
146
148
useEffect ( ( ) => {
149
+ log . info ( 'use effect' ) ;
147
150
const controller = new AbortController ( ) ;
148
151
149
152
window . addEventListener (
150
153
'paste' ,
151
154
( e ) => {
155
+ log . info ( 'event listener' ) ;
156
+ log . info ( JSON . stringify ( e . clipboardData ) ) ;
152
157
if ( ! e . clipboardData ?. files ) {
158
+ log . info ( 'no files' ) ;
153
159
return ;
154
160
}
155
161
const files = Array . from ( e . clipboardData . files ) ;
156
- validateAndUploadFiles ( files ) ;
162
+ const { getState } = getStore ( ) ;
163
+ const uploadFilesSchema = getFilesSchema ( undefined ) ;
164
+ const parseResult = uploadFilesSchema . safeParse ( files ) ;
165
+
166
+ if ( ! parseResult . success ) {
167
+ // const description =
168
+ // maxImageUploadCount === undefined
169
+ // ? t('toast.uploadFailedInvalidUploadDesc')
170
+ // : t('toast.uploadFailedInvalidUploadDesc_withCount', { count: maxImageUploadCount });
171
+
172
+ // toast({
173
+ // id: 'UPLOAD_FAILED',
174
+ // title: t('toast.uploadFailed'),
175
+ // description,
176
+ // status: 'error',
177
+ // });
178
+ log . info ( "couldn't parse" ) ;
179
+ return ;
180
+ }
181
+ const autoAddBoardId = selectAutoAddBoardId ( getState ( ) ) ;
182
+
183
+ const uploadArgs : UploadImageArg [ ] = files . map ( ( file , i ) => ( {
184
+ file,
185
+ image_category : 'user' ,
186
+ is_intermediate : false ,
187
+ board_id : autoAddBoardId === 'none' ? undefined : autoAddBoardId ,
188
+ isFirstUploadOfBatch : i === 0 ,
189
+ } ) ) ;
190
+
191
+ uploadImages ( uploadArgs ) ;
192
+ // validateAndUploadFiles(files);
157
193
} ,
158
194
{ signal : controller . signal }
159
195
) ;
160
196
161
197
return ( ) => {
198
+ log . info ( 'aborted' ) ;
162
199
controller . abort ( ) ;
163
200
} ;
164
- } , [ validateAndUploadFiles ] ) ;
201
+ } , [ ] ) ;
165
202
166
203
return (
167
204
< Box ref = { ref } data-dnd-state = { dndState } sx = { sx } >
0 commit comments