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

QE: Avatar Rating #589

Merged
merged 20 commits into from
Dec 11, 2024
Merged

Conversation

andrewdmontgomery
Copy link
Contributor

@andrewdmontgomery andrewdmontgomery commented Dec 5, 2024

Closes #546 #548

Description

Adds support for viewing and changing the rating of an avatar in the Quick Editor.

Testing Steps

  1. Run the Demo app
  2. Choose SwiftUI Demos --> Profile editor with oauth --> Tap Open Profile Editor with OAuth flow
  3. Tap the action menu ...
    • OBSERVE:
      • The Rating menu appears in the menu
      • The Rating menu shows the current rating for the image: Rating: PG
      • The Rating menu has a icon of a half-filled star ⭐
  4. Tap the Rating menu to show the sub-menu
    • OBSERVE:
      • All rating options are visible, with descriptions (G (General))
      • The selected rating has a checkmark (✔️)
  5. Choose a different rating
    • OBSERVE:
      • The rating for the image changes on the device
      • The rating for the image changes on web

Try:

  • different layouts
  • dark/light
  • iPad

@andrewdmontgomery andrewdmontgomery added the enhance New feature or request label Dec 5, 2024
@andrewdmontgomery andrewdmontgomery linked an issue Dec 5, 2024 that may be closed by this pull request
@wpmobilebot
Copy link

wpmobilebot commented Dec 5, 2024

Gravatar Prototype Build📲 You can test the changes from this Pull Request in Gravatar Prototype Build by scanning the QR code below to install the corresponding build.
App NameGravatar Prototype Build Gravatar Prototype Build
Build Number1848
Version1.0
Bundle IDcom.automattic.gravatar-sdk-demo-uikit.prototype-build
Commitb535bac
App Center BuildGravatar SDK Demo - UIKit #457
Automatticians: You can use our internal self-serve MC tool to give yourself access to App Center if needed.

/// Transforms `Avatar.Rating` into `AvatarRating`
/// This is only necessary while we maintain both enums. For our next major realease, `Avatar` will use the `AvatarRating` enum
/// rather than defining its own.
var avatarRating: AvatarRating {
Copy link
Contributor Author

@andrewdmontgomery andrewdmontgomery Dec 6, 2024

Choose a reason for hiding this comment

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

We only need this in one place, currently, and only until we release a new major release. But I wonder if it still makes sense to move it to Gravatar and use package, to match the access of Avatar.Rating.

@@ -1,24 +1,21 @@
import Foundation
import SwiftUI

enum AvatarAction: String, CaseIterable, Identifiable {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since we are laying out the menu manually, the CaseIterable is no longer needed.

I'm using an enum with an associated value (rating(AvatarRating)) in order to pass values back up the chain when a rating is tapped. So conforming to String is no longer possible.

@andrewdmontgomery andrewdmontgomery marked this pull request as ready for review December 6, 2024 23:50
@andrewdmontgomery
Copy link
Contributor Author

@etoledom this makes some changes that will likely conflict with work you are doing on #535 and #545. Let me know if I can clear up anything.

Comment on lines -229 to 294
if request.httpMethod == "POST" {
if request.url?.absoluteString.contains(RequestType.avatars.rawValue) == true {
return (Bundle.postAvatarSelectedJsonData, HTTPURLResponse.successResponse()) // Avatars data
if request.isSetAvatarForEmailRequest {
return (Bundle.postAvatarSelectedJsonData, HTTPURLResponse.successResponse()) // Avatars data
}

if request.isSetAvatarRatingRequest {
if let returnErrorCode {
return (Data("".utf8), HTTPURLResponse.errorResponse(code: returnErrorCode))
} else {
return (Bundle.setRatingJsonData, HTTPURLResponse.successResponse()) // Avatar data
}
}
if request.url?.absoluteString.contains(RequestType.profiles.rawValue) == true {

if request.isProfilesRequest {
return (Bundle.fullProfileJsonData, HTTPURLResponse.successResponse()) // Profile data
} else if request.url?.absoluteString.contains(RequestType.avatars.rawValue) == true {
} else if request.isAvatarsRequest == true {
return (Bundle.getAvatarsJsonData, HTTPURLResponse.successResponse()) // Avatars data
}
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 broke this into helpers. Now that we're adding more capabilities, I think this will be easy to read and extend.

Comment on lines +241 to +242
"Handle avatar rating change: Failure",
arguments: [HTTPStatus.unauthorized, .forbidden]
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 have been adding titles to tests as I write them.

And parameterized tests in Swift Testing are 🎉

@andrewdmontgomery andrewdmontgomery force-pushed the andrewdmontgomery/qe-avatar-rating branch from 81ddcf3 to a840f86 Compare December 10, 2024 22:35
Copy link
Contributor

@pinarol pinarol left a comment

Choose a reason for hiding this comment

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

Looks great 🎉

@@ -419,6 +444,16 @@ extension AvatarPickerViewModel {
value: "Oops, something didn't quite work out while trying to share your avatar.",
comment: "This error message shows when the user attempts to share an avatar and fails."
)
static let avatarRatingUpdateSuccess = SDKLocalizedString(
"AvatarPickerViewModel.RatingUpdate.Success",
value: "Avatar rating was changed successfully",
Copy link
Contributor

Choose a reason for hiding this comment

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

let's put a . at the end for consistency, 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.

Definitely, thanks for catching.

@andrewdmontgomery andrewdmontgomery merged commit 2c54ae0 into trunk Dec 11, 2024
9 checks passed
@andrewdmontgomery andrewdmontgomery deleted the andrewdmontgomery/qe-avatar-rating branch December 11, 2024 17:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhance New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

New internal API: Update rating
3 participants