|
|
@@ -2,6 +2,8 @@ import React from 'react';
|
|
|
import md5 from 'md5';
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
|
|
+import { userPageRoot } from '@commons/util/path-utils';
|
|
|
+
|
|
|
const DEFAULT_IMAGE = '/images/icons/user.svg';
|
|
|
|
|
|
// TODO UserComponent?
|
|
|
@@ -49,6 +51,26 @@ export default class UserPicture extends React.Component {
|
|
|
);
|
|
|
}
|
|
|
|
|
|
+ RootElmWithoutLink = (props) => {
|
|
|
+ return <span {...props}>{props.children}</span>;
|
|
|
+ }
|
|
|
+
|
|
|
+ RootElmWithLink = (props) => {
|
|
|
+ const { user } = this.props;
|
|
|
+ const href = userPageRoot(user);
|
|
|
+
|
|
|
+ return <a href={href} {...props}>{props.children}</a>;
|
|
|
+ }
|
|
|
+
|
|
|
+ withTooltip = (RootElm) => {
|
|
|
+ const { user } = this.props;
|
|
|
+ const title = `@${user.username}<br />${user.name}`;
|
|
|
+
|
|
|
+ return props => (
|
|
|
+ <RootElm data-toggle="tooltip" data-placement="bottom" data-html="true" title={title}>{props.children}</RootElm>
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
render() {
|
|
|
const user = this.props.user;
|
|
|
|
|
|
@@ -56,18 +78,22 @@ export default class UserPicture extends React.Component {
|
|
|
return this.renderForNull();
|
|
|
}
|
|
|
|
|
|
- const imgElem = (
|
|
|
- <img
|
|
|
- src={this.getUserPicture(user)}
|
|
|
- alt={user.username}
|
|
|
- className={this.getClassName()}
|
|
|
- />
|
|
|
- );
|
|
|
+ const { noLink, noTooltip } = this.props;
|
|
|
+
|
|
|
+ // determine RootElm
|
|
|
+ let RootElm = noLink ? this.RootElmWithoutLink : this.RootElmWithLink;
|
|
|
+ if (!noTooltip) {
|
|
|
+ RootElm = this.withTooltip(RootElm);
|
|
|
+ }
|
|
|
|
|
|
return (
|
|
|
- (this.props.withoutLink)
|
|
|
- ? <span>{imgElem}</span>
|
|
|
- : <a href={`/user/${user.username}`}>{imgElem}</a>
|
|
|
+ <RootElm>
|
|
|
+ <img
|
|
|
+ src={this.getUserPicture(user)}
|
|
|
+ alt={user.username}
|
|
|
+ className={this.getClassName()}
|
|
|
+ />
|
|
|
+ </RootElm>
|
|
|
);
|
|
|
}
|
|
|
|
|
|
@@ -76,9 +102,12 @@ export default class UserPicture extends React.Component {
|
|
|
UserPicture.propTypes = {
|
|
|
user: PropTypes.object,
|
|
|
size: PropTypes.string,
|
|
|
- withoutLink: PropTypes.bool,
|
|
|
+ noLink: PropTypes.bool,
|
|
|
+ noTooltip: PropTypes.bool,
|
|
|
};
|
|
|
|
|
|
UserPicture.defaultProps = {
|
|
|
size: null,
|
|
|
+ noLink: false,
|
|
|
+ noTooltip: false,
|
|
|
};
|