2016-12-06 18:06:29 +01:00
|
|
|
import { Components, registerComponent } from 'meteor/nova:lib';
|
2016-03-28 12:36:29 +09:00
|
|
|
import React, { PropTypes, Component } from 'react';
|
2016-06-09 20:26:33 +09:00
|
|
|
import { FormattedMessage } from 'react-intl';
|
2016-06-23 15:00:58 +09:00
|
|
|
import Users from 'meteor/nova:users';
|
2016-06-30 12:05:59 +09:00
|
|
|
import { Link } from 'react-router';
|
2017-01-16 12:32:28 +09:00
|
|
|
import { ShowIf, withDocument, withCurrentUser } from 'meteor/nova:core';
|
2016-11-23 11:07:48 +09:00
|
|
|
import gql from 'graphql-tag';
|
2016-10-26 18:03:26 +09:00
|
|
|
|
2016-10-28 16:22:07 +09:00
|
|
|
const UsersProfile = (props) => {
|
2016-11-23 11:07:48 +09:00
|
|
|
if (props.loading) {
|
2016-12-09 09:55:07 +01:00
|
|
|
|
2017-01-16 12:32:28 +09:00
|
|
|
return <div className="page users-profile"><Components.Loading/></div>
|
2016-12-09 09:55:07 +01:00
|
|
|
|
2016-11-11 18:19:18 +09:00
|
|
|
} else {
|
|
|
|
|
2016-11-23 11:07:48 +09:00
|
|
|
const user = props.document;
|
2016-11-11 18:19:18 +09:00
|
|
|
|
|
|
|
const terms = {view: "userPosts", userId: user._id};
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="page users-profile">
|
2017-01-16 12:32:28 +09:00
|
|
|
<Components.HeadTags url={Users.getProfileUrl(user, true)} title={Users.getDisplayName(user)} />
|
2016-11-11 18:19:18 +09:00
|
|
|
<h2 className="page-title">{Users.getDisplayName(user)}</h2>
|
2017-01-18 10:18:33 +09:00
|
|
|
{user.htmlBio ? <div dangerouslySetInnerHTML={{__html: user.htmlBio}}></div> : null }
|
2016-11-11 18:19:18 +09:00
|
|
|
<ul>
|
2017-01-16 12:32:28 +09:00
|
|
|
{user.twitterUsername ? <li><a href={"http://twitter.com/" + user.twitterUsername}>@{user.twitterUsername}</a></li> : null }
|
2017-01-18 10:18:33 +09:00
|
|
|
{user.website ? <li><a href={user.website}>{user.website}</a></li> : null }
|
2017-01-18 12:51:10 +01:00
|
|
|
<Components.ShowIf check={Users.options.mutations.edit.check} document={user}>
|
2016-11-11 18:19:18 +09:00
|
|
|
<li><Link to={Users.getEditUrl(user)}><FormattedMessage id="users.edit_account"/></Link></li>
|
2017-01-18 12:51:10 +01:00
|
|
|
</Components.ShowIf>
|
2016-11-11 18:19:18 +09:00
|
|
|
</ul>
|
|
|
|
<h3><FormattedMessage id="users.posts"/></h3>
|
2016-12-06 18:06:29 +01:00
|
|
|
<Components.PostsList terms={terms} />
|
2016-11-11 18:19:18 +09:00
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
2016-03-28 12:36:29 +09:00
|
|
|
}
|
|
|
|
|
2016-04-19 15:54:53 +09:00
|
|
|
UsersProfile.propTypes = {
|
2016-11-11 18:19:18 +09:00
|
|
|
// document: React.PropTypes.object.isRequired,
|
2016-08-06 19:47:04 +02:00
|
|
|
}
|
|
|
|
|
2016-05-22 16:42:24 +09:00
|
|
|
UsersProfile.displayName = "UsersProfile";
|
|
|
|
|
2016-11-26 11:17:01 +09:00
|
|
|
UsersProfile.fragment = gql`
|
2017-01-16 12:32:28 +09:00
|
|
|
fragment usersProfileFragment on User {
|
2016-11-23 11:07:48 +09:00
|
|
|
_id
|
|
|
|
username
|
|
|
|
createdAt
|
|
|
|
isAdmin
|
2017-01-18 10:18:33 +09:00
|
|
|
bio
|
|
|
|
commentCount
|
|
|
|
displayName
|
|
|
|
downvotedComments {
|
2016-11-23 11:07:48 +09:00
|
|
|
itemId
|
|
|
|
power
|
|
|
|
votedAt
|
|
|
|
}
|
2017-01-18 10:18:33 +09:00
|
|
|
downvotedPosts {
|
2016-11-23 11:07:48 +09:00
|
|
|
itemId
|
|
|
|
power
|
|
|
|
votedAt
|
|
|
|
}
|
2017-01-18 10:18:33 +09:00
|
|
|
emailHash
|
|
|
|
groups
|
|
|
|
htmlBio
|
|
|
|
karma
|
|
|
|
newsletter_subscribeToNewsletter
|
|
|
|
notifications_users
|
|
|
|
notifications_posts
|
|
|
|
postCount
|
|
|
|
slug
|
2017-01-16 12:32:28 +09:00
|
|
|
twitterUsername
|
2017-01-18 10:18:33 +09:00
|
|
|
upvotedComments {
|
2016-11-23 11:07:48 +09:00
|
|
|
itemId
|
|
|
|
power
|
|
|
|
votedAt
|
|
|
|
}
|
2017-01-18 10:18:33 +09:00
|
|
|
upvotedPosts {
|
2016-11-23 11:07:48 +09:00
|
|
|
itemId
|
|
|
|
power
|
|
|
|
votedAt
|
|
|
|
}
|
2017-01-18 10:18:33 +09:00
|
|
|
website
|
2016-11-23 11:07:48 +09:00
|
|
|
}
|
|
|
|
`;
|
|
|
|
|
|
|
|
const options = {
|
|
|
|
collection: Users,
|
|
|
|
queryName: 'usersSingleQuery',
|
2016-11-26 11:17:01 +09:00
|
|
|
fragment: UsersProfile.fragment,
|
2016-11-23 11:07:48 +09:00
|
|
|
};
|
|
|
|
|
2017-01-16 12:32:28 +09:00
|
|
|
registerComponent('UsersProfile', UsersProfile, withCurrentUser, withDocument(options));
|