diff --git a/frontend/src/app/store.ts b/frontend/src/app/store.ts index 0ee14ed56f..d37da505cb 100644 --- a/frontend/src/app/store.ts +++ b/frontend/src/app/store.ts @@ -59,6 +59,7 @@ const galleryPersistConfig = { key: 'gallery', storage, whitelist: [ + 'galleryWidth', 'shouldPinGallery', 'shouldShowGallery', 'galleryScrollPosition', diff --git a/frontend/src/features/gallery/ImageGallery.scss b/frontend/src/features/gallery/ImageGallery.scss index 0930a81169..f737e47a2d 100644 --- a/frontend/src/features/gallery/ImageGallery.scss +++ b/frontend/src/features/gallery/ImageGallery.scss @@ -52,9 +52,15 @@ .image-gallery-header { display: flex; - justify-content: end; align-items: center; column-gap: 0.5rem; + justify-content: space-between; + + div { + display: flex; + column-gap: 0.5rem; + column-gap: 0.5rem; + } .image-gallery-icon-btn { background-color: var(--btn-load-more) !important; diff --git a/frontend/src/features/gallery/ImageGallery.tsx b/frontend/src/features/gallery/ImageGallery.tsx index 1b430659d8..0e0556bf50 100644 --- a/frontend/src/features/gallery/ImageGallery.tsx +++ b/frontend/src/features/gallery/ImageGallery.tsx @@ -15,6 +15,7 @@ import { setGalleryImageMinimumWidth, setGalleryImageObjectFit, setGalleryScrollPosition, + setGalleryWidth, setShouldAutoSwitchToNewImages, setShouldHoldGalleryOpen, setShouldPinGallery, @@ -33,6 +34,8 @@ import IAICheckbox from '../../common/components/IAICheckbox'; import { setNeedsCache } from '../tabs/Inpainting/inpaintingSlice'; import _ from 'lodash'; +const GALLERY_SHOW_BUTTONS_MIN_WIDTH = 320; + export default function ImageGallery() { const dispatch = useAppDispatch(); const toast = useToast(); @@ -51,71 +54,39 @@ export default function ImageGallery() { shouldHoldGalleryOpen, shouldAutoSwitchToNewImages, areMoreImagesAvailable, + galleryWidth, } = useAppSelector(imageGallerySelector); - const [gallerySize, setGallerySize] = useState({ - width: '300', - height: '100%', - }); + const [galleryMinWidth, setGalleryMinWidth] = useState(300); + const [galleryMaxWidth, setGalleryMaxWidth] = useState(590); - const [galleryMaxSize, setGalleryMaxSize] = useState({ - width: '590', // keep max at 590 for any tab - height: '100%', - }); - - const [galleryMinSize, setGalleryMinSize] = useState({ - width: '300', // keep max at 590 for any tab - height: '100%', - }); - - console.log(gallerySize, galleryMaxSize, galleryMinSize); + const [shouldShowButtons, setShouldShowButtons] = useState( + galleryWidth >= GALLERY_SHOW_BUTTONS_MIN_WIDTH + ); useEffect(() => { - if (activeTabName === 'inpainting' && shouldPinGallery) { - setGalleryMinSize((prevSize) => { - return { ...prevSize, width: 220 }; - }); - setGalleryMaxSize((prevSize) => { - return { ...prevSize, width: 220 }; - }); - setGallerySize((prevSize) => { - return { - ...prevSize, - width: Math.min(Math.max(Number(prevSize.width), 0), 220), - }; - }); - } else if (activeTabName === 'img2img' && shouldPinGallery) { - setGalleryMaxSize((prevSize) => { - return { ...prevSize, width: 490, height: '100%' }; - }); - setGallerySize((prevSize) => { - return { - ...prevSize, - width: Math.min(Math.max(Number(prevSize.width), 0), 490), - }; - }); + if (!shouldPinGallery) return; + + if (activeTabName === 'inpainting') { + dispatch(setGalleryWidth(220)); + setGalleryMinWidth(220); + setGalleryMaxWidth(220); + } else if (activeTabName === 'img2img') { + dispatch( + setGalleryWidth(Math.min(Math.max(Number(galleryWidth), 0), 490)) + ); + setGalleryMaxWidth(490); } else { - setGalleryMaxSize((prevSize) => { - return { ...prevSize, width: 590, height: '100%' }; - }); - setGallerySize((prevSize) => { - return { - ...prevSize, - width: Math.min(Math.max(Number(prevSize.width), 0), 590), - }; - }); + dispatch( + setGalleryWidth(Math.min(Math.max(Number(galleryWidth), 0), 590)) + ); + setGalleryMaxWidth(590); } - }, [activeTabName, shouldPinGallery]); + }, [dispatch, activeTabName, shouldPinGallery, galleryWidth]); useEffect(() => { if (!shouldPinGallery) { - setGalleryMaxSize((prevSize) => { - // calculate vh in px - return { - ...prevSize, - width: window.innerWidth, - }; - }); + setGalleryMaxWidth(window.innerWidth); } }, [shouldPinGallery]); @@ -126,10 +97,6 @@ export default function ImageGallery() { const handleSetShouldPinGallery = () => { dispatch(setNeedsCache(true)); dispatch(setShouldPinGallery(!shouldPinGallery)); - setGallerySize({ - ...gallerySize, - height: shouldPinGallery ? '100vh' : '100%', - }); }; const handleToggleGallery = () => { @@ -300,9 +267,9 @@ export default function ImageGallery() { onMouseOver={!shouldPinGallery ? cancelCloseGalleryTimer : undefined} > { - setGallerySize({ - width: _.clamp(Number(gallerySize.width) + delta.width, 0, Number(galleryMaxSize.width)), - height: '100%', - }); + dispatch( + setGalleryWidth( + _.clamp( + Number(galleryWidth) + delta.width, + 0, + Number(galleryMaxWidth) + ) + ) + ); elementRef.removeAttribute('data-resize-alert'); }} onResize={( @@ -335,18 +310,21 @@ export default function ImageGallery() { delta: NumberSize ) => { const newWidth = _.clamp( - Number(gallerySize.width) + delta.width, + Number(galleryWidth) + delta.width, 0, - Number(galleryMaxSize.width) + Number(galleryMaxWidth) ); - if (newWidth >= galleryMaxSize.width) { + + if (newWidth >= 320 && !shouldShowButtons) { + setShouldShowButtons(true); + } else if (newWidth < 320 && shouldShowButtons) { + setShouldShowButtons(false); + } + + if (newWidth >= galleryMaxWidth) { elementRef.setAttribute('data-resize-alert', 'true'); } else { elementRef.removeAttribute('data-resize-alert'); - setGallerySize({ - width: newWidth, - height: '100%', - }); } }} > @@ -358,7 +336,7 @@ export default function ImageGallery() { variant="solid" className="image-gallery-category-btn-group" > - {gallerySize.width > 320 ? ( + {shouldShowButtons ? ( <>