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

Quick Editor - Alt text feature foundations #501

Open
wants to merge 12 commits into
base: trunk
Choose a base branch
from

Conversation

hamorillo
Copy link
Contributor

@hamorillo hamorillo commented Dec 17, 2024

Closes #497

Description

This PR implements the foundations of the Alt Text feature. It doesn't include all of the functionality, as some parts still need to be implemented/improved. See sub-issues

I'm opening this PR for two reasons:

  • I think we can parallelize the missing work
  • To keep this PR as small as possible

The basic functionality, which is changing the alternative text for an image, is implemented.
You should be able to see the confirmation toast and the error toast when something fails.

image

Testing Steps

  1. Open the QE and the options for any avatar
  2. Modify the alt text
  3. Verify the Save is enabled when the value is different from the original alt text
  4. Save a new alt text
  5. Verify the QE navigates to the Avatar picker
  6. Close the QE bottom sheet and reopen it
  7. Open the alt text for the previous image and verify you see the new alt text
  8. Try to change it again but force an error (network error is enough)
  9. Verify you see the error toast
  10. Open the alt text again and verify you see the previous alt text (not the one that produces the error)
  11. Verify dark/light mode
  12. Verify orientation changes

@hamorillo hamorillo added new feature New feature [Feature] Gravatar-Quickeditor Gravatar Quick Editor module labels Dec 17, 2024
@hamorillo hamorillo added this to the 2.3.0 milestone Dec 17, 2024
@wpmobilebot
Copy link
Collaborator

wpmobilebot commented Dec 17, 2024

📲 You can test the changes from this Pull Request in Gravatar Demo by scanning the QR code below to install the corresponding build.
App Name Gravatar Demo
Commit29c3a14
Direct Downloadgravatar-demo-prototype-build-pr501-29c3a14.apk

@hamorillo hamorillo force-pushed the hamorillo/alt-text-404 branch from 9d28fbf to fe57213 Compare December 17, 2024 11:04
@hamorillo hamorillo marked this pull request as ready for review December 17, 2024 11:28
@hamorillo hamorillo force-pushed the hamorillo/alt-text-404 branch from fe57213 to 4dd4122 Compare December 17, 2024 11:51
Copy link
Contributor

@AdamGrzybkowski AdamGrzybkowski left a comment

Choose a reason for hiding this comment

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

I've left some comments/ideas that I think are worth discussing. Additionally, I think we need to handle the system back button to hide the Alt text section only, not the whole bottom sheet. There's no way to exit this state now without saving the new Alt text.

Comment on lines 209 to 215
if (uiState.mainSection is MainContentSection.AvatarsSectionUiState) {
key(uiState.avatarUpdates) {
ProfileCard(
profile = uiState.profile,
modifier = Modifier.padding(horizontal = 16.dp),
)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

❓ Have you considered creating a new page for the Alt text functionality? We could use nested graphs for this. Although it might look more time-consuming, I think it could lead to:

  1. Simplified UI code. There wouldn't be a need for several checks like this to show/hide section.
  2. Potentially simpler integration with the Close/Cancel button from the TopBar. This is a very top-level component, so having a nested destination would simplify working with it as it's closer.

If you prefer to keep it like this, maybe we should wrap the whole AvatarPicker (card and the section) and only do one of those checks (if section) in one place. This would also simplify any type of enter/exit animations I think.

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'll take a look at the nested graphs. Thanks for the suggestion.

Copy link
Contributor Author

@hamorillo hamorillo Dec 19, 2024

Choose a reason for hiding this comment

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

I've done a lot of refactoring in this PR using a nested graph. As you mentioned, the code looks cleaner (at least in my opinion).

Potentially simpler integration with the Close/Cancel button from the TopBar.

This still will cause some "problems" so we'll need to figure out how to solve this. One option could be to move the TopBar inside each section, but I haven't thought deeply about this.

Anyway, let me know what you think about the current approach.

I think we can still do another step and create a different ViewModel for the AltText section. Extracting the code related to the AltText should be "easy", the problem here is that we'll need to also make a way to sync the data between them. We can iterate over this in the following PRs.

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 still do another step and create a different ViewModel for the AltText section. Extracting the code related to the AltText should be "easy", the problem here is that we'll need to also make a way to sync the data between them. We can iterate over this in the following PRs.

I think we should do that. I left a comment related to that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Working on it ⚙️

Copy link
Contributor Author

@hamorillo hamorillo Dec 30, 2024

Choose a reason for hiding this comment

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

I've extracted the AltText related code to it's own ViewModel. The AvatarPickerViewModel handles only the rating changes so I've also refactored that code to remove all the unnecessary stuff.

we'll need to also make a way to sync the data between them

This PR doesn't accomplish that part. I think we should work on that in a different PR. For the moment, the AltText won't be updated in the local data models (it's updated in the backend) until the bottomsheet is closed and reopened again. (Which forces the data to be loaded from the server). #516

@AdamGrzybkowski
Copy link
Contributor

One more and this could be left as a subtask for further improvements, but I think it would be great to set the max height of the input field and make the content of it scrollable in a way the the Save button would remain visible even with a longer text.

Screenshot 2024-12-17 at 14 10 29

@hamorillo hamorillo marked this pull request as draft December 17, 2024 16:09
@hamorillo hamorillo force-pushed the hamorillo/alt-text-404 branch 2 times, most recently from 9bc1b80 to 2f1ddaf Compare December 19, 2024 17:52
@hamorillo
Copy link
Contributor Author

I think it would be great to set the max height of the input field and make the content of it scrollable in a way the the Save button would remain visible even with a longer text.

We have an issue to limit the number of characters #502, when we implement that feature, I would say this won't be a huge problem, but we'll see.

Copy link
Contributor

@AdamGrzybkowski AdamGrzybkowski left a comment

Choose a reason for hiding this comment

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

That looks better now I think! I've left a few comments that are worth addressing first.

I noticed that the Avatar in the profile card refreshes after coming back from the AltText section. I believe it's not directly related to this PR, but something that we should take a look at.

Comment on lines 46 to 51
val editorViewModel: AvatarPickerViewModel = viewModel(
factory = AvatarPickerViewModelFactory(
gravatarQuickEditorParams = gravatarQuickEditorParams,
handleExpiredSession = true,
),
)
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ There's a slight change in behavior here. This will make the AvatarPickerViewModel service QE relaunches. You can see that when you close/open the QE, there's no initial loading.

I wonder if this would be problematic for apps that provide the token. In a scenario where the user changes but the ViewModel survives and persists the previous data.

Copy link
Contributor

Choose a reason for hiding this comment

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

My suggestion would be to opt for a separate ViewModel anyway. So maybe it's not worth thinking about how to fix that.

@AdamGrzybkowski
Copy link
Contributor

I created an issue for the Avatar reload - #514

@hamorillo hamorillo force-pushed the hamorillo/alt-text-404 branch from 4e29afe to 3f3eb15 Compare December 30, 2024 14:28
}
}

private fun updateAvatar(avatarId: String, rating: Avatar.Rating? = null, altText: String? = null) {
private fun updateAvatarRating(avatarId: String, rating: Avatar.Rating? = null) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The AvatarPicker modifies only the Rating so there is no need for the generic method that allow the altText update. I've remove/renamed all the related code.

Copy link
Contributor

@AdamGrzybkowski AdamGrzybkowski 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 all the updates! Tested it and all worked fine!

altText = altText,
avatarUrl = avatarUrl,
onBackPressed = { navController.popBackStack() },
modifier = Modifier.padding(16.dp),
Copy link
Contributor

Choose a reason for hiding this comment

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

❓ All other pages define their own paddings, rather than it being set here. Is there a reason you did it here?

_uiState.update { currentState ->
currentState.copy(
altText = newAltText,
isSaveButtonEnabled = newAltText != altText,
Copy link
Contributor

Choose a reason for hiding this comment

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

When the newAltTest is empty the API call returns 200, but it doesn't update it. Looks like it quietly fails. Should we disable the save button in such cases?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Gravatar-Quickeditor Gravatar Quick Editor module new feature New feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Quick Editor: Alt Text - Base implementation of the Alt Text functionality
3 participants