Skip to content

Commit 69e7ffa

Browse files
Mary Hipppsychedelicious
authored andcommitted
add logging, remove deps
1 parent 993401a commit 69e7ffa

File tree

1 file changed

+45
-8
lines changed

1 file changed

+45
-8
lines changed

invokeai/frontend/web/src/features/dnd/FullscreenDropzone.tsx

Lines changed: 45 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ import { containsFiles, getFiles } from '@atlaskit/pragmatic-drag-and-drop/exter
44
import { preventUnhandled } from '@atlaskit/pragmatic-drag-and-drop/prevent-unhandled';
55
import type { SystemStyleObject } from '@invoke-ai/ui-library';
66
import { Box, Flex, Heading } from '@invoke-ai/ui-library';
7+
import { logger } from 'app/logging/logger';
78
import { getStore } from 'app/store/nanostores/store';
89
import { useAppSelector } from 'app/store/storeHooks';
910
import { DndDropOverlay } from 'features/dnd/DndDropOverlay';
1011
import type { DndTargetState } from 'features/dnd/types';
1112
import { selectAutoAddBoardId } from 'features/gallery/store/gallerySelectors';
12-
import { selectMaxImageUploadCount } from 'features/system/store/configSlice';
1313
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';
1515
import { useTranslation } from 'react-i18next';
1616
import { uploadImages } from 'services/api/endpoints/images';
1717
import { useBoardName } from 'services/api/hooks/useBoardName';
@@ -20,6 +20,7 @@ import { z } from 'zod';
2020

2121
const ACCEPTED_IMAGE_TYPES = ['image/png', 'image/jpg', 'image/jpeg'];
2222
const ACCEPTED_FILE_EXTENSIONS = ['.png', '.jpg', '.jpeg'];
23+
const log = logger('paste');
2324

2425
// const MAX_IMAGE_SIZE = 4; //In MegaBytes
2526
// const sizeInMB = (sizeInBytes: number, decimalsNum = 2) => {
@@ -66,17 +67,18 @@ const sx = {
6667
},
6768
} satisfies SystemStyleObject;
6869

70+
const maxImageUploadCount = undefined;
71+
6972
export const FullscreenDropzone = memo(() => {
7073
const { t } = useTranslation();
7174
const ref = useRef<HTMLDivElement>(null);
72-
const maxImageUploadCount = useAppSelector(selectMaxImageUploadCount);
73-
const [dndState, setDndState] = useState<DndTargetState>('idle');
7475

75-
const uploadFilesSchema = useMemo(() => getFilesSchema(maxImageUploadCount), [maxImageUploadCount]);
76+
const [dndState, setDndState] = useState<DndTargetState>('idle');
7677

7778
const validateAndUploadFiles = useCallback(
7879
(files: File[]) => {
7980
const { getState } = getStore();
81+
const uploadFilesSchema = getFilesSchema(maxImageUploadCount);
8082
const parseResult = uploadFilesSchema.safeParse(files);
8183

8284
if (!parseResult.success) {
@@ -105,7 +107,7 @@ export const FullscreenDropzone = memo(() => {
105107

106108
uploadImages(uploadArgs);
107109
},
108-
[maxImageUploadCount, t, uploadFilesSchema]
110+
[maxImageUploadCount, t]
109111
);
110112

111113
useEffect(() => {
@@ -144,24 +146,59 @@ export const FullscreenDropzone = memo(() => {
144146
}, [validateAndUploadFiles]);
145147

146148
useEffect(() => {
149+
log.info('use effect');
147150
const controller = new AbortController();
148151

149152
window.addEventListener(
150153
'paste',
151154
(e) => {
155+
log.info('event listener');
156+
log.info(JSON.stringify(e.clipboardData));
152157
if (!e.clipboardData?.files) {
158+
log.info('no files');
153159
return;
154160
}
155161
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);
157193
},
158194
{ signal: controller.signal }
159195
);
160196

161197
return () => {
198+
log.info('aborted');
162199
controller.abort();
163200
};
164-
}, [validateAndUploadFiles]);
201+
}, []);
165202

166203
return (
167204
<Box ref={ref} data-dnd-state={dndState} sx={sx}>

0 commit comments

Comments
 (0)