mirror of
https://github.com/invoke-ai/InvokeAI
synced 2024-08-30 20:32:17 +00:00
fix(ui): fix IAISelectableImage fallback
This commit is contained in:
parent
3b9426eb72
commit
b1e1e3efc7
@ -4,13 +4,13 @@ import {
|
|||||||
Icon,
|
Icon,
|
||||||
IconButtonProps,
|
IconButtonProps,
|
||||||
Image,
|
Image,
|
||||||
|
Spinner,
|
||||||
Text,
|
Text,
|
||||||
} from '@chakra-ui/react';
|
} from '@chakra-ui/react';
|
||||||
import { useDroppable } from '@dnd-kit/core';
|
import { useDroppable } from '@dnd-kit/core';
|
||||||
import IAIIconButton from 'common/components/IAIIconButton';
|
import IAIIconButton from 'common/components/IAIIconButton';
|
||||||
import ImageMetadataOverlay from 'common/components/ImageMetadataOverlay';
|
import ImageMetadataOverlay from 'common/components/ImageMetadataOverlay';
|
||||||
import { useGetUrl } from 'common/util/getUrl';
|
import { useGetUrl } from 'common/util/getUrl';
|
||||||
import ImageFallbackSpinner from 'features/gallery/components/ImageFallbackSpinner';
|
|
||||||
import { AnimatePresence, motion } from 'framer-motion';
|
import { AnimatePresence, motion } from 'framer-motion';
|
||||||
import { SyntheticEvent } from 'react';
|
import { SyntheticEvent } from 'react';
|
||||||
import { memo, useRef } from 'react';
|
import { memo, useRef } from 'react';
|
||||||
@ -18,6 +18,8 @@ import { FaImage, FaUndo } from 'react-icons/fa';
|
|||||||
import { ImageDTO } from 'services/api';
|
import { ImageDTO } from 'services/api';
|
||||||
import { v4 as uuidv4 } from 'uuid';
|
import { v4 as uuidv4 } from 'uuid';
|
||||||
|
|
||||||
|
const PLACEHOLDER_MIN_HEIGHT = 48;
|
||||||
|
|
||||||
type IAISelectableImageProps = {
|
type IAISelectableImageProps = {
|
||||||
image: ImageDTO | null | undefined;
|
image: ImageDTO | null | undefined;
|
||||||
onChange: (image: ImageDTO) => void;
|
onChange: (image: ImageDTO) => void;
|
||||||
@ -49,17 +51,42 @@ const IAISelectableImage = (props: IAISelectableImageProps) => {
|
|||||||
ref={setNodeRef}
|
ref={setNodeRef}
|
||||||
>
|
>
|
||||||
{image && (
|
{image && (
|
||||||
<Flex sx={{ position: 'relative' }}>
|
<Flex
|
||||||
|
sx={{
|
||||||
|
position: 'relative',
|
||||||
|
w: 'full',
|
||||||
|
h: 'full',
|
||||||
|
alignItems: 'center',
|
||||||
|
justifyContent: 'center',
|
||||||
|
}}
|
||||||
|
>
|
||||||
<Image
|
<Image
|
||||||
src={getUrl(image.image_url)}
|
src={getUrl(image.image_url)}
|
||||||
fallbackStrategy="beforeLoadOrError"
|
fallbackStrategy="beforeLoadOrError"
|
||||||
fallback={<ImageFallbackSpinner />}
|
fallback={<ImageFallback />}
|
||||||
onError={onError}
|
onError={onError}
|
||||||
sx={{
|
sx={{
|
||||||
borderRadius: 'base',
|
borderRadius: 'base',
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<ImageMetadataOverlay image={image} />
|
<ImageMetadataOverlay image={image} />
|
||||||
|
{onReset && (
|
||||||
|
<Box
|
||||||
|
sx={{
|
||||||
|
position: 'absolute',
|
||||||
|
top: 0,
|
||||||
|
right: 0,
|
||||||
|
p: 2,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<IAIIconButton
|
||||||
|
size={resetIconSize}
|
||||||
|
aria-label="Reset Image"
|
||||||
|
icon={<FaUndo />}
|
||||||
|
onClick={onReset}
|
||||||
|
/>
|
||||||
|
</Box>
|
||||||
|
)}
|
||||||
<AnimatePresence>
|
<AnimatePresence>
|
||||||
{active && <DropOverlay isOver={isOver} />}
|
{active && <DropOverlay isOver={isOver} />}
|
||||||
</AnimatePresence>
|
</AnimatePresence>
|
||||||
@ -69,7 +96,7 @@ const IAISelectableImage = (props: IAISelectableImageProps) => {
|
|||||||
<>
|
<>
|
||||||
<Flex
|
<Flex
|
||||||
sx={{
|
sx={{
|
||||||
p: 8,
|
minH: PLACEHOLDER_MIN_HEIGHT,
|
||||||
bg: 'base.850',
|
bg: 'base.850',
|
||||||
w: 'full',
|
w: 'full',
|
||||||
h: 'full',
|
h: 'full',
|
||||||
@ -91,23 +118,6 @@ const IAISelectableImage = (props: IAISelectableImageProps) => {
|
|||||||
</AnimatePresence>
|
</AnimatePresence>
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
{image && onReset && (
|
|
||||||
<Box
|
|
||||||
sx={{
|
|
||||||
position: 'absolute',
|
|
||||||
top: 0,
|
|
||||||
right: 0,
|
|
||||||
p: 2,
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<IAIIconButton
|
|
||||||
size={resetIconSize}
|
|
||||||
aria-label="Reset Image"
|
|
||||||
icon={<FaUndo />}
|
|
||||||
onClick={onReset}
|
|
||||||
/>
|
|
||||||
</Box>
|
|
||||||
)}
|
|
||||||
</Flex>
|
</Flex>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
@ -198,3 +208,20 @@ const DropOverlay = (props: DropOverlayProps) => {
|
|||||||
</motion.div>
|
</motion.div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const ImageFallback = () => (
|
||||||
|
<Flex
|
||||||
|
sx={{
|
||||||
|
w: 'full',
|
||||||
|
h: 'full',
|
||||||
|
alignItems: 'center',
|
||||||
|
justifyContent: 'center',
|
||||||
|
minH: PLACEHOLDER_MIN_HEIGHT,
|
||||||
|
color: 'base.400',
|
||||||
|
bg: 'base.850',
|
||||||
|
borderRadius: 'base',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Spinner size="xl" />
|
||||||
|
</Flex>
|
||||||
|
);
|
||||||
|
@ -14,6 +14,7 @@ const ImageFallbackSpinner = (props: ImageFallbackSpinnerProps) => {
|
|||||||
justifyContent: 'center',
|
justifyContent: 'center',
|
||||||
position: 'absolute',
|
position: 'absolute',
|
||||||
color: 'base.400',
|
color: 'base.400',
|
||||||
|
minH: 40,
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Spinner size={size} {...rest} />
|
<Spinner size={size} {...rest} />
|
||||||
|
Loading…
x
Reference in New Issue
Block a user