Skip to content

Commit 0f6a889

Browse files
committed
1 parent 601ba7d commit 0f6a889

File tree

4 files changed

+27
-15
lines changed

4 files changed

+27
-15
lines changed

src/shared/components/Avatar/index.jsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,14 @@
2020

2121
import PT from 'prop-types';
2222
import React from 'react';
23+
import _ from 'lodash';
2324
import { themr } from 'react-css-themr';
2425
import DefaultAvatar from '../../../assets/images/ico-user-default.svg';
2526
import defaultStyle from './style.scss';
2627

27-
function Avatar({ theme, url }) {
28+
function Avatar({ theme, url, handleError }) {
2829
return url
29-
? <img alt="Avatar" src={url} className={theme.avatar} />
30+
? <img alt="Avatar" src={url} className={theme.avatar} onError={handleError} />
3031
: <DefaultAvatar className={theme.avatar} />;
3132
}
3233

@@ -36,13 +37,15 @@ Avatar.defaultProps = {
3637
avatar: '',
3738
},
3839
url: null,
40+
handleError: _.noop,
3941
};
4042

4143
Avatar.propTypes = {
4244
theme: PT.shape({
4345
avatar: PT.string.isRequired,
4446
}),
4547
url: PT.string,
48+
handleError: PT.func,
4649
};
4750

4851
export default themr('Avatar', defaultStyle)(Avatar);

src/shared/components/LeaderboardAvatar/index.jsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import React, { Component } from 'react';
44
import PT from 'prop-types';
55
import './style.scss';
66

7+
import config from 'utils/config';
8+
79
// Constants
810
const VISIBLE_CHARACTERS = 3;
911
const MOCK_PHOTO = 'https://acrobatusers.com/assets/images/template/author_generic.jpg';
@@ -27,7 +29,7 @@ class LeaderboardAvatar extends Component {
2729
render() {
2830
const { domain, openNewTab, url } = this.props;
2931
const { member } = this.state;
30-
const targetURL = url || `//${domain}/members/${member.handle}`;
32+
const targetURL = url || `${domain}/members/${member.handle}`;
3133
return (
3234
<a
3335
href={targetURL}
@@ -50,7 +52,7 @@ class LeaderboardAvatar extends Component {
5052
}
5153

5254
LeaderboardAvatar.defaultProps = {
53-
domain: process.env.domain,
55+
domain: config.URL.BASE,
5456
member: {},
5557
openNewTab: false,
5658
url: '',

src/shared/components/challenge-listing/Tooltips/UserAvatarTooltip/index.jsx

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ import React, { Component } from 'react';
1111
import PT from 'prop-types';
1212
// import moment from 'moment';
1313
import Tooltip from 'components/Tooltip';
14-
import './style.scss';
14+
import Avatar from 'components/Avatar';
15+
import styles from './style.scss';
1516

16-
const MOCK_PHOTO = 'https://acrobatusers.com/assets/images/template/author_generic.jpg';
1717
/**
1818
* Renders the tooltip's content.
1919
* It includes: user profile picture, handle, his country and the TC registration
@@ -31,15 +31,19 @@ function Tip(props) {
3131
</span>
3232
)); */
3333
const { photoLink } = props.user;
34-
const src = photoLink.startsWith('https') ? photoLink : `${props.MAIN_URL}/${photoLink}`;
34+
let src = null;
35+
if (photoLink) {
36+
src = photoLink.startsWith('https') ? photoLink : `${props.MAIN_URL}/${photoLink}`;
37+
}
3538

3639
return (
3740
<div styleName="user-avatar-tooltip">
38-
<img
39-
alt="User avatar"
40-
styleName="avatar"
41-
src={src}
42-
onError={props.handleError}
41+
<Avatar
42+
theme={{
43+
avatar: styles.avatar,
44+
}}
45+
url={src}
46+
handleError={props.handleError}
4347
/>
4448
<div styleName="handle">{props.user.handle}</div>
4549
{/* Below block is commented out as it's not possible to get this information
@@ -86,7 +90,7 @@ class UserAvatarTooltip extends Component {
8690
}
8791
handleError() {
8892
const user = this.state.user;
89-
user.photoLink = MOCK_PHOTO;
93+
user.photoLink = null;
9094
this.setState({ user });
9195
}
9296

src/shared/components/challenge-listing/Tooltips/UserAvatarTooltip/style.scss

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ $avatar-radius-50: $corner-radius * 25;
88
$avatar-radius-4: $corner-radius * 2;
99

1010
.user-avatar-tooltip {
11+
display: flex;
12+
justify-content: space-between;
13+
align-items: center;
1114
max-width: 640px;
1215
font-family: 'Roboto';
1316
overflow: auto;
@@ -43,13 +46,13 @@ $avatar-radius-4: $corner-radius * 2;
4346

4447
.avatar {
4548
border-radius: $avatar-radius-50;
46-
float: left;
47-
margin-right: $avatar-space-15;
4849
width: $base-unit * 10;
4950
height: $base-unit * 10;
51+
overflow: hidden;
5052
}
5153

5254
.handle {
55+
margin-left: $avatar-space-15;
5356
display: inline-block;
5457
font-weight: 500;
5558
font-size: 20px;

0 commit comments

Comments
 (0)