Skip to content

feat(avatar): add loading state to avatar and AIConversation #5777

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

Merged
merged 3 commits into from
Sep 11, 2024

Conversation

dbanksdesign
Copy link
Contributor

Description of changes

Added isLoading prop to Avatar primitive and added a loading state in the AIConversation which uses it.

Issue #, if available

Description of how you validated changes

CleanShot 2024-09-09 at 21 55 13

Checklist

  • Have read the Pull Request Guidelines
  • PR description included
  • yarn test passes and tests are updated/added
  • PR title and commit messages follow conventional commit syntax
  • If this change should result in a version bump, changeset added (This can be done after creating the PR.) This does not apply to changes made to docs, e2e, examples, or other private packages.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@dbanksdesign dbanksdesign requested a review from a team as a code owner September 10, 2024 04:58
Copy link

changeset-bot bot commented Sep 10, 2024

🦋 Changeset detected

Latest commit: 40a8945

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 15 packages
Name Type
@aws-amplify/ui-react-ai Minor
@aws-amplify/ui-react Minor
@aws-amplify/ui Minor
@aws-amplify/ui-react-auth Patch
@aws-amplify/ui-react-liveness Patch
@aws-amplify/ui-react-notifications Patch
@aws-amplify/ui-react-storage Patch
@aws-amplify/ui-react-core-auth Patch
@aws-amplify/ui-react-core-notifications Patch
@aws-amplify/ui-react-core Patch
@aws-amplify/ui-react-native-auth Patch
@aws-amplify/ui-react-native Patch
@aws-amplify/ui-vue Patch
@aws-amplify/ui-angular Patch
@aws-amplify/ui-react-geo Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

)}
>
<View className={ComponentClassName.AIConversationMessageAvatar}>
<Avatar isLoading>{avatar?.avatar}</Avatar>
Copy link
Member

@calebpollman calebpollman Sep 10, 2024

Choose a reason for hiding this comment

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

If the intention of adding isLoading to the Avatar so it can render a loading indicator here seems like we could just provide the loading component as children here, e.g.:

        <Avatar>{isLoading ? <LoadingComp /> : avatar?.avatar}</Avatar>

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We could, but I don't think we should. If you look at the gif the loading avatar shows the avatar icon and the circular loader so your could would need to include both a Loader component and the avatar for the loading state plus some CSS to get it positioned correctly. I think an isLoading prop for an Avatar primitive makes sense in general too.

Copy link
Contributor

Choose a reason for hiding this comment

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

I do somewhat think the isLoading prop is very specific to our use case, but maybe that's not an issue since we're the primary user of this primitive right now

Copy link
Member

Choose a reason for hiding this comment

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

Ultimately feel coupling loading state/rendering logic inside a UI primitive leads to long term complications with extension of the primitive. Adding isLoading to Avatar feels like a bit of a foot gun, since as a consumer i now need to make sure that I'm removing isLoading/setting to false if my avatar is loaded, in addition to the mental overhead of the existing behavior of the src and children props.

In this case providing a loading component would just require passing a className to our existing Loader component. IMO the Loader itself should just work out of the box for use cases where it is provided as a placeholder.

Not blocking, but do feel like we gain more from composition and lose flexibility by adding behavioral props

Copy link
Contributor

@thaddmt thaddmt left a comment

Choose a reason for hiding this comment

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

Are there any relevant tests that should be updated for Avatar? Otherwise LGTM

)}
>
<View className={ComponentClassName.AIConversationMessageAvatar}>
<Avatar isLoading>{avatar?.avatar}</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 do somewhat think the isLoading prop is very specific to our use case, but maybe that's not an issue since we're the primary user of this primitive right now

@dbanksdesign dbanksdesign merged commit 0ebf8b3 into main Sep 11, 2024
40 checks passed
@dbanksdesign dbanksdesign deleted the avatar-loading branch September 11, 2024 20:07
@github-actions github-actions bot mentioned this pull request Sep 11, 2024
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.

4 participants