Skip to content
Snippets Groups Projects
Commit 864e0a4d authored by Chris Lawton's avatar Chris Lawton Committed by Todd Dembrey
Browse files

sort notes by timestamp

parent 41fc9077
No related branches found
No related tags found
No related merge requests found
...@@ -10,13 +10,13 @@ import Note from '@containers/Note'; ...@@ -10,13 +10,13 @@ import Note from '@containers/Note';
import { import {
getNotesErrorState, getNotesErrorState,
getNotesErrorMessage, getNotesErrorMessage,
getNoteIDsForSubmissionOfID, getNotesForSubmission,
getNotesFetchState, getNotesFetchState,
getNoteEditingStateForSubmission getNoteEditingStateForSubmission
} from '@selectors/notes'; } from '@selectors/notes';
const NoteListing = ({ loadNotes, submissionID, noteIDs, isErrored, errorMessage, isLoading, editing }) => { const NoteListing = ({ loadNotes, submissionID, notes, isErrored, errorMessage, isLoading, editing }) => {
const fetchNotes = () => loadNotes(submissionID) const fetchNotes = () => loadNotes(submissionID)
const {start, stop } = useInterval(fetchNotes, 30000) const {start, stop } = useInterval(fetchNotes, 30000)
...@@ -37,7 +37,9 @@ const NoteListing = ({ loadNotes, submissionID, noteIDs, isErrored, errorMessage ...@@ -37,7 +37,9 @@ const NoteListing = ({ loadNotes, submissionID, noteIDs, isErrored, errorMessage
} }
} }
const renderItem = noteID => <Note key={`note-${noteID}`} noteID={noteID} submissionID={submissionID} disabled={!!editing} />; const orderedNotes = notes.sort((a,b) => a.timestamp - b.timestamp);
const renderItem = note => <Note key={`note-${note.id}`} noteID={note.id} submissionID={submissionID} disabled={!!editing} />;
return ( return (
<Listing <Listing
...@@ -46,7 +48,7 @@ const NoteListing = ({ loadNotes, submissionID, noteIDs, isErrored, errorMessage ...@@ -46,7 +48,7 @@ const NoteListing = ({ loadNotes, submissionID, noteIDs, isErrored, errorMessage
errorMessage={ errorMessage } errorMessage={ errorMessage }
handleRetry={ handleRetry } handleRetry={ handleRetry }
renderItem={ renderItem } renderItem={ renderItem }
items={ noteIDs } items={ orderedNotes }
column="notes" column="notes"
/> />
); );
...@@ -55,7 +57,7 @@ const NoteListing = ({ loadNotes, submissionID, noteIDs, isErrored, errorMessage ...@@ -55,7 +57,7 @@ const NoteListing = ({ loadNotes, submissionID, noteIDs, isErrored, errorMessage
NoteListing.propTypes = { NoteListing.propTypes = {
loadNotes: PropTypes.func, loadNotes: PropTypes.func,
submissionID: PropTypes.number, submissionID: PropTypes.number,
noteIDs: PropTypes.array, notes: PropTypes.array,
isErrored: PropTypes.bool, isErrored: PropTypes.bool,
errorMessage: PropTypes.string, errorMessage: PropTypes.string,
isLoading: PropTypes.bool, isLoading: PropTypes.bool,
...@@ -68,7 +70,7 @@ const mapDispatchToProps = dispatch => ({ ...@@ -68,7 +70,7 @@ const mapDispatchToProps = dispatch => ({
}); });
const mapStateToProps = (state, ownProps) => ({ const mapStateToProps = (state, ownProps) => ({
noteIDs: getNoteIDsForSubmissionOfID(ownProps.submissionID)(state), notes: getNotesForSubmission(ownProps.submissionID)(state),
isLoading: getNotesFetchState(state), isLoading: getNotesFetchState(state),
isErrored: getNotesErrorState(state), isErrored: getNotesErrorState(state),
errorMessage: getNotesErrorMessage(state), errorMessage: getNotesErrorMessage(state),
......
...@@ -24,6 +24,11 @@ export const getLatestNoteForSubmissionOfID = submissionID => createSelector( ...@@ -24,6 +24,11 @@ export const getLatestNoteForSubmissionOfID = submissionID => createSelector(
notes => notes[0] || null notes => notes[0] || null
); );
export const getNotesForSubmission = submissionID => createSelector(
[getNoteIDsForSubmissionOfID(submissionID), getNotes],
(noteIDs, notes) => noteIDs.map(noteID => notes[noteID])
);
const getNoteCreatingErrors = state => state.notes.createError; const getNoteCreatingErrors = state => state.notes.createError;
export const getNoteCreatingErrorForSubmission = submissionID => createSelector( export const getNoteCreatingErrorForSubmission = submissionID => createSelector(
......
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