Skip to content
Snippets Groups Projects
Commit 8df4bd37 authored by Tomasz Knapik's avatar Tomasz Knapik Committed by Todd Dembrey
Browse files

Add on click handler on submissions listing

parent e7f69509
No related branches found
No related tags found
No related merge requests found
...@@ -9,7 +9,7 @@ import './style.scss'; ...@@ -9,7 +9,7 @@ import './style.scss';
export default class Listing extends React.Component { export default class Listing extends React.Component {
renderListItems() { renderListItems() {
const { isLoading, isError, items } = this.props; const { isLoading, isError, items, onItemSelection } = this.props;
if (isLoading) { if (isLoading) {
return <p>Loading...</p>; return <p>Loading...</p>;
...@@ -25,7 +25,7 @@ export default class Listing extends React.Component { ...@@ -25,7 +25,7 @@ export default class Listing extends React.Component {
return ( return (
<ListingGroup key={`listing-group-${v.group}`} item={v}> <ListingGroup key={`listing-group-${v.group}`} item={v}>
{v.items.map(item => { {v.items.map(item => {
return <ListingItem key={`listing-item-${item.id}`} item={item}/>; return <ListingItem onClick={onItemSelection} key={`listing-item-${item.id}`} item={item}/>;
})} })}
</ListingGroup> </ListingGroup>
); );
...@@ -75,4 +75,5 @@ Listing.propTypes = { ...@@ -75,4 +75,5 @@ Listing.propTypes = {
isError: PropTypes.bool, isError: PropTypes.bool,
groupBy: PropTypes.string, groupBy: PropTypes.string,
order: PropTypes.arrayOf(PropTypes.string), order: PropTypes.arrayOf(PropTypes.string),
onItemSelection: PropTypes.func,
}; };
...@@ -4,9 +4,12 @@ import PropTypes from 'prop-types'; ...@@ -4,9 +4,12 @@ import PropTypes from 'prop-types';
export default class ListingItem extends React.Component { export default class ListingItem extends React.Component {
render() { render() {
const { onClick, item } = this.props;
return ( return (
<li className="listing__item"> <li className="listing__item">
<a className="listing__link">{this.props.item.title}</a> <a className="listing__link" onClick={() => onClick(item.id)}>
{item.title}
</a>
</li> </li>
); );
} }
...@@ -16,4 +19,5 @@ ListingItem.propTypes = { ...@@ -16,4 +19,5 @@ ListingItem.propTypes = {
item: PropTypes.shape({ item: PropTypes.shape({
title: PropTypes.string, title: PropTypes.string,
}), }),
onClick: PropTypes.func,
}; };
...@@ -3,13 +3,17 @@ import PropTypes from 'prop-types'; ...@@ -3,13 +3,17 @@ import PropTypes from 'prop-types';
import { connect } from 'react-redux' import { connect } from 'react-redux'
import Listing from '@components/Listing'; import Listing from '@components/Listing';
import {
fetchSubmissionsByRound,
setCurrentSubmission,
setCurrentSubmissionRound,
} from '@actions/submissions';
import { import {
getCurrentRoundID, getCurrentRoundID,
getCurrentRoundSubmissions, getCurrentRoundSubmissions,
getSubmissionsByRoundErrorState, getSubmissionsByRoundErrorState,
getSubmissionsByRoundLoadingState, getSubmissionsByRoundLoadingState,
} from '@selectors/submissions'; } from '@selectors/submissions';
import { setCurrentSubmissionRound, fetchSubmissionsByRound } from '@actions/submissions';
class ByStatusListing extends React.Component { class ByStatusListing extends React.Component {
...@@ -30,11 +34,12 @@ class ByStatusListing extends React.Component { ...@@ -30,11 +34,12 @@ class ByStatusListing extends React.Component {
} }
render() { render() {
const { isLoading, isError } = this.props; const { isLoading, isError, items, setCurrentItem } = this.props;
return <Listing return <Listing
isLoading={isLoading} isLoading={isLoading}
isError={isError} isError={isError}
items={this.props.items} items={items}
onItemSelection={setCurrentItem}
groupBy={'status'} groupBy={'status'}
order={[ order={[
// TODO: Set the proper order of statuses. // TODO: Set the proper order of statuses.
...@@ -60,6 +65,7 @@ const mapStateToProps = state => ({ ...@@ -60,6 +65,7 @@ const mapStateToProps = state => ({
const mapDispatchToProps = dispatch => ({ const mapDispatchToProps = dispatch => ({
loadSubmissions: id => dispatch(fetchSubmissionsByRound(id)), loadSubmissions: id => dispatch(fetchSubmissionsByRound(id)),
setCurrentItem: id => dispatch(setCurrentSubmission(id)),
}); });
ByStatusListing.propTypes = { ByStatusListing.propTypes = {
......
...@@ -3,6 +3,7 @@ import api from '@api'; ...@@ -3,6 +3,7 @@ import api from '@api';
// Submissions by round // Submissions by round
export const SET_CURRENT_SUBMISSION_ROUND = 'SET_CURRENT_SUBMISSION_ROUND'; export const SET_CURRENT_SUBMISSION_ROUND = 'SET_CURRENT_SUBMISSION_ROUND';
export const SET_CURRENT_SUBMISSION = 'SET_CURRENT_SUBMISSION';
export const UPDATE_SUBMISSIONS_BY_ROUND = 'UPDATE_SUBMISSIONS_BY_ROUND'; export const UPDATE_SUBMISSIONS_BY_ROUND = 'UPDATE_SUBMISSIONS_BY_ROUND';
export const START_LOADING_SUBMISSIONS_BY_ROUND = 'START_LOADING_SUBMISSIONS_BY_ROUND'; export const START_LOADING_SUBMISSIONS_BY_ROUND = 'START_LOADING_SUBMISSIONS_BY_ROUND';
export const FAIL_LOADING_SUBMISSIONS_BY_ROUND = 'FAIL_LOADING_SUBMISSIONS_BY_ROUND'; export const FAIL_LOADING_SUBMISSIONS_BY_ROUND = 'FAIL_LOADING_SUBMISSIONS_BY_ROUND';
...@@ -13,20 +14,25 @@ export const setCurrentSubmissionRound = id => ({ ...@@ -13,20 +14,25 @@ export const setCurrentSubmissionRound = id => ({
id, id,
}); });
export const setCurrentSubmission = id => ({
type: SET_CURRENT_SUBMISSION,
id,
});
export const fetchSubmissionsByRound = roundId => { export const fetchSubmissionsByRound = roundId => {
return async function(dispatch) { return async function(dispatch) {
dispatch(startLoadingSubmissionsByRound(roundId)); dispatch(startLoadingSubmissionsByRound());
try { try {
const response = await api.fetchSubmissionsByRound(roundId); const response = await api.fetchSubmissionsByRound(roundId);
const json = await response.json(); const json = await response.json();
if (!response.ok) { if (!response.ok) {
dispatch(failLoadingSubmissionsByRound(roundId)); dispatch(failLoadingSubmissionsByRound());
return; return;
} }
dispatch(updateSubmissionsByRound(roundId, json)); dispatch(updateSubmissionsByRound(roundId, json));
} catch (e) { } catch (e) {
console.error(e); console.error(e);
dispatch(failLoadingSubmissionsByRound(roundId)); dispatch(failLoadingSubmissionsByRound());
} }
}; };
}; };
...@@ -39,14 +45,12 @@ const updateSubmissionsByRound = (roundId, data) => ({ ...@@ -39,14 +45,12 @@ const updateSubmissionsByRound = (roundId, data) => ({
}); });
const startLoadingSubmissionsByRound = roundId => ({ const startLoadingSubmissionsByRound = () => ({
type: START_LOADING_SUBMISSIONS_BY_ROUND, type: START_LOADING_SUBMISSIONS_BY_ROUND,
roundId,
}); });
const failLoadingSubmissionsByRound = roundId => ({ const failLoadingSubmissionsByRound = () => ({
type: FAIL_LOADING_SUBMISSIONS_BY_ROUND, type: FAIL_LOADING_SUBMISSIONS_BY_ROUND,
roundId,
}); });
import { import {
FAIL_LOADING_SUBMISSIONS_BY_ROUND, FAIL_LOADING_SUBMISSIONS_BY_ROUND,
SET_CURRENT_SUBMISSION,
SET_CURRENT_SUBMISSION_ROUND, SET_CURRENT_SUBMISSION_ROUND,
START_LOADING_SUBMISSIONS_BY_ROUND, START_LOADING_SUBMISSIONS_BY_ROUND,
UPDATE_SUBMISSIONS_BY_ROUND, UPDATE_SUBMISSIONS_BY_ROUND,
...@@ -7,6 +8,7 @@ import { ...@@ -7,6 +8,7 @@ import {
const initialState = { const initialState = {
currentRound: null, currentRound: null,
currenSubmission: null,
submissionsByID: {}, submissionsByID: {},
submissionsByRoundID: {}, submissionsByRoundID: {},
itemsLoadingError: false, itemsLoadingError: false,
...@@ -15,6 +17,11 @@ const initialState = { ...@@ -15,6 +17,11 @@ const initialState = {
export default function submissions(state = initialState, action) { export default function submissions(state = initialState, action) {
switch(action.type) { switch(action.type) {
case SET_CURRENT_SUBMISSION:
return {
...state,
currentSubmission: action.id,
};
case SET_CURRENT_SUBMISSION_ROUND: case SET_CURRENT_SUBMISSION_ROUND:
return { return {
...state, ...state,
......
Source diff could not be displayed: it is too large. Options to address this: view the blob.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment