Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: too many comments in profile page freeze the app #365

Closed
plebeius-eth opened this issue Sep 9, 2024 · 4 comments
Closed

fix: too many comments in profile page freeze the app #365

plebeius-eth opened this issue Sep 9, 2024 · 4 comments
Assignees
Labels
bug Something isn't working

Comments

@plebeius-eth
Copy link
Member

https://t.me/plebbitjs/30554
https://t.me/seeditreact/6756

@plebeius-eth plebeius-eth self-assigned this Sep 9, 2024
@plebeius-eth plebeius-eth converted this from a draft issue Sep 9, 2024
@plebeius-eth plebeius-eth added the bug Something isn't working label Sep 9, 2024
@plebeius-eth
Copy link
Member Author

2295599

@github-project-automation github-project-automation bot moved this from In Progress to Done in seedit Sep 9, 2024
@estebanabaroa
Copy link
Member

you should use url params to set the tabs, this isn't good

  useEffect(() => {
    if (isInProfileUpvotedView) setActiveTab('upvoted');
    else if (isInProfileDownvotedView) setActiveTab('downvoted');
    else if (isInProfileHiddenView) setActiveTab('hidden');
    else if (isInCommentsView) setActiveTab('comments');
    else if (isInSubmittedView) setActiveTab('submitted');
    else setActiveTab('overview');

    setCurrentPage(1); // Reset page when changing tabs
  }, [isInProfileUpvotedView, isInProfileDownvotedView, isInProfileHiddenView, isInCommentsView, isInSubmittedView]);

@estebanabaroa estebanabaroa reopened this Sep 10, 2024
@estebanabaroa
Copy link
Member

estebanabaroa commented Sep 10, 2024

you shouldnt calculate everything for all tabs at once


  const upvotedCommentCids = useMemo(() => {
    const allUpvotedCids = accountVotes?.filter((vote) => vote.vote === 1).map((vote) => vote.commentCid) || [];
    return allUpvotedCids.slice(0, currentPage * pageSize);
  }, [accountVotes, currentPage]);

  const downvotedCommentCids = useMemo(() => {
    const allDownvotedCids = accountVotes?.filter((vote) => vote.vote === -1).map((vote) => vote.commentCid) || [];
    return allDownvotedCids.slice(0, currentPage * pageSize);
  }, [accountVotes, currentPage]);

  const hiddenCommentCids = useMemo(() => {
    const allHiddenCids = Object.keys(account?.blockedCids ?? {});
    return allHiddenCids.slice(0, currentPage * pageSize);
  }, [account?.blockedCids, currentPage]);

  const { hasMoreUpvoted, hasMoreDownvoted, hasMoreHidden } = useMemo(() => {
    const allUpvotedCids = accountVotes?.filter((vote) => vote.vote === 1).map((vote) => vote.commentCid) || [];
    const allDownvotedCids = accountVotes?.filter((vote) => vote.vote === -1).map((vote) => vote.commentCid) || [];
    const allHiddenCids = Object.keys(account?.blockedCids ?? {});

you should only do calculation if the user is on the tab, ie, you should use routes like this

const Profile = () => {
  const { t } = useTranslation();
  const account = useAccount();
  const location = useLocation();
  const params = useParams();
  const isMobile = useWindowWidth() < 640;
  // ...

 return (
     <div className={styles.content}>
      <div className={isMobile ? styles.sidebarMobile : styles.sidebarDesktop}>
        <AuthorSidebar />
      </div>
    <Routes>
            <Route path='/profile/upvotes/:page' element={<Upvotes />} />
            <Route path='/profile/downvotes/:page' element={<Downvotes />} />
            // .. etc
     </Routes>

also its probably good to use virtuoso for the accountComments, but the votes and hidden (anything that uses useComments to load) will probably work best with pagination [previous][next] because they are loading progressively so the infinite scroll isnt really gonna work. You actually dont even need to use useComments(), you can just have single component that calls useComment inside, and render an array of components

at some point we need to have a useFeed like hook for votes and hidden but it's complicated to do and low priority as people rarely use these pages

@plebeius-eth plebeius-eth moved this from Done to In Progress in seedit Oct 3, 2024
@plebeius-eth
Copy link
Member Author

refactored with virtuoso for account comments, pagination for comments from votes and blocked cids

9434a17

@github-project-automation github-project-automation bot moved this from In Progress to Done in seedit Oct 23, 2024
@plebeius-eth plebeius-eth removed this from seedit Oct 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants