@@ -12,6 +12,8 @@ import type { FC } from 'react';
12
12
13
13
import 'photoswipe/style.css' ;
14
14
15
+ import useScrollDown from './hooks/useScrollDown' ;
16
+
15
17
interface Props {
16
18
images : GalleryImage [ ] ;
17
19
}
@@ -30,6 +32,8 @@ const Gallery: FC<Props> = ({ images }) => {
30
32
const [ page , setPage ] = useState < number > ( INITIAL_PAGE ) ;
31
33
const observerTarget = useRef ( null ) ;
32
34
35
+ const isScrollingDown = useScrollDown ( ) ;
36
+
33
37
const [ loadedStates , setLoadedStates ] = useState < LoadedStates > ( { } ) ;
34
38
35
39
// calculate if new page is loaded on scroll
@@ -41,6 +45,8 @@ const Gallery: FC<Props> = ({ images }) => {
41
45
42
46
const isEnd = loadedImages . length === images . length ;
43
47
48
+ const shouldShowLoader = isScrollingDown && ! isEnd && ! isLoadingPageImages ;
49
+
44
50
// converts page to loaded images
45
51
useEffect ( ( ) => {
46
52
const upToPageImages = fetchImagesUpToPage ( images , page ) ;
@@ -121,15 +127,15 @@ const Gallery: FC<Props> = ({ images }) => {
121
127
122
128
< div
123
129
className = { cn (
124
- 'flex items-center justify-center transition-all duration-300 ease-in-out' ,
125
- isLoadingPageImages ? 'min-h-32 ' : 'min-h-0'
130
+ 'flex items-center justify-center transition-all duration-500 ease-in-out' ,
131
+ shouldShowLoader ? 'min-h-48 ' : 'min-h-0'
126
132
) }
127
133
>
128
- { isLoadingPageImages && < PiSpinnerGapBold className = "size-12 animate-spin mt-4" /> }
134
+ { shouldShowLoader && < PiSpinnerGapBold className = "size-10 sm: size-12 animate-spin mt-4" /> }
129
135
</ div >
130
136
131
137
{ /* control threshold with margin-top */ }
132
- < div ref = { observerTarget } className = "mt-0" > </ div >
138
+ < div ref = { observerTarget } className = "mt-0" / >
133
139
</ >
134
140
) ;
135
141
} ;
0 commit comments