From 0807c4ce3909bbe38b68e57c325cea8a9d07b62f Mon Sep 17 00:00:00 2001 From: Daria Mikhailova Date: Thu, 30 May 2024 11:36:34 +1000 Subject: [PATCH] spinner when switching map src --- src/client/components/OfficeFloorMap.tsx | 11 ++++++++--- src/client/components/ui/ImageWithPanZoom.tsx | 8 +++++++- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/client/components/OfficeFloorMap.tsx b/src/client/components/OfficeFloorMap.tsx index 7131dd54..03698c4f 100644 --- a/src/client/components/OfficeFloorMap.tsx +++ b/src/client/components/OfficeFloorMap.tsx @@ -1,5 +1,5 @@ -import React, { MouseEventHandler, useState } from 'react' -import { Avatar, Button, P } from '#client/components/ui' +import React, { MouseEventHandler, useEffect, useState } from 'react' +import { Avatar, Button, LoaderSpinner, P } from '#client/components/ui' import { OfficeArea, OfficeAreaDesk, @@ -105,6 +105,10 @@ export const OfficeFloorMap: React.FC = ({ onToggle, }) => { const [isMapLoaded, setIsMapLoaded] = useState(false) + const maprSrc = React.useMemo(() => { + !panZoom && setIsMapLoaded(false) + return area.map + }, [area]) const me = useStore(stores.me) const initialStartPosition = selectedPointId ? mappablePoints?.find( @@ -205,8 +209,9 @@ export const OfficeFloorMap: React.FC = ({ return (
+ {!isMapLoaded && } {`${area.name} setIsMapLoaded(true)} diff --git a/src/client/components/ui/ImageWithPanZoom.tsx b/src/client/components/ui/ImageWithPanZoom.tsx index 9ef04715..850884cf 100644 --- a/src/client/components/ui/ImageWithPanZoom.tsx +++ b/src/client/components/ui/ImageWithPanZoom.tsx @@ -2,6 +2,7 @@ import React, { useEffect, useRef, useState } from 'react' import { cn } from '#client/utils' //@ts-ignore import { PanZoom, OnStateChangeData } from 'react-easy-panzoom' +import { LoaderSpinner } from './Loader' type ImageWithPanZoomProps = { src: string @@ -22,6 +23,10 @@ export const ImageWithPanZoom = ({ }: ImageWithPanZoomProps) => { const [imgScale, setImgScale] = useState(1) const [isMapLoaded, setIsMapLoaded] = useState(false) + const maprSrc = React.useMemo(() => { + setIsMapLoaded(false) + return src + }, [src]) const containerRef = useRef(null) const imageRef = useRef(null) const panZoomRef = useRef(null) @@ -49,6 +54,7 @@ export const ImageWithPanZoom = ({ containerClassName )} > + {!isMapLoaded && }