-
Notifications
You must be signed in to change notification settings - Fork 0
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
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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
withproject_id
, which isn't right.project_contents
id is needed, which available in projectlinks
.There was a problem hiding this comment.
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.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed now.