Skip to content

Commit

Permalink
feat(avatars): use right avatar source
Browse files Browse the repository at this point in the history
  • Loading branch information
JalilArfaoui committed Aug 14, 2020
1 parent 51a5dec commit 61ab983
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 13 deletions.
1 change: 1 addition & 0 deletions src/app/profiles/App/Profiles/Profile/ProfileIntro.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ export const ProfileIntro = ({
onSubscribe={subscribe}
onUnsubscribe={unsubscribe}
loading={loading}
avatarSize="large"
>
{contributor && !!contributor.website && (
<ExternalLink href={contributor.website}>
Expand Down
32 changes: 23 additions & 9 deletions src/components/molecules/Avatar/Avatar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,21 +43,35 @@ interface AvatarProps<S = LocationState> {
loading?: boolean;
}

const getUrlForSize = (
contributor: {
avatar?: AvatarType;
},
size: AvatarSize
): string | undefined => {
if (size === 'large') return contributor.avatar?.large.url;
if (size === 'normal') return contributor.avatar?.normal.url;
return contributor.avatar?.small.url;
};

const Avatar = ({
contributor,
size,
className,
onClick,
to,
loading
}: AvatarProps) => (
<Wrapper size={size} className={className} onClick={onClick} to={to}>
{!loading && contributor?.avatar && contributor.avatar[size].url ? (
<img src={contributor.avatar.normal.url} alt={contributor.name} />
) : (
<AvatarDefault />
)}
</Wrapper>
);
}: AvatarProps) => {
const url = contributor ? getUrlForSize(contributor, size) : '';
return (
<Wrapper size={size} className={className} onClick={onClick} to={to}>
{!loading && url ? (
<img src={url} alt={contributor?.name} />
) : (
<AvatarDefault />
)}
</Wrapper>
);
};

export default styled(Avatar)``;
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export const ContributorCompact = ({
className
}: Props) => (
<Wrapper className={className}>
<Avatar contributor={contributor} size="small" to={to} />
<Avatar contributor={contributor} size="normal" to={to} />

<ContributorInfos>
<UserName>
Expand Down
6 changes: 4 additions & 2 deletions src/components/organisms/Contributor/ContributorLarge.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import styled from 'styled-components';
import { LocationDescriptor, LocationState } from 'history';
import { StatefulContributor } from 'app/lmem/contributor';
import { AvatarSize, StatefulContributor } from 'app/lmem/contributor';
import Avatar from 'components/molecules/Avatar/Avatar';
import UserName from 'components/atoms/UserName/UserName';
import ContributorButton from './ContributorButton';
Expand Down Expand Up @@ -39,6 +39,7 @@ const ContributorIntro = styled.div.attrs<IntroProps>(

interface ContributorLargeProps<S = LocationState> {
contributor?: StatefulContributor;
avatarSize?: AvatarSize;
onSubscribe: () => void;
onUnsubscribe: () => void;
className?: string;
Expand All @@ -49,6 +50,7 @@ interface ContributorLargeProps<S = LocationState> {

const ContributorLarge = ({
contributor,
avatarSize,
onSubscribe,
onUnsubscribe,
children,
Expand All @@ -60,7 +62,7 @@ const ContributorLarge = ({
<>
<ContributorWrapper>
<Avatar
size="normal"
size={avatarSize || 'normal'}
contributor={contributor}
to={to}
loading={loading}
Expand Down
2 changes: 1 addition & 1 deletion src/components/organisms/NoticeDetails/NoticeDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ class NoticeDetails extends PureComponent<NoticeDetailsProps, CountDownState> {
<DetailsMeta>
<AvatarNotice
contributor={contributor}
size="small"
size="normal"
onClick={this.handleContributorClicked}
/>
<DetailsMetaValue>
Expand Down

0 comments on commit 61ab983

Please sign in to comment.