import type { IconButtonProps, SystemStyleObject } from '@invoke-ai/ui-library'; import { IconButton } from '@invoke-ai/ui-library'; import { logger } from 'app/logging/logger'; import { useAppSelector } from 'app/store/storeHooks'; import { selectAutoAddBoardId } from 'features/gallery/store/gallerySelectors'; import { selectMaxImageUploadCount } from 'features/system/store/configSlice'; import { toast } from 'features/toast/toast'; import { useCallback } from 'react'; import type { FileRejection } from 'react-dropzone'; import { useDropzone } from 'react-dropzone'; import { useTranslation } from 'react-i18next'; import { PiUploadBold } from 'react-icons/pi'; import { uploadImages, useUploadImageMutation } from 'services/api/endpoints/images'; import type { ImageDTO } from 'services/api/types'; import { assert } from 'tsafe'; import type { SetOptional } from 'type-fest'; type UseImageUploadButtonArgs = | { isDisabled?: boolean; allowMultiple: false; onUpload?: (imageDTO: ImageDTO) => void; } | { isDisabled?: boolean; allowMultiple: true; onUpload?: (imageDTOs: ImageDTO[]) => void; }; const log = logger('gallery'); /** * Provides image uploader functionality to any component. * * @example * const { getUploadButtonProps, getUploadInputProps, openUploader } = useImageUploadButton({ * postUploadAction: { * type: 'SET_CONTROL_ADAPTER_IMAGE', * controlNetId: '12345', * }, * isDisabled: getIsUploadDisabled(), * }); * * // open the uploaded directly * const handleSomething = () => { openUploader() } * * // in the render function *