From 62a3ba7c5f716b0174aafd35e8658128e2f06c53 Mon Sep 17 00:00:00 2001 From: Lim Chee Aun Date: Mon, 16 Jan 2023 20:32:30 +0800 Subject: [PATCH] Bug fixes for boosts carousel + scrolling --- src/pages/home.jsx | 70 ++++++++++++++++++++++++------------------ src/pages/status.jsx | 2 +- src/utils/states.js | 2 +- src/utils/useScroll.js | 20 ++++++------ 4 files changed, 53 insertions(+), 41 deletions(-) diff --git a/src/pages/home.jsx b/src/pages/home.jsx index bee401fb..ff264e26 100644 --- a/src/pages/home.jsx +++ b/src/pages/home.jsx @@ -48,8 +48,8 @@ function Home({ hidden }) { }; }); - { - // BOOSTS CAROUSEL + // BOOSTS CAROUSEL + if (snapStates.settings.boostsCarousel) { let specialHome = []; let boostStash = []; for (let i = 0; i < homeValues.length; i++) { @@ -90,19 +90,22 @@ function Home({ hidden }) { specialHome, }); if (firstLoad) { - states.specialHome = specialHome; + states.home = specialHome; } else { - states.specialHome.push(...specialHome); + states.home.push(...specialHome); + } + } else { + if (firstLoad) { + states.home = homeValues; + } else { + states.home.push(...homeValues); } } - if (firstLoad) { - states.home = homeValues; - } else { - states.home.push(...homeValues); - } states.homeLastFetchTime = Date.now(); - return allStatuses; + return { + done: false, + }; } const loadingStatuses = useRef(false); @@ -212,19 +215,24 @@ function Home({ hidden }) { } }); - const { scrollDirection, reachStart, nearReachStart, nearReachEnd } = - useScroll({ - scrollableElement: scrollableRef.current, - distanceFromStart: 0.1, - distanceFromEnd: 0.15, - scrollThresholdStart: 44, - }); + const { + scrollDirection, + reachStart, + nearReachStart, + nearReachEnd, + reachEnd, + } = useScroll({ + scrollableElement: scrollableRef.current, + distanceFromStart: 1, + distanceFromEnd: 3, + scrollThresholdStart: 44, + }); useEffect(() => { - if (nearReachEnd && showMore) { + if (nearReachEnd || (reachEnd && showMore)) { loadStatuses(); } - }, [nearReachEnd]); + }, [nearReachEnd, reachEnd]); useEffect(() => { if (reachStart) { @@ -245,10 +253,6 @@ function Home({ hidden }) { })(); }, []); - const snapHome = snapStates.settings.boostsCarousel - ? snapStates.specialHome - : snapStates.home; - return (