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

Automatic collapse child comments #841

Merged
merged 32 commits into from
Jan 29, 2024

Conversation

schmeat
Copy link
Contributor

@schmeat schmeat commented Jan 3, 2024

Checklist

  • I have read CONTRIBUTING.md
  • I have described what this PR contains
  • This PR addresses one or more open issues that were assigned to me:
    - list issue(s) here
  • If this PR alters the UI, I have attached pictures/videos

Pull Request Information

About this Pull Request

Adding a feature that automatically collapses child comments when a user loads a page. A feature toggle is added to the settings with the default being off.

Screenshots and Videos

Screenshot Screenshot
Simulator Screenshot - iPhone 15 Pro - 2024-01-05 at 17 50 09 Simulator Screenshot - iPhone 15 Pro - 2024-01-03 at 15 32 59
Simulator Screenshot - iPhone 15 Pro - 2024-01-05 at 17 52 15 Simulator Screenshot - iPhone 15 Pro - 2024-01-05 at 17 52 25
Video
https://streamable.com/b0h7s2

Additional Context

Other apps such as Apollo have this feature and thought it would be a good addition. Please let me know if I should change naming conventions. The icon in the settings page is missing too, was not sure what the best one is available for that.

Apollo did have different UI for this feature, it would say [X amount of replies] under each parent comments and would load comments if a user clicked that. I can add that functionality but just did core functionality for now while I wait for feedback.

@schmeat schmeat requested a review from a team as a code owner January 3, 2024 08:57
@schmeat schmeat requested review from WestonHanners and JakeShirley and removed request for a team January 3, 2024 08:57
Copy link
Contributor

@Sjmarf Sjmarf left a comment

Choose a reason for hiding this comment

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

Thanks for the PR! This is a useful feature.

Regarding the settings icon, I think "arrow.down.and.line.horizontal.and.arrow.up" would be a good choice. This is what we use elsewhere in the app to represent collapsing a comment.

I did notice a small issue. When a comment is collapsed, its children should be hidden completely. However, when a post is first opened with the new setting enabled, all of the children are visible, even those whose parents are collapsed.

Here's what it look like currently:

Screenshot 2024-01-03 at 18 23 39

Here's what it should look like:

Screenshot 2024-01-03 at 18 23 53

The correct appearance can be reached by expanding and re-collapsing each top-layer (orange-colored) comment.

To hide comments completely, you can set the isParentCollapsed value to true.

@schmeat
Copy link
Contributor Author

schmeat commented Jan 3, 2024

Good catch @Sjmarf , I'll check to see why that collapse behaviour is happening. I'll also update the icon too. Thanks

- Updated collapseComment flag name to be more consistent
@schmeat
Copy link
Contributor Author

schmeat commented Jan 3, 2024

Adding the feature flag to isParentCollapsed produces this result:

Simulator Screenshot - iPhone 15 Pro - 2024-01-03 at 10 44 09

I do find that it looks better this way and the user can see amount of replies in the bottom portion of the comment box. However, clicking on it collapses the comment which means the user has to press the comment twice to see child comments. Looking at ways to work around that right now, any suggestions?

I also need to put isParentCollapsedto true on both of the available comment blocks in order to produce this result, doing it on only one seems to just produce the same behaviour as before.

@Sjmarf
Copy link
Contributor

Sjmarf commented Jan 3, 2024

Hmm yeah that's a little tricky.

I think we'd need to have isParentCollapsed set to true for all comments further down than the orange-colored reply, but set to false for the top-level comment and the orange-colored reply. This should be doable by calculating the depth of the comment (this is done already in the initialiser of HierarchicalComment) and only setting isParentCollapsed to true for comments with a depth of 2 or more.

Maybe instead of determining isCollapsed and isParentCollapsed before the HierarchicalComment is initialised, we could do it inside of the HierarchicalComment initialiser? That way, we could access the depth value that is calculated in the initialiser.

@schmeat
Copy link
Contributor Author

schmeat commented Jan 3, 2024

Ok updated logic:

https://streamable.com/fevk7o

@schmeat schmeat changed the title [Feature] Added automatic collapse child comments [Feature] Automatic collapse child comments Jan 3, 2024
Copy link
Contributor

@Sjmarf Sjmarf left a comment

Choose a reason for hiding this comment

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

Looks good! I like the new settings location.

Mlem/API/Internal/HierarchicalComment.swift Outdated Show resolved Hide resolved
@schmeat
Copy link
Contributor Author

schmeat commented Jan 4, 2024

For some reason every time I try to revert the enum, it discards the change and makes a blank commit. Unsure why that's happening, maybe due to git hooks? Not sure

@EricBAndrews
Copy link
Member

For some reason every time I try to revert the enum, it discards the change and makes a blank commit. Unsure why that's happening, maybe due to git hooks? Not sure

This is due to the Swiftformat hook. Icons contains nothing but static members--it's basically a namespace, except that Swift doesn't have namespaces. It therefore doesn't make sense for it to be instantiable, hence declaring it as a caseless enum.

@schmeat
Copy link
Contributor Author

schmeat commented Jan 5, 2024

I actually think I can implement the Apollo style collapse (where it displays n replies below the comment box) sooner rather than later. I have the functionality down just working on UI. Please hold off on merging.

Copy link
Contributor

@Sjmarf Sjmarf left a comment

Choose a reason for hiding this comment

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

Yep, that fixed it!

This introduced a bug, though. If you click "show n replies", then go to a user profile, then click "back", the comment tree is collapsed again but the "show n replies" button is hidden.

Before the most recent fix, the "Show n replies" button would be (correctly) shown in this situation.

@schmeat
Copy link
Contributor Author

schmeat commented Jan 11, 2024

That was because I removed the onDisappearsince it should only be collapsing in certain contexts, but still not sure what's causing it. Anyways I readded that onDisappear code and it should work now

Copy link
Contributor

@Sjmarf Sjmarf left a comment

Choose a reason for hiding this comment

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

Because the comments section uses a LazyVStack, using .onDisappear makes the "Show n replies" button appear again on an expanded comment if you scroll down the comments and then back up.

@Sjmarf Sjmarf added enhancement New feature or request ui Related to UI Fixes labels Jan 11, 2024
@Sjmarf Sjmarf changed the title [Feature] Automatic collapse child comments Automatic collapse child comments Jan 11, 2024
@schmeat
Copy link
Contributor Author

schmeat commented Jan 11, 2024

@Sjmarf Not sure what the best solution to this would be. I tried to set isCommentReplyHidden in .onAppear instead, but it seems like when we navigate back to the post from the user profile, isCollapsedis not being set correctly in HierarchicalComment. I'm unsure what method is actually collapsing it still, since it's not hitting any of my current collapse methods.

I tried debugging and it's showing as retaining the hidden variable but not resetting collapse. I guess it's particularly tricky in this case because isCollapsed being false can be when the child comments are hidden and not hidden.

ID: 3350207, isCollapsed: false, isCommentReplyHidden: false, number of children: 8
ID: 3350207, isCollapsed: false, isCommentReplyHidden: true, number of children: 8

Would that be an acceptable bug to ship with? Will take me some more time to investigate the root cause of it and I'm not sure how much time I can dedicate this week. If you have a hunch as to why this behaviour is happening please let me know.

@Sjmarf
Copy link
Contributor

Sjmarf commented Jan 12, 2024

I'll take a look at it this weekend and see if I can find the issue 👍

@Sjmarf
Copy link
Contributor

Sjmarf commented Jan 13, 2024

Looks like it's caused by the .task in ExpandedPost on line 85. Adding an if statement fixes it

.task {
    if commentTracker.comments.isEmpty {
        await loadComments()
    }
}

@schmeat
Copy link
Contributor Author

schmeat commented Jan 14, 2024

Thanks so much for checking, I've added those changes now!

Copy link
Contributor

@Sjmarf Sjmarf left a comment

Choose a reason for hiding this comment

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

Looks good to go!

@schmeat
Copy link
Contributor Author

schmeat commented Jan 17, 2024

Is there something I need to fix to get it merged? I noticed some build failures but logs say something about access

@Sjmarf
Copy link
Contributor

Sjmarf commented Jan 17, 2024

Every time you make a change, the checks need to re-run. For organisation members this happens automatically, but for everyone else it has to be approved by an organisation member :(

Also occasionally the checks do fail for no apparent reason and we just have to re-run them.

Feel free to merge this whenever you like (if you're able to? If not lmk and I'll merge it).

@schmeat
Copy link
Contributor Author

schmeat commented Jan 17, 2024

Okay sounds good. I don't think it lets me merge unless all checks are passed.

@Sjmarf
Copy link
Contributor

Sjmarf commented Jan 17, 2024

Huh, I see the Error: Resource not accessible by integration too now 🤔

I've not seen that before

@schmeat
Copy link
Contributor Author

schmeat commented Jan 18, 2024

Not sure what the build settings for this project are, but maybe this is it:

kishikawakatsumi/xcresulttool#691 (comment)

We need pull_request_target if the repository is forked.

@Sjmarf
Copy link
Contributor

Sjmarf commented Jan 19, 2024

Thanks - Jake's put a PR up to fix it, once that's in I'll rerun the checks 👍

@EricBAndrews
Copy link
Member

Builds and checks pass locally--we're still getting our CI stuff worked out for forked builds, so once this PR is merge-compatible I'll run the checks again locally and bypass CI to merge

…llapse-child-comments

# Conflicts:
#	Mlem/Views/Shared/Comments/Comment Item.swift
#	Mlem/Views/Shared/Posts/Expanded Post.swift
#	Mlem/Views/Tabs/Profile/UserView+Logic.swift
@schmeat
Copy link
Contributor Author

schmeat commented Jan 29, 2024

Sorry for the delay, busy week. Should be good to go now.

@Sjmarf Sjmarf added this to the v1.2 milestone Jan 29, 2024
@EricBAndrews
Copy link
Member

Build and test work locally. I'm bypassing branch protections to merge without CI; if this breaks dev that's on me.

@EricBAndrews EricBAndrews merged commit 6354137 into mlemgroup:dev Jan 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request ui Related to UI Fixes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants