Skip to content

Commit

Permalink
Merge pull request #349
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 c1d85d3 + 105faa5 commit 956d15e
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 23 deletions.
18 changes: 14 additions & 4 deletions epoch_frontend/src/modules/Feed.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export default function Feed({
const [offset, setOffset] = useState(0);
const limit = 20; // must be bigger than toRemove
const maxPosts = 25;
const toRemove = 15; // Must be smaller than 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,11 +104,21 @@ export default function Feed({
{
let finalToSetFeedPosts = finalFeedPosts;

setPreviousPosts(previousPosts.concat(finalFeedPosts.slice(0, toRemove)));
finalToSetFeedPosts = finalToSetFeedPosts.slice(toRemove);
finalToSetFeedPosts = finalToSetFeedPosts.concat(data);


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

finalToSetFeedPosts = finalToSetFeedPosts.concat(data);

if(finalOffset > 0) {
setAllowScrollToTop(true);
setNoMoreTopPosts(false);
Expand Down
3 changes: 2 additions & 1 deletion epoch_frontend/src/modules/NotificationsPopup.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ function NotificationsPopup ({showNotifications, setShowNotifications, newUnread
const [countUnreadNotifications, setCountUnreadNotifications] = useState(0);
const [loadMorePrompt, setLoadMorePrompt] = useState('Load more');
const [markAllAsReadPrompt, setMarkAllAsReadPrompt] = useState('Mark all as read');
const getNotificationsEvery = 10000; // 10 seconds

const {transform: inTransform, opacity: inOpacity} = useSpring({
opacity: showNotifications ? 1 : 0,
Expand Down Expand Up @@ -103,7 +104,7 @@ function NotificationsPopup ({showNotifications, setShowNotifications, newUnread
if (!showNotifications && !isLoading ) {
const interval = setInterval(() => {
getNotifications();
}, 90000000);
}, getNotificationsEvery);

return () => clearInterval(interval);
}
Expand Down
33 changes: 15 additions & 18 deletions epoch_frontend/src/modules/Post.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import FavoriteBorderOutlinedIcon from '@mui/icons-material/FavoriteBorderOutlin
import '../styles/Post.css';
import {useNavigate} from 'react-router-dom';
import {useLocation} from 'react-router-dom';
import PostPopup from "./PostPopup";
import ArrowCircleUpSharpIcon from '@mui/icons-material/ArrowCircleUpSharp';
import ArrowCircleDownSharpIcon from '@mui/icons-material/ArrowCircleDownSharp';
import {favoritePost, removeFavoritePost, votePost, removeVotePost} from "../services/post";
Expand All @@ -22,10 +21,9 @@ export default function Post({post, postViewer, isInFavorites, setShowDeletePost
const navigate = useNavigate();
const [showOverlay, setShowOverlay] = useState(false);
const [overlayImageUrl, setOverlayImageUrl] = useState('');
const [postAdmin, setPostAdmin] = useState(postViewer && postViewer.username === post.username);
const postAdmin= postViewer && postViewer.username === post.username;
const [error, setError] = useState(false);
const [errorMessage, setErrorMessage] = useState('');
const [deleted, setDeleted] = useState(false);
const [updating, setUpdating] = useState(false);
const [updatingMessage, setUpdatingMessage] = useState('');
const [favorited, setFavorited] = useState(false);
Expand Down Expand Up @@ -197,29 +195,28 @@ export default function Post({post, postViewer, isInFavorites, setShowDeletePost
let visible = false;

if (postIsInThePast() || postAdmin) {
if (!deleted) {
if ( (isInFavorites && favorited) || !isInFavorites) {
if (usernames.length > 0) {
for (let i = 0; i < usernames.length && !visible; i++) {
if (postViewer && postViewer.username === usernames[i]) {
visible = true;
}
}

if (!visible)
{
visible = postAdmin;
if ( (isInFavorites && favorited) || !isInFavorites) {
if (usernames.length > 0) {
for (let i = 0; i < usernames.length && !visible; i++) {
if (postViewer && postViewer.username === usernames[i]) {
visible = true;
}
}
else

if (!visible)
{
visible = true;
visible = postAdmin;
}
}
else
{
visible = true;
}
}
}



return visible;
}

Expand Down Expand Up @@ -549,7 +546,7 @@ export default function Post({post, postViewer, isInFavorites, setShowDeletePost
setLocalFinalFavoritedByUsernameList(updatedFavoritedByUsernameList);
}
} else if (!favorited && postViewer) {
let updatedFavoritedByUsernameList = favoritedByUsernameList.filter((user) => user.user_id !== postViewer.id);
let updatedFavoritedByUsernameList = localFinalFavoritedByUsernameList.filter((user) => user.user_id !== postViewer.id);

if (JSON.stringify(updatedFavoritedByUsernameList) !== JSON.stringify(localFinalFavoritedByUsernameList)) {
setLocalFinalFavoritedByUsernameList(updatedFavoritedByUsernameList);
Expand Down

0 comments on commit 956d15e

Please sign in to comment.