Skip to content

Commit 7c48320

Browse files
author
David Silva
committed
Merge branch 'release/0.10.0'
2 parents 13b3982 + 9119484 commit 7c48320

File tree

7 files changed

+82
-22
lines changed

7 files changed

+82
-22
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Changelog
2+
3+
## 0.10.0
4+
5+
- displaying projects and submissions in profile page

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "codecorgi",
3-
"version": "0.9.1",
3+
"version": "0.10.0",
44
"private": true,
55
"proxy": "http://localhost:9500",
66
"devDependencies": {

src/components/challenges/list.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class ChallengesList extends Component {
1010

1111
render() {
1212
const { challenges } = this.props;
13-
13+
challenges.sort((a, b) => parseInt(a.attributes.number, 10) < parseInt(b.attributes.number, 10));
1414
return(
1515
<div>
1616
<TintedHeader title="Challenges" subtitle="These are all the available challenges" />

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/components/submit/list.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import React, { Component } from 'react';
2+
import PropTypes from 'prop-types';
3+
import { SubmitType } from '../../types';
4+
import { Link } from 'react-router-dom';
5+
import Moment from '../misc/moment';
6+
7+
class SubmitList extends Component {
8+
static propTypes = {
9+
submits: PropTypes.arrayOf(SubmitType),
10+
}
11+
12+
render() {
13+
const { submits } = this.props;
14+
15+
return(
16+
<div>
17+
{submits.map((s) => (
18+
s && s.attributes &&
19+
<div key={ s.id }>
20+
<p>Submission for: <strong> {s.attributes.challenge.number }&nbsp;</strong>
21+
<Link to={`/challenge/${s.attributes.challenge.number}/${ s.attributes.challenge.title }`}>{ s.attributes.challenge.title } </Link>
22+
</p>
23+
<p><strong>Description:</strong> { s.attributes.description }</p>
24+
<p>Submitted: <Moment date={ s.attributes.createdAt } /></p>
25+
<p>
26+
<Link to={`/submit/${ s.id }`} className="btn btn-primary">View Details</Link>
27+
</p>
28+
</div>
29+
))}
30+
</div>
31+
);
32+
}
33+
}
34+
35+
export default SubmitList;

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

src/containers/submit/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@ class ChallengeContainer extends Component {
2626
render() {
2727
const { challenge, submission, user } = this.props;
2828
return (
29-
<div>
29+
<div style={{ margin: '30px auto' }} >
3030
{submission && challenge && <Helmet>
3131
<title>{ `codecorgi | submission for: ${ challenge.title }` }</title>
3232
<meta property="og:title" content={ `codecorgi | submission for: ${ challenge.title }` } />
3333
<meta property="og:url" content={ `${PROD_URL}/${ challenge.url }` } />
3434
<meta name="twitter:title" content={ `codecorgi | submission for: ${ challenge.title }` } />
3535
</Helmet>}
36-
{submission && challenge &&
36+
{submission && challenge && user._id &&
3737
<SubmitDetails submission={ submission } challenge={ challenge } user={ user } />
3838
}
3939
</div>

0 commit comments

Comments
 (0)