This file contains hidden or 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
class BookViewListMobileItem extends React.Component{ | |
constructor(){ | |
super(); | |
this.state = { expanded: false }; | |
} | |
toggle(){ | |
this.setState({ expanded: !this.state.expanded }); | |
} | |
render(){ | |
return ( |
This file contains hidden or 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
const editSubjects = Symbol('editSubjectStateCollection'); | |
class BookViewListDesktop extends React.Component{ | |
constructor(){ | |
super(); | |
this.state = { | |
booksSubjectsModalShown: false, | |
editSubjectsFor: [], | |
subjectsAdding: [], | |
subjectsRemoving: [] |
This file contains hidden or 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
function stackAndGetTopLevelSubjects(subjects){ | |
subjects.forEach(s => { | |
s.children = []; | |
s.children.push(...subjects.filter(sc => new RegExp(`,${s._id},$`).test(sc.path))); | |
}); | |
return subjects.filter(s => s.path == null); | |
} |
This file contains hidden or 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
function subjectsReducer(state = initialSubjectsState(), action = {}) { | |
switch (action.type) { | |
case LOAD_SUBJECTS_RESULTS: | |
return Object.assign({}, state, {list: stackAndGetTopLevelSubjects(action.subjects)}); | |
} | |
} |
This file contains hidden or 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
function subjectsReducer(state = initialSubjectsState(), action = {}){ | |
switch(action.type){ | |
case LOAD_SUBJECTS_RESULTS: | |
return Object.assign({}, state, { list: stackAndGetTopLevelSubjects(action.subjects) }); | |
case EDIT_SUBJECT: | |
var editingSubject = Object.assign({}, [...flattenedSubjects(state.list)].find(s => s._id == action._id)), | |
newSubjectParent; | |
var eligibleParents = [...flattenedSubjects(state.list)] | |
.filter(s => s._id !== action._id && (!new RegExp(`,${action._id},`).test(s.path))); |
This file contains hidden or 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
function subjectsReducer(state = initialSubjectsState(), action = {}){ | |
switch(action.type){ | |
case LOAD_SUBJECTS_RESULTS: | |
return Object.assign({}, state, { list: subjectsToHash(action.subjects) }); | |
} | |
return state; | |
} | |
function subjectsToHash(subjects){ | |
let hash = {}; |
This file contains hidden or 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
function subjectsReducer(state = initialSubjectsState(), action = {}){ | |
switch(action.type){ | |
case LOAD_SUBJECTS_RESULTS: | |
return Object.assign({}, state, { list: subjectsToHash(action.subjects) }); | |
case EDIT_SUBJECT: | |
var editingSubject = state.list[action._id], | |
newSubjectParent, | |
eligibleParents = flattenedSubjects(state.list).filter(s => s._id !== action._id && (!new RegExp(`,${action._id},`).test(s.path))); | |
if (editingSubject.path == null){ |
This file contains hidden or 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
const bookListSelector = state => ({ | |
subjects: Object.assign({}, state.bookList.subjects, {list: stackAndGetTopLevelSubjects(state.bookList.subjects.list)}), | |
books: Object.assign({}, state.bookList.books, {list: booksWithSubjectsSelector(state.bookList)}) | |
}); | |
function stackAndGetTopLevelSubjects(subjectsHash){ | |
let subjects = Object.keys(subjectsHash).map(_id => subjectsHash[_id]); | |
subjects.forEach(s => { | |
s.children = []; | |
s.children.push(...subjects.filter(sc => new RegExp(`,${s._id},$`).test(sc.path))); |
This file contains hidden or 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
const stackedSubjectsSelector = createSelector( | |
[state => state.list], | |
list => stackAndGetTopLevelSubjects(list) | |
); | |
const bookListSelector = state => ({ | |
subjects: Object.assign({}, state.bookList.subjects, {list: stackedSubjectsSelector(state.bookList.subjects)}), | |
books: Object.assign({}, state.bookList.books, {list: booksWithSubjectsSelector(state.bookList)}), | |
filters: state.bookList.filters | |
}); |
This file contains hidden or 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
const booksWithSubjectsSelector = createSelector( | |
[state => state.books.list, state => state.subjects.list], | |
setBookResultsSubjects | |
); | |
const stackedSubjectsSelector = createSelector( | |
[state => state.list], | |
stackAndGetTopLevelSubjects | |
); |
OlderNewer