2017-08-10 07:25:59 -04:00
|
|
|
import _ from 'underscore';
|
|
|
|
|
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];
|
|
|
|
|
2017-08-10 07:37:21 -04:00
|
|
|
export const getUserData = state => state.userData || {};
|
2017-08-02 12:19:06 -04:00
|
|
|
export const getUserDataByProp = state => prop => state.userData && state.userData[prop];
|
2017-07-25 15:01:53 -04:00
|
|
|
|
2017-07-28 14:59:31 -04:00
|
|
|
export const notesById = state => state.notes.reduce((acc, note) => {
|
|
|
|
note.notes.every(n => Object.assign(acc, { [n.id]: n }));
|
|
|
|
return acc;
|
|
|
|
}, {});
|
2017-07-28 13:43:19 -04:00
|
|
|
|
|
|
|
const reverseNotes = array => array.slice(0).reverse();
|
2017-08-11 07:51:41 -04:00
|
|
|
const isLastNote = (note, state) => !note.system &&
|
2017-08-18 12:02:21 -04:00
|
|
|
state.userData && note.author &&
|
2017-08-11 07:51:41 -04:00
|
|
|
note.author.id === state.userData.id;
|
|
|
|
|
|
|
|
export const getCurrentUserLastNote = state => _.flatten(
|
|
|
|
reverseNotes(state.notes)
|
|
|
|
.map(note => reverseNotes(note.notes)),
|
|
|
|
).find(el => isLastNote(el, state));
|
2017-07-28 13:43:19 -04:00
|
|
|
|
2017-08-10 07:25:59 -04:00
|
|
|
export const getDiscussionLastNote = state => discussion => reverseNotes(discussion.notes)
|
|
|
|
.find(el => isLastNote(el, state));
|