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

Add updating post to fetch new comments when attempting to scroll... #332

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from

Conversation

Aivean
Copy link
Collaborator

@Aivean Aivean commented May 30, 2023

…to a comment that is not fetched yet.

Demo:
notif-demo

Tested some common scrolling scenarios, including scrolling to not existing hash.

@Aivean Aivean requested a review from a team May 30, 2023 04:22
@Aivean Aivean changed the title Add updating post to fetch a new comments when attempting to scroll... Add updating post to fetch new comments when attempting to scroll... May 30, 2023
@@ -59,6 +63,11 @@ export default function PostPage() {
if (location.hash) {
commentId = parseInt(location.hash.substring(1));
scrollToComment = document.querySelector<HTMLDivElement>(`[data-comment-id="${commentId}"]`);

if (!scrollToComment && fetchingComment !== commentId) {
reload(unreadOnly).then(() => setFetchingComment(commentId));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I got your idea but this will reload the post by just clicking at the link which may be not something user wants - I often skip reading answers in big posts because I don't have enough time to read all of them right now. At least we should ask for user's confirmation
Second scenario - comment is not on the page because it is in read branch - in this case reloading won't show it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think both cases can be fixed by relying on the last read timestamp/comment instead of the materialized "isNew" flag.

This allows performing the comment presence check easily, as well as loading the "new" comments without removing existing "new" comments from the page.

@4vanger
Copy link
Collaborator

4vanger commented Jun 8, 2023 via email

@Aivean
Copy link
Collaborator Author

Aivean commented Jun 8, 2023

@4vanger

I'm almost done with this proposal ;)

An idea for that:

Instead of having two statuses for comments: "read" and "new", have three:

  • "read"
  • "previously new"
  • "new"

When page is loaded originally, comments are either "read" or "new".

However, user has the ability to refresh the page or or follow notification link, which loads a batch of fresh comments. To distinguish between them and "new" comments that were already on the page, I suggest to introduce a new status with working name "previously new".

When fresh comments are added to the page, the currently "new" comments will transition to the status "previously new", and freshly added comments will become "new".

Obviously, both statuses are calculated based on the corresponding timestamp/last comment id.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants