File size: 2,877 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
// @flow
import React, { Component } from 'react';
import compose from 'recompose/compose';
import { connect } from 'react-redux';
import { withRouter } from 'react-router';
import AvatarImage from 'src/components/avatar/image';
import { Link } from 'react-router-dom';
import Badge from 'src/components/badges';
import { OutlineButton } from 'src/components/button';
import ConditionalWrap from 'src/components/conditionalWrap';
import type { GetUserType } from 'shared/graphql/queries/user/getUser';
import type { Dispatch } from 'redux';
import renderTextWithLinks from 'src/helpers/render-text-with-markdown-links';
import { withCurrentUser } from 'src/components/withCurrentUser';
import {
HoverWrapper,
ProfileCard,
CoverContainer,
CoverPhoto,
ProfilePhotoContainer,
Content,
Title,
Username,
Description,
Actions,
} from './style';
type ProfileProps = {
user: GetUserType,
dispatch: Dispatch<Object>,
currentUser: ?Object,
ref: (?HTMLElement) => void,
style: CSSStyleDeclaration,
};
class HoverProfile extends Component<ProfileProps> {
render() {
const { user, currentUser, ref, style } = this.props;
const me = currentUser && currentUser.id === user.id;
return (
<HoverWrapper popperStyle={style} ref={ref}>
<ProfileCard>
<ConditionalWrap
condition={!!user.username}
wrap={children => (
<Link to={`/users/${user.username}`}>{children}</Link>
)}
>
<CoverContainer>
<CoverPhoto src={user.coverPhoto ? user.coverPhoto : null} />
<ProfilePhotoContainer>
<AvatarImage
src={user.profilePhoto}
alt={user.name}
type={'user'}
size={40}
/>
</ProfilePhotoContainer>
</CoverContainer>
</ConditionalWrap>
<Content>
<ConditionalWrap
condition={!!user.username}
wrap={children => (
<Link to={`/users/${user.username}`}>{children}</Link>
)}
>
<Title>{user.name}</Title>
<Username>@{user.username}</Username>
</ConditionalWrap>
{user.betaSupporter && (
<span style={{ display: 'inline-block', marginBottom: '4px' }}>
<Badge type="beta-supporter" />
</span>
)}
{user.description && (
<Description>{renderTextWithLinks(user.description)}</Description>
)}
</Content>
<Actions>
{me && <OutlineButton to={'/me'}>My profile</OutlineButton>}
</Actions>
</ProfileCard>
</HoverWrapper>
);
}
}
export default compose(
withCurrentUser,
withRouter,
connect()
)(HoverProfile);
|