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

[Avatar] Hookify component #2067

Merged
merged 1 commit into from
Sep 19, 2019
Merged

[Avatar] Hookify component #2067

merged 1 commit into from
Sep 19, 2019

Conversation

BPScott
Copy link
Member

@BPScott BPScott commented Aug 31, 2019

WHY are these changes introduced?

Starting down the path of removing withAppProvider usage into the new world of hooks.
Part of #1995

WHAT is this pull request doing?

Converts Avatar to use hooks.
Reworks the logic for how we handle falling back to using initials if an image fails to load so it relies on a single status state that can be either "pending, errored or loading" rather than two hasError and hasLoading states.

Use react-testing in some Avatar tests as Enzyme doesn't seem to accurately reflect props chagnes for functional components.

How to 🎩

Play with the following to investigate how the onError fallback to initials logic behaves:

Copy-paste this code in playground/Playground.tsx:
import React, {useState, useCallback} from 'react';
import {Page, Button, Avatar} from '../src';

export function Playground() {
  const [isUsingValidSource, setIsUsingValidSource] = useState(true);
  const toggle = useCallback(() => {
    setIsUsingValidSource((state) => !state);
  }, []);

  const avatarSource = isUsingValidSource
    ? 'http://placekitten.com/40/40'
    : 'nope';

  return (
    <Page title="Playground">
      <Button onClick={toggle}>Toggle Source</Button>
      <hr />
      <Avatar size="large" initials="DL" source={avatarSource} />
    </Page>
  );
}

🎩 checklist

@BPScott BPScott requested review from dleroux and tmlayton August 31, 2019 00:18
@BPScott BPScott mentioned this pull request Aug 31, 2019
@BPScott BPScott force-pushed the hookify-avatar branch 2 times, most recently from 82fb040 to 7a7e40c Compare September 3, 2019 19:46
@dleroux
Copy link
Contributor

dleroux commented Sep 5, 2019

I'm trying to run yarn prod but it isn't working for me. This one would be safer to test in web, prod, using an account that doesn't have an avatar. The code looks fine but we had a lot of back and forth when implementing the "error" approach.

@BPScott BPScott changed the title Hookify Avatar component [Avatar] Hookify component Sep 6, 2019
Copy link
Contributor

@tmlayton tmlayton 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! I like the change to use a single status. I think we are okay to not 🎩 in Web as it functionally the same.

@BPScott
Copy link
Member Author

BPScott commented Sep 19, 2019

@dleroux did you have any further comments on this?

@dleroux
Copy link
Contributor

dleroux commented Sep 19, 2019

If Tim is confident I'm good too. I just remember the trouble this one caused when we first rolled it out so being a little cautious. But the code looks good.

Use react-testing in some Avatar tests as Enzyme doesn't like updating
after hooky components after a setState
@BPScott BPScott merged commit 3ed0d10 into master Sep 19, 2019
@BPScott BPScott deleted the hookify-avatar branch September 19, 2019 19:27
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.

3 participants