Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Project listing #1

Merged
merged 3 commits into from
May 30, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/components/ProjectContents.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ options.log = (test) => {
class ProjectContents extends Component {
render() {
const { contents } = this.props;
const data = contents.data;
const project_contents = contents.data.length ? contents.data[0] : {};
return (
<div>
<h2>Project Contents</h2>
<p>Title: { data.title }</p>
<p>Description: { data.description }</p>
<p>Introduction: { data.introduction }</p>
<p>Language: { data.language}</p>
<p>Title: { project_contents.title }</p>
<p>Description: { project_contents.description }</p>
<p>Introduction: { project_contents.introduction }</p>
<p>Language: { project_contents.language}</p>
</div>
);
}
Expand Down
40 changes: 40 additions & 0 deletions src/components/ProjectList.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import fixIt, { options } from 'react-fix-it';
import { Link } from 'react-router';

const propTypes = {
projects: PropTypes.object.isRequired,
};

function ProjectListItem(props) {
return(
<li key={props.project.id}>
<Link to={`/project/${props.project.id}`} >{props.project.display_name}</Link>
</li>
);
}
class ProjectList extends Component {

render() {
const { projects } = this.props;
return (
<div>
<h2>Projects</h2>
<ul>
{projects.data.map(project => <ProjectListItem project={project} />)}
</ul>
</div>
);
}
}

ProjectList.propTypes = propTypes;

ProjectList.defaultProps = {
projects: {
data: []
}
}

export default fixIt(ProjectList);
2 changes: 1 addition & 1 deletion src/containers/ProjectContentsContainer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class ProjectContentsContainer extends Component {
}
componentDidMount() {
const { actions } = this.props;
return actions.fetchProjectContents();
return actions.fetchProjectContents(this.props.params.project_id);
}

handleClick(event) {
Expand Down
49 changes: 49 additions & 0 deletions src/containers/ProjectListContainer.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { connect } from 'react-redux';
import { bindActionCreators } from 'redux';

import * as projectsActions from '../ducks/projects';

import ProjectList from '../components/ProjectList';

const propTypes = {
actions: PropTypes.object.isRequired,
projects: PropTypes.object.isRequired,
};

class ProjectListContainer extends Component {

componentDidMount() {
const { actions } = this.props;
actions.fetchProjects();
}

render() {
const { projects } = this.props;
return (
<ProjectList projects={projects} />
);
}
}

const mapStateToProps = (state) => ({
projects: state.projects,
});

const mapDispatchToProps = (dispatch) => ({
actions: bindActionCreators(projectsActions, dispatch),
});

ProjectListContainer.propTypes = propTypes;

ProjectListContainer.defaultProps = {
projects: {
data: []
}
}

export default connect(
mapStateToProps,
mapDispatchToProps,
)(ProjectListContainer);
5 changes: 3 additions & 2 deletions src/ducks/contents.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,13 @@ const projectContentsReducer = (state = initialState, action) => {
};

// Action Creators
const fetchProjectContents = () => {
const fetchProjectContents = (project_id) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're requesting project_contents with project_id, which isn't right. project_contents id is needed, which available in project links.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My bad, this should actually be requesting a list of all ProjectContents resources for a given project, then listing them by language.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed now.

return (dispatch) => {
dispatch({
type: FETCH_PROJECT_CONTENTS,
});
apiClient.type('project_contents').get('1727')
const query = { project_id };
apiClient.type('project_contents').get(query)
.then((projectContents) => {
dispatch({
type: FETCH_PROJECT_CONTENTS_SUCCESS,
Expand Down
52 changes: 52 additions & 0 deletions src/ducks/projects.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import apiClient from 'panoptes-client/lib/api-client';

// Action Types
export const FETCH_PROJECTS = 'FETCH_PROJECTS';
export const FETCH_PROJECTS_SUCCESS = 'FETCH_PROJECTS_SUCCESS';
export const FETCH_PROJECTS_ERROR = 'FETCH_PROJECTS_ERROR';

// Reducer
const initialState = {
data: [],
error: false,
loading: false,
};

const projectsReducer = (state = initialState, action) => {
switch (action.type) {
case FETCH_PROJECTS:
return Object.assign({}, initialState, { loading: true });
case FETCH_PROJECTS_SUCCESS:
return Object.assign({}, state, { data: action.payload, loading: false });
case FETCH_PROJECTS_ERROR:
return Object.assign({}, state, { error: action.payload, loading: false });
default:
return state;
}
};

// Action Creators
const fetchProjects = () => {
return (dispatch) => {
dispatch({
type: FETCH_PROJECTS,
});
const query = {
current_user_roles: ['owner', 'translator']
}
apiClient.type('projects').get(query)
.then((projects) => {
dispatch({
type: FETCH_PROJECTS_SUCCESS,
payload: projects,
});
});
};
};

// Exports
export default projectsReducer;

export {
fetchProjects
};
2 changes: 2 additions & 0 deletions src/ducks/reducer.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { combineReducers } from 'redux';
import contents from './contents';
import login from './login';
import projects from './projects';

export default combineReducers({
contents,
login,
projects
});
4 changes: 3 additions & 1 deletion src/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import About from './components/About';
import config from './config';
import configureStore from './store';
import ProjectContents from './containers/ProjectContentsContainer';
import ProjectList from './containers/ProjectListContainer';

// Todo: let's find a better way to include Styles,
// currently Styles looks like an unused var to eslint
Expand All @@ -22,7 +23,8 @@ oauth.init(config.panoptesAppId)
<Provider store={store}>
<Router history={browserHistory}>
<Route path="/" component={App}>
<IndexRoute component={ProjectContents} />
<IndexRoute component={ProjectList} />
<Route path="/project/:project_id" component={ProjectContents} />
<Route path="/about" component={About} />
</Route>
</Router>
Expand Down