Skip to content

Commit

Permalink
Merge pull request #357
Browse files Browse the repository at this point in the history
Bug fix for feed scrolling
  • Loading branch information
Aymanhki authored Mar 30, 2024
2 parents 589e2e8 + 2560db5 commit 4e0d451
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions epoch_frontend/src/modules/Feed.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ export default function Feed({
const [allowScrollToTop, setAllowScrollToTop] = useState(false);
const [noMoreTopPosts, setNoMoreTopPosts] = useState(false);
const [offset, setOffset] = useState(0);
const limit = 20; // must be bigger than toRemove and smaller than maxPosts
const limit = 20; // must be bigger than toRemove
const maxPosts = 25;
const toRemove = 15; // Must be smaller than limit and maxPosts
const toRemove = 15; // Must be smaller than limit
const [previousPosts, setPreviousPosts] = useState([]);
const bottomElementRef = useRef(null);
const [ref, inView] = useInView({threshold: 0.1, });
Expand Down Expand Up @@ -104,16 +104,19 @@ export default function Feed({
{
let finalToSetFeedPosts = finalFeedPosts;

// if(finalToSetFeedPosts.length > maxPosts)
// {
// setPreviousPosts(previousPosts.concat(finalFeedPosts.slice(toRemove + (limit - toRemove))));
// finalToSetFeedPosts = finalToSetFeedPosts.slice(toRemove + (limit - toRemove));
// }
// else
// {


if (finalFeedPosts.length - toRemove > maxPosts)
{
setPreviousPosts(previousPosts.concat(finalFeedPosts.slice(0, toRemove + (maxPosts - toRemove))));
finalToSetFeedPosts = finalToSetFeedPosts.slice( toRemove + (maxPosts - toRemove));
}
else
{
setPreviousPosts(previousPosts.concat(finalFeedPosts.slice(0, toRemove)));
finalToSetFeedPosts = finalToSetFeedPosts.slice(0, toRemove);
// }
finalToSetFeedPosts = finalToSetFeedPosts.slice(toRemove);
}

finalToSetFeedPosts = finalToSetFeedPosts.concat(data);

if(finalOffset > 0) {
Expand Down Expand Up @@ -431,15 +434,14 @@ export default function Feed({
</animated.div>

{(postToEdit.file) ? (
(showPostPopup && fileBlob) &&
(fileBlob) &&
<PostPopup showPopup={showPostPopup} setShowPopup={setShowPostPopup} username={currentUser.username}
profilePic={currentUser.profile_pic_data} refreshFeed={refreshFeed}
setRefreshFeed={setRefreshFeed} editPost={true} caption={postToEditCaption} postFile={fileBlob}
year={releaseYear} month={releaseMonth} day={releaseDay} hour={releaseHour}
minute={releaseMinute} second={releaseSecond}
postId={postToEditId} userId={currentUser.id}/>
) : (
(showPostPopup) &&
<PostPopup showPopup={showPostPopup} setShowPopup={setShowPostPopup} username={currentUser.username}
profilePic={currentUser.profile_pic_data} refreshFeed={refreshFeed}
setRefreshFeed={setRefreshFeed} editPost={true} caption={postToEditCaption}
Expand All @@ -449,4 +451,4 @@ export default function Feed({
)}
</>
)
}
}

0 comments on commit 4e0d451

Please sign in to comment.