diff --git a/apps/frontend/src/app/gallery/components/GallerySlide/CompareSlider/CompareSlider.module.css b/apps/frontend/src/app/gallery/components/GallerySlide/CompareSlider/CompareSlider.module.css index 2fb1aafb..27d7a838 100644 --- a/apps/frontend/src/app/gallery/components/GallerySlide/CompareSlider/CompareSlider.module.css +++ b/apps/frontend/src/app/gallery/components/GallerySlide/CompareSlider/CompareSlider.module.css @@ -2,6 +2,18 @@ position: relative; } +.loading { + position: absolute; + left: 0; + top: 0; + z-index: 1000; + width: 100%; + height: 100%; + pointer-events: none; + user-select: none; + background-color: var(--gray-a4); +} + .root img { height: auto !important; } diff --git a/apps/frontend/src/app/gallery/components/GallerySlide/CompareSlider/CompareSlider.tsx b/apps/frontend/src/app/gallery/components/GallerySlide/CompareSlider/CompareSlider.tsx index 599a7814..82b34bd9 100644 --- a/apps/frontend/src/app/gallery/components/GallerySlide/CompareSlider/CompareSlider.tsx +++ b/apps/frontend/src/app/gallery/components/GallerySlide/CompareSlider/CompareSlider.tsx @@ -8,30 +8,20 @@ import { import { clsx } from 'clsx' import { DragHandle } from './DragHandle' -import { getRandomNumber } from '@helpers/getRandomNumber' import styles from './CompareSlider.module.css' +type Orientation = 'landscape' | 'portrait' + interface Props { - index: number label: string beforeSrc: string afterSrc: string - orientation?: 'landscape' | 'portrait' + orientation?: Orientation } const totalImages = 2 -const getRandomPosition = (index: number): number => { - /* - * Make the default position values for "handle" random for a more interesting UI. - */ - const isEven = index % 2 === 0 - const range: [number, number] = isEven ? [40, 60] : [30, 50] - - return getRandomNumber(...range) -} - -const getImageFallback = ({ orientation }: Pick): string => { +const getImageFallback = (orientation?: Orientation): string => { const landscapeFallback = '/slide-landscape-fallback.jpeg' const portraitFallback = '/slide-portrait-fallback.jpeg' @@ -42,13 +32,16 @@ const getImageFallback = ({ orientation }: Pick): string = return portraitFallback } -export const CompareSlider = ({ index, label, beforeSrc, afterSrc, orientation }: Props) => { +export const CompareSlider = ({ label, beforeSrc, afterSrc, orientation }: Props) => { + const sliderRef = useReactCompareSliderRef() + const imageFallback = getImageFallback(orientation) + /* + * TODO: Issue is resolved. Refactor * Prevent scrolling to element when clicking on the handle container. * https://github.com/nerdyman/react-compare-slider/blob/main/lib/src/ReactCompareSlider.tsx#L192-L195 * https://github.com/nerdyman/react-compare-slider/issues/128 */ - const sliderRef = useReactCompareSliderRef() useEffect(() => { const rootContainer = sliderRef.current.rootContainer if (!rootContainer) return @@ -100,31 +93,35 @@ export const CompareSlider = ({ index, label, beforeSrc, afterSrc, orientation } } return ( - : null} - itemOne={ - - } - itemTwo={ - - } - portrait={isPortrait} - className={clsx(styles.root, isPortrait ? styles.portrait : styles.landscape)} - /> + <> + {loaded < totalImages && errors.length === 0 &&
} + + } + itemOne={ + + } + itemTwo={ + + } + portrait={isPortrait} + className={clsx(styles.root, isPortrait ? styles.portrait : styles.landscape)} + /> + ) } diff --git a/apps/frontend/src/app/gallery/components/GallerySlide/CompareSlider/DragHandle/DragHandle.module.css b/apps/frontend/src/app/gallery/components/GallerySlide/CompareSlider/DragHandle/DragHandle.module.css index 4c614cdd..913d7b17 100644 --- a/apps/frontend/src/app/gallery/components/GallerySlide/CompareSlider/DragHandle/DragHandle.module.css +++ b/apps/frontend/src/app/gallery/components/GallerySlide/CompareSlider/DragHandle/DragHandle.module.css @@ -26,7 +26,6 @@ .gutter { background-color: var(--color-background); - box-shadow: 0 0 4px rgba(0 0 0 / 0.5); } .gutterThumb { diff --git a/apps/frontend/src/app/gallery/components/GallerySlide/CompareSlider/DragHandle/DragHandle.tsx b/apps/frontend/src/app/gallery/components/GallerySlide/CompareSlider/DragHandle/DragHandle.tsx index 756616af..9ea6db02 100644 --- a/apps/frontend/src/app/gallery/components/GallerySlide/CompareSlider/DragHandle/DragHandle.tsx +++ b/apps/frontend/src/app/gallery/components/GallerySlide/CompareSlider/DragHandle/DragHandle.tsx @@ -20,9 +20,11 @@ export const DragHandle = memo(({ isPortrait }: Props) => ( className={clsx(styles.root, isPortrait ? styles.portrait : styles.landscape)} > + + )) diff --git a/apps/frontend/src/app/gallery/components/GallerySlide/GallerySlide.tsx b/apps/frontend/src/app/gallery/components/GallerySlide/GallerySlide.tsx index b551fb65..5a6bbcd0 100644 --- a/apps/frontend/src/app/gallery/components/GallerySlide/GallerySlide.tsx +++ b/apps/frontend/src/app/gallery/components/GallerySlide/GallerySlide.tsx @@ -46,7 +46,6 @@ const GallerySlide = ({ >