mirror of
https://github.com/Qortal/qapp-core.git
synced 2025-06-14 17:41:20 +00:00
fix loader display
This commit is contained in:
parent
9eb467ad72
commit
f2a30ac9ad
@ -1,14 +1,14 @@
|
|||||||
import { CircularProgress } from '@mui/material';
|
import { CircularProgress } from '@mui/material';
|
||||||
import React, { useEffect, useRef } from 'react'
|
import React, { useEffect, useRef, useState } from 'react'
|
||||||
import { useInView } from 'react-intersection-observer'
|
import { useInView } from 'react-intersection-observer'
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
onLoadMore: () => void
|
onLoadMore: () => Promise<void>
|
||||||
}
|
}
|
||||||
|
|
||||||
const LazyLoad: React.FC<Props> = ({ onLoadMore }) => {
|
const LazyLoad: React.FC<Props> = ({ onLoadMore }) => {
|
||||||
const hasTriggeredRef = useRef(false); // Prevents multiple auto-triggers
|
const hasTriggeredRef = useRef(false); // Prevents multiple auto-triggers
|
||||||
|
const [isLoading, setIsLoading] = useState(false)
|
||||||
const [ref, inView] = useInView({
|
const [ref, inView] = useInView({
|
||||||
threshold: 0.7,
|
threshold: 0.7,
|
||||||
triggerOnce: false, // Allows multiple triggers, but we control when
|
triggerOnce: false, // Allows multiple triggers, but we control when
|
||||||
@ -17,7 +17,10 @@ const LazyLoad: React.FC<Props> = ({ onLoadMore }) => {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (inView && !hasTriggeredRef.current) {
|
if (inView && !hasTriggeredRef.current) {
|
||||||
hasTriggeredRef.current = true; // Set flag so it doesn’t trigger again immediately
|
hasTriggeredRef.current = true; // Set flag so it doesn’t trigger again immediately
|
||||||
onLoadMore();
|
setIsLoading(true)
|
||||||
|
onLoadMore().finally(()=> {
|
||||||
|
setIsLoading(false)
|
||||||
|
});
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
hasTriggeredRef.current = false; // Reset trigger after a short delay
|
hasTriggeredRef.current = false; // Reset trigger after a short delay
|
||||||
}, 1000);
|
}, 1000);
|
||||||
@ -33,7 +36,7 @@ const LazyLoad: React.FC<Props> = ({ onLoadMore }) => {
|
|||||||
height: '50px',
|
height: '50px',
|
||||||
overflow: 'hidden'
|
overflow: 'hidden'
|
||||||
}}
|
}}
|
||||||
><CircularProgress /></div>
|
>{isLoading &&<CircularProgress />}</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user