1
0
mirror of https://github.com/ascribe/onion.git synced 2024-12-23 01:39:36 +01:00

Only use previous filterBy on refreshing edition lists if no filterBy argument was given

Also fix the behaviour of refresh using the list’s current length
rather than the previous page size.
This commit is contained in:
Brett Sun 2015-11-30 11:32:48 +01:00
parent ea52c54e3a
commit 3d017392c1

View File

@ -60,46 +60,29 @@ class EditionListStore {
* We often just have to refresh the edition list for a certain pieceId, * We often just have to refresh the edition list for a certain pieceId,
* this method provides exactly that functionality without any side effects * this method provides exactly that functionality without any side effects
*/ */
onRefreshEditionList({pieceId, filterBy}) { onRefreshEditionList({pieceId, filterBy = this.editionList[pieceId].filterBy}) {
const pieceEditionList = this.editionList[pieceId];
// It may happen that the user enters the site logged in already // It may happen that the user enters the site logged in already
// through /editions // through /editions
// If he then tries to delete a piece/edition and this method is called, // If he then tries to delete a piece/edition and this method is called,
// we'll not be able to refresh his edition list since its not yet there. // we'll not be able to refresh his edition list since its not yet there.
// Therefore we can just return, since there is no data to be refreshed // Therefore we can just return, since there is no data to be refreshed
if(!this.editionList[pieceId]) { if (!pieceEditionList) {
return; return;
} }
let prevEditionListLength = this.editionList[pieceId].length;
let prevEditionListPage = this.editionList[pieceId].page;
let prevEditionListPageSize = this.editionList[pieceId].pageSize;
// we can also refresh the edition list using filterBy,
// if we decide not to do that then the old filter will just be applied.
if(filterBy && Object.keys(filterBy).length <= 0) {
filterBy = this.editionList[pieceId].filterBy;
prevEditionListLength = 10;
prevEditionListPage = 1;
prevEditionListPageSize = 10;
}
// to clear an array, david walsh recommends to just set it's length to zero // to clear an array, david walsh recommends to just set it's length to zero
// http://davidwalsh.name/empty-array // http://davidwalsh.name/empty-array
this.editionList[pieceId].length = 0; pieceEditionList.length = 0;
// refetch editions with adjusted page size // refetch editions from the beginning with the previous settings
EditionsListActions.fetchEditionList(pieceId, 1, prevEditionListLength, EditionsListActions
this.editionList[pieceId].orderBy, .fetchEditionList(pieceId, 1, pieceEditionList.pageSize,
this.editionList[pieceId].orderAsc, pieceEditionList.orderBy,
filterBy) pieceEditionList.orderAsc,
.then(() => { filterBy)
// reset back to the normal pageSize and page .catch(console.logGlobal);
this.editionList[pieceId].page = prevEditionListPage;
this.editionList[pieceId].pageSize = prevEditionListPageSize;
})
.catch((err) => {
console.logGlobal(err);
});
} }
onSelectEdition({pieceId, editionId, toValue}) { onSelectEdition({pieceId, editionId, toValue}) {