this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Don't debounce if loading subsequent posts

+25 -25
+25 -25
src/pages/home.jsx
··· 119 119 } 120 120 121 121 const loadingStatuses = useRef(false); 122 - const loadStatuses = useDebouncedCallback( 123 - (firstLoad) => { 124 - if (loadingStatuses.current) return; 125 - loadingStatuses.current = true; 126 - setUIState('loading'); 127 - (async () => { 128 - try { 129 - const { done } = await fetchStatuses(firstLoad); 130 - setShowMore(!done); 131 - setUIState('default'); 132 - } catch (e) { 133 - console.warn(e); 134 - setUIState('error'); 135 - } finally { 136 - loadingStatuses.current = false; 137 - } 138 - })(); 139 - }, 140 - 3000, 141 - { leading: true, trailing: false }, 142 - ); 122 + const loadStatuses = (firstLoad) => { 123 + if (loadingStatuses.current) return; 124 + loadingStatuses.current = true; 125 + setUIState('loading'); 126 + (async () => { 127 + try { 128 + const { done } = await fetchStatuses(firstLoad); 129 + setShowMore(!done); 130 + setUIState('default'); 131 + } catch (e) { 132 + console.warn(e); 133 + setUIState('error'); 134 + } finally { 135 + loadingStatuses.current = false; 136 + } 137 + })(); 138 + }; 139 + const debouncedLoadStatuses = useDebouncedCallback(loadStatuses, 3000, { 140 + leading: true, 141 + trailing: false, 142 + }); 143 143 144 144 useEffect(() => { 145 145 loadStatuses(true); ··· 284 284 285 285 useEffect(() => { 286 286 if (reachStart) { 287 - loadStatuses(true); 287 + debouncedLoadStatuses(true); 288 288 } 289 289 }, [reachStart]); 290 290 ··· 324 324 scrollableRef.current?.scrollTo({ top: 0, behavior: 'smooth' }); 325 325 }} 326 326 onDblClick={() => { 327 - loadStatuses(true); 327 + debouncedLoadStatuses(true); 328 328 }} 329 329 > 330 330 <div class="header-side"> ··· 372 372 ); 373 373 states.home.unshift(...uniqueHomeNew); 374 374 } 375 - loadStatuses(true); 375 + debouncedLoadStatuses(true); 376 376 states.homeNew = []; 377 377 378 378 scrollableRef.current?.scrollTo({ ··· 443 443 <button 444 444 type="button" 445 445 onClick={() => { 446 - loadStatuses(true); 446 + debouncedLoadStatuses(true); 447 447 }} 448 448 > 449 449 Try again