Skip to content

Commit f664343

Browse files
author
David Silva
committed
displaying the user submissions in their profile
1 parent f155e9b commit f664343

File tree

2 files changed

+38
-18
lines changed

2 files changed

+38
-18
lines changed

src/components/profile/index.js

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,23 @@
11
import React from 'react';
2-
import { ProfileType } from '../../types';
2+
import { ProfileType, SubmitType } from '../../types';
33
import PropTypes from 'prop-types';
44
import { Link } from 'react-router-dom';
55
import corgiImg from '../../assets/images/team/corginson.png';
66
import bgImage from '../../assets/images/art/pattern-background03.png';
77
import { Helmet } from 'react-helmet';
88
import { PROD_URL, BACKEND_URL } from '../../constants';
99
import ReactMarkdown from 'react-markdown';
10+
import SubmitList from '../submit/list';
1011

1112
class ProfileComponent extends React.Component {
1213
static propTypes = {
1314
profile: ProfileType,
1415
self: PropTypes.bool.isRequired,
16+
submits: PropTypes.arrayOf( SubmitType ),
1517
}
1618

1719
render() {
18-
const { profile, self } = this.props;
20+
const { profile, self, submits } = this.props;
1921
return (
2022
<div className="profile-container">
2123
<Helmet>
@@ -50,23 +52,33 @@ class ProfileComponent extends React.Component {
5052
</div>
5153
</div>
5254
</section>
53-
<section className="container profile-body">
55+
<section className="container profile-body" style={{ margin: '30px auto' }}>
5456
<div className="row">
5557
<div className="col-xs-12">
5658
<ReactMarkdown source={ profile.profile.bio } />
5759
</div>
5860
</div>
59-
{profile.projects && profile.projects.length > 0 && <div className="row">
60-
<h3>Projects</h3>
61-
<div className="col-xs-12">
62-
{profile.projects.map((p, index) => (
63-
<div className="project" key={ index }>
64-
<p><Link to={p.url} target="_blank">{ p.name }</Link></p>
65-
<p>{ p.description }</p>
66-
</div>
67-
))}
61+
{submits && submits.length > 0 &&
62+
<div className="row" style={{ marginBottom: '30px' }}>
63+
<h3>Submissions</h3>
64+
<div className="col-xs-12">
65+
<SubmitList submits={ submits } />
66+
</div>
67+
</div>
68+
}
69+
{profile.projects && profile.projects.length > 0 &&
70+
<div className="row" style={{ marginBottom: '30px' }}>
71+
<h3>Projects</h3>
72+
<div className="col-xs-12">
73+
{profile.projects.map((p, index) => (
74+
<div className="project" key={ index }>
75+
<p><Link to={p.url} target="_blank">{ p.name }</Link></p>
76+
<p>{ p.description }</p>
77+
</div>
78+
))}
79+
</div>
6880
</div>
69-
</div>}
81+
}
7082
</section>
7183
</div>
7284
);

src/containers/profile/index.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import React from 'react';
22
import { connect } from 'react-redux';
3-
import { ProfileType } from '../../types';
3+
import { ProfileType, SubmitType } from '../../types';
44
import ReactRouterPropTypes from 'react-router-prop-types';
55
import { readEndpoint } from 'redux-json-api';
66
import PropTypes from 'prop-types';
77
import { bindActionCreators } from 'redux';
88
import E404 from '../404/';
99
import ProfileComponent from '../../components/profile';
10+
import _get from 'lodash/get';
1011

1112
class Profile extends React.Component {
1213
static propTypes = {
@@ -15,6 +16,7 @@ class Profile extends React.Component {
1516
match: ReactRouterPropTypes.match,
1617
username: PropTypes.string,
1718
self: PropTypes.bool.isRequired,
19+
submits: PropTypes.arrayOf(SubmitType),
1820
}
1921

2022
constructor(props) {
@@ -25,32 +27,38 @@ class Profile extends React.Component {
2527
}
2628

2729
componentWillMount() {
28-
this.props.readEndpoint(`profile/${this.props.username || ''}`).then(() => {
30+
this.props.readEndpoint(`profile/${this.props.username || ''}`).then((r) => {
2931
this.setState({ loading: false });
32+
const user = _get(r, 'body.data[0]', null);
33+
if (user) {
34+
this.props.readEndpoint(`submit/all/user/${ user.id }`);
35+
}
3036
});
3137
}
3238

3339
render() {
34-
const { profile, self } = this.props;
40+
const { profile, self, submits } = this.props;
3541
return(
3642
<div>
37-
{!this.state.loading && this.props.profile && <ProfileComponent profile={profile} self={self} />}
43+
{!this.state.loading && this.props.profile && <ProfileComponent profile={profile} self={self} submits={ submits }/>}
3844
{!this.state.loading && !this.props.profile && <E404 />}
3945
</div>);
4046
}
4147
}
4248

4349
const mapStateToProps = (state, ownProps) => {
4450
const { profile, api } = state;
45-
const { users = {data: [] }} = api;
51+
const { users = {data: [] }, submit = {data: []} } = api;
4652

4753
const username = ownProps.match.params.username ? ownProps.match.params.username : profile.username;
4854
const user = users.data.find((u) => u.attributes.username === username);
55+
const submits = submit.data.filter(s => s.attributes._user === user.id);
4956

5057
return {
5158
profile: user ? user.attributes : undefined,
5259
username,
5360
self: !ownProps.match.params.username || ownProps.match.params.username === profile.username,
61+
submits,
5462
};
5563
};
5664

0 commit comments

Comments
 (0)