2017-07-25 15:01:53 -04:00
|
|
|
export const notes = state => state.notes;
|
|
|
|
export const targetNoteHash = state => state.targetNoteHash;
|
2017-07-28 05:46:46 -04:00
|
|
|
|
|
|
|
export const getNotesData = state => state.notesData;
|
2017-07-27 16:24:05 -04:00
|
|
|
export const getNotesDataByProp = state => prop => state.notesData[prop];
|
2017-07-28 05:46:46 -04:00
|
|
|
|
|
|
|
export const getIssueData = state => state.issueData;
|
|
|
|
export const getIssueDataByProp = state => prop => state.issueData[prop];
|
|
|
|
|
|
|
|
export const getUserData = state => state.userData;
|
2017-07-27 16:24:05 -04:00
|
|
|
export const getUserDataByProp = state => prop => state.notesData[prop];
|
2017-07-25 15:01:53 -04:00
|
|
|
|
|
|
|
export const notesById = (state) => {
|
|
|
|
const notesByIdObject = {};
|
2017-07-27 16:24:05 -04:00
|
|
|
// TODO: FILIPA: TRANSFORM INTO A REDUCE
|
2017-07-25 15:01:53 -04:00
|
|
|
state.notes.forEach((note) => {
|
|
|
|
note.notes.forEach((n) => {
|
|
|
|
notesByIdObject[n.id] = n;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
return notesByIdObject;
|
|
|
|
};
|
2017-07-28 13:43:19 -04:00
|
|
|
|
|
|
|
const reverseNotes = array => array.slice(0).reverse();
|
|
|
|
const isLastNote = (note, userId) => !note.system && note.author.id === userId;
|
|
|
|
|
|
|
|
export const getCurrentUserLastNote = state => userId => reverseNotes(state.notes)
|
|
|
|
.reduce((acc, note) => {
|
|
|
|
acc.push(reverseNotes(note.notes).find(el => isLastNote(el, userId)));
|
|
|
|
return acc;
|
|
|
|
}, []).filter(el => el !== undefined)[0];
|
|
|
|
|
2017-07-28 13:48:13 -04:00
|
|
|
export const getDiscussionLastNote = state => (discussion, userId) => reverseNotes(discussion.notes)
|
2017-07-28 13:43:19 -04:00
|
|
|
.find(el => isLastNote(el, userId));
|
|
|
|
|