import { createSelector } from '@reduxjs/toolkit'; import { useAppDispatch, useAppSelector } from 'app/store/storeHooks'; import IAIIconButton from 'common/components/IAIIconButton'; import { useTranslation } from 'react-i18next'; import { requestCanvasRescale } from 'features/canvas/store/thunks/requestCanvasScale'; import { setShouldShowGallery } from 'features/ui/store/uiSlice'; import { isEqual } from 'lodash-es'; import { MdPhotoLibrary } from 'react-icons/md'; import { activeTabNameSelector, uiSelector } from '../store/uiSelectors'; import { memo } from 'react'; const floatingGalleryButtonSelector = createSelector( [activeTabNameSelector, uiSelector], (activeTabName, ui) => { const { shouldPinGallery, shouldShowGallery } = ui; return { shouldPinGallery, shouldShowGalleryButton: !shouldShowGallery, }; }, { memoizeOptions: { resultEqualityCheck: isEqual } } ); const FloatingGalleryButton = () => { const { t } = useTranslation(); const { shouldPinGallery, shouldShowGalleryButton } = useAppSelector( floatingGalleryButtonSelector ); const dispatch = useAppDispatch(); const handleShowGallery = () => { dispatch(setShouldShowGallery(true)); shouldPinGallery && dispatch(requestCanvasRescale()); }; return shouldShowGalleryButton ? ( ) : null; }; export default memo(FloatingGalleryButton);