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

[Notifications Refresh] Comment Moderation Content Header #23117

Conversation

salimbraksa
Copy link
Contributor

@salimbraksa salimbraksa commented Apr 29, 2024

Part of https://github.com/Automattic/wordpress-mobile/issues/31 and https://github.com/Automattic/wordpress-mobile/issues/38

This PR implements the header part of the comment content view. The rest of the view will addressed in a separate PR.

 Header Menu

Test Instructions

  1. Go to WordPressAppDelegate.swift file.
  2. Comment both didFinishLaunchingWithOptions and willFinishLaunchingWithOptions methods.
  3. Go to CommentContentHeaderView.swift file.
  4. Enable Previews.
  5. Compare the implementation against the design.

Regression Notes

  1. Potential unintended areas of impact
    N/A

  2. What I did to test those areas of impact (or what existing automated tests I relied on)
    N/A

  3. What automated tests I added (or what prevented me from doing so)
    N/A

PR submission checklist:

  • I have completed the Regression Notes.
  • I have considered adding unit tests for my changes.
  • I have considered adding accessibility improvements for my changes.
  • I have considered if this change warrants user-facing release notes and have added them to RELEASE-NOTES.txt if necessary.

Testing checklist:

  • WordPress.com sites and self-hosted Jetpack sites.
  • Portrait and landscape orientations.
  • Light and dark modes.
  • Fonts: Larger, smaller and bold text.
  • High contrast.
  • VoiceOver.
  • Languages with large words or with letters/accents not frequently used in English.
  • Right-to-left languages. (Even if translation isn’t complete, formatting should still respect the right-to-left layout)
  • iPhone and iPad.
  • Multi-tasking: Split view and Slide over. (iPad)

@salimbraksa salimbraksa added this to the Pending milestone Apr 29, 2024
@salimbraksa salimbraksa self-assigned this Apr 29, 2024
@salimbraksa salimbraksa changed the base branch from trunk to feature/notifications_refresh_p2 April 29, 2024 23:42
import UIKit
import SwiftUI

final class CommentContentView: UIView {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This class is still WIP and will open another PR to finalize it.

@salimbraksa salimbraksa marked this pull request as ready for review April 29, 2024 23:48
@wpmobilebot
Copy link
Contributor

wpmobilebot commented Apr 29, 2024

WordPress Alpha📲 You can test the changes from this Pull Request in WordPress Alpha by scanning the QR code below to install the corresponding build.
App NameWordPress Alpha WordPress Alpha
ConfigurationRelease-Alpha
Build Numberpr23117-81dd999
Version24.7
Bundle IDorg.wordpress.alpha
Commit81dd999
App Center BuildWPiOS - One-Offs #9780
Automatticians: You can use our internal self-serve MC tool to give yourself access to App Center if needed.

@wpmobilebot
Copy link
Contributor

wpmobilebot commented Apr 29, 2024

Jetpack Alpha📲 You can test the changes from this Pull Request in Jetpack Alpha by scanning the QR code below to install the corresponding build.
App NameJetpack Alpha Jetpack Alpha
ConfigurationRelease-Alpha
Build Numberpr23117-81dd999
Version24.7
Bundle IDcom.jetpack.alpha
Commit81dd999
App Center Buildjetpack-installable-builds #8826
Automatticians: You can use our internal self-serve MC tool to give yourself access to App Center if needed.

@salimbraksa salimbraksa force-pushed the task/notifications-comment-content-header branch from 4624595 to 1bf164c Compare April 30, 2024 17:02
@@ -92,6 +92,7 @@ public struct ContentPreview: View {
}
}

#if DEBUG
Copy link
Contributor

Choose a reason for hiding this comment

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

I think, this is redundant but won't cause any harm for sure. Compiler should be removing all the Previews and code that isn't used by the application on release version. So effectively, this should only be relevant to the developer and never to the AppStore version

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Resolved in 17738c5

let avatarURL: URL?
let username: String
let handleAndTimestamp: String
let menu: [[MenuItem]]
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it isn't very obvious why menu is an array of arrays. Could we improve the data structure to make the use case more explicit? Or perhaps rename it to highlight the sections & rows structure?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Resolved in c5ba22d

button(for: menuItem)
}
}
if sectionIndex < menu.count - 1 && !menu[sectionIndex + 1].isEmpty {
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we improve this by using a compactMap or filter logic to remove sections which have no items? Then we could always place the divider after the last index available.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Resolved in 57e22b4

}
} label: {
Image.DS.icon(named: .ellipsisHorizontal)
.imageScale(.small)
Copy link
Contributor

Choose a reason for hiding this comment

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

This disables dynamic font sizing for the image. I am not sure if that's desired. I just wanted to highlight.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I removed that modifier and the icon still doesn't scale. I think this a known issue where custom icons don't scale like SF Symbols.

Comment on lines 77 to 82
Button(action: action) {
Label {
Text(Strings.userInfo)
} icon: {
Image.DS.icon(named: .avatar)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we can extract this into a function that accepts a text and IconName and reduce the duplication.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Resolved in dd9db3f

Comment on lines 110 to 119
enum Item {
case userInfo(() -> Void)
case share(() -> Void)
case editComment(() -> Void)
case changeStatus((Status) -> Void)

enum Status {
case approve, trash, spam, pending
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Wouldn't a ViewModel be more scalable here? The view can report to actions there. Instead of dealing with closures, we the VM could implement all the cases. For 1 or 2 events I think closures are fine but this to me feels a bit rigid in terms of scalability. Wdyt?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've tried having only 1 closure to report menu events, something like this:

  enum Item {
       case userInfo
       case share
       case editComment
       case changeStatus(Status)

       enum Status {
           case approve, trash, spam, pending
       }
   }

Then I wanted to have a closure with this signature that callers will implement

let onItemSelected: (Item) -> Void = { item in 
    ...
}

The challenge arises with the .changeStatus(Status) case in our Item enum. When configuring the menu:

let menu = [.userInfo, .share, .editComment, .changeStatus(???)]

It's unclear how to specify a status for .changeStatus statically, as it represents multiple potential actions (approve, trash, spam, pending).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can you share a pseudo-code of how the VM approach would work?

Copy link
Contributor

@justtwago justtwago left a comment

Choose a reason for hiding this comment

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

Finally managed to test the previews and they look awesome! I like the sub-menu under the "Change status" section! ❤️
Looking forward to seeing this in practice.

Copy link
Contributor

@justtwago justtwago 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 improvement. It's definitely clearer to have a separate menu configuration class. Great job!
Just left one minor Swift-related question.

}

private var shouldShowMenu: Bool {
return [menu.userInfo, menu.share, menu.editComment, menu.changeStatus].reduce(false) { $0 || $1 }
Copy link
Contributor

Choose a reason for hiding this comment

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

Just curious if this function checks whether one of the menu items is true.
.reduce(false) { $0 || $1 } part seems to be not entirely intuitive, and I'm wondering if .contains { _ in true } would have a similar result.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Resolved in 7154ae5

@salimbraksa salimbraksa merged commit 7924ea1 into feature/notifications_refresh_p2 May 4, 2024
3 of 18 checks passed
@salimbraksa salimbraksa deleted the task/notifications-comment-content-header branch May 4, 2024 01:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants