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

Member avatar (no photo variant) #128

Merged
merged 5 commits into from
Mar 21, 2017
Merged

Member avatar (no photo variant) #128

merged 5 commits into from
Mar 21, 2017

Conversation

mperrotti
Copy link
Contributor

Related issues

Fixes https://meetup.atlassian.net/browse/SDS-186
Needed for mug/mup comm work

Description

Displays a placeholder avatar for users without a photo

Screenshots (if applicable)

screen shot 2017-03-14 at 10 32 53 am

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.08%) to 70.196% when pulling b6ea56b on avatar_no_photo into 849bb8a on master.

@jmhammons
Copy link

Awesome. I need this exact variant for /register/photo.

@@ -1,6 +1,9 @@
import React from 'react';
import cx from 'classnames';
import Avatar from './Avatar';
import { getIconAsBase64Uri } from './utils/base64';

const NO_PHOTO_SRC = getIconAsBase64Uri('profile');
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm interested in this choice as opposed to <img> with an SVG src? base64 strings can't be cached like other external assets, so this approach saves an http request but only in the first instance.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because the icon is used as in a background-image rule

Copy link
Contributor

Choose a reason for hiding this comment

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

apparently it's possible to use external SVGs in background-image rules - http://stackoverflow.com/a/9193203

Are there technical blockers for that? It's not a huge deal, but I am curious

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're rendering the icons from an SVG sprite, so there isn't a static SVG asset to point to in the background-image rule

Copy link
Contributor

Choose a reason for hiding this comment

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

you're blowing my mind @mperrotti

));
)).add('no photo', () => {
const MOCK_MEMBER_NO_PHOTO = { ...MOCK_MEMBER }; // treat the mock as immutable
MOCK_MEMBER_NO_PHOTO.photo = {};
Copy link
Contributor

Choose a reason for hiding this comment

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

another way to write this is const MOCK_MEMBER_NO_PHOTO = { ...MOCK_MEMBER, photo: {} };

@jmhammons
Copy link

@mperrotti @mmcgahan -- Any chance this could get merged this week? Member growth could really use this for an upcoming launch, potentially next week.

@akdetrick akdetrick merged commit 6e474fc into master Mar 21, 2017
try {
return require(`base64-image!swarm-icons/dist/optimized/${name}.svg`);
} catch(e) {
return new Error(`Could not construct base64 uri for icon "${name}" \n ${e}`);
Copy link
Contributor

Choose a reason for hiding this comment

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

does this catch work in practice? since the base-64 image is created by webpack at build time, the build should fail in case of an error, but this doesn't throw the error so I think it's probably not doing what it's intended to do at runtime

Copy link
Contributor

@akdetrick akdetrick Mar 21, 2017

Choose a reason for hiding this comment

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

I think the try/catch was my idea, but now it's obvious that it doesn't really do anything. We should just return the stuff inside the try

Copy link
Contributor

Choose a reason for hiding this comment

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

@@ -21,15 +24,16 @@ class AvatarMember extends React.Component {
{
'avatar--org': org,
'avatar--fbFriend': fbFriend,
'avatar--noPhoto': (member.photo || {}).photo_link == undefined
Copy link
Contributor

Choose a reason for hiding this comment

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

just use 'avatar--noPhoto': !(member.photo || {}).photo_link - no need to check that it's a particular kind of falsy.

className={classNames}
{...other} />
{...other}/>
Copy link
Contributor

Choose a reason for hiding this comment

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

newline before />

@mmcgahan
Copy link
Contributor

ah, just saw that @akdetrick merged. @mperrotti could you submit a PR to fix up the throw/catch?

@chenrui333 chenrui333 deleted the avatar_no_photo branch September 16, 2019 22:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants