From ea52c54e3a38ef37e0670878c5bf3d31e953e26f Mon Sep 17 00:00:00 2001 From: Brett Sun Date: Mon, 30 Nov 2015 11:27:15 +0100 Subject: [PATCH 1/2] Fix check for determining if a piece's edition list is open --- js/components/piece_list.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/js/components/piece_list.js b/js/components/piece_list.js index 3d4309f8..4a269aa8 100644 --- a/js/components/piece_list.js +++ b/js/components/piece_list.js @@ -130,7 +130,9 @@ let PieceList = React.createClass({ this.state.pieceList .forEach((piece) => { // but only if they're actually open - if(this.state.isEditionListOpenForPieceId[piece.id].show) { + const isEditionListOpenForPiece = this.state.isEditionListOpenForPieceId[piece.id]; + + if (isEditionListOpenForPiece && isEditionListOpenForPiece.show) { EditionListActions.refreshEditionList({ pieceId: piece.id, filterBy From 3d017392c10ad28fc3192a4b0a53ec8d9f241aa1 Mon Sep 17 00:00:00 2001 From: Brett Sun Date: Mon, 30 Nov 2015 11:32:48 +0100 Subject: [PATCH 2/2] Only use previous filterBy on refreshing edition lists if no filterBy argument was given MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Also fix the behaviour of refresh using the list’s current length rather than the previous page size. --- js/stores/edition_list_store.js | 43 ++++++++++----------------------- 1 file changed, 13 insertions(+), 30 deletions(-) diff --git a/js/stores/edition_list_store.js b/js/stores/edition_list_store.js index 4ccada4e..6b4d64f9 100644 --- a/js/stores/edition_list_store.js +++ b/js/stores/edition_list_store.js @@ -32,7 +32,7 @@ class EditionListStore { // page let storeEditionIndex = (page - 1) * pageSize + i; let editionsForPieces = this.editionList[pieceId]; - + // if edition already exists, just merge if(editionsForPieces[storeEditionIndex]) { editionsForPieces[storeEditionIndex] = React.addons.update(editionsForPieces[storeEditionIndex], {$merge: editionListOfPiece[i]}); @@ -60,46 +60,29 @@ class EditionListStore { * We often just have to refresh the edition list for a certain pieceId, * 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 // through /editions // 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. // Therefore we can just return, since there is no data to be refreshed - if(!this.editionList[pieceId]) { + if (!pieceEditionList) { 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 // http://davidwalsh.name/empty-array - this.editionList[pieceId].length = 0; + pieceEditionList.length = 0; - // refetch editions with adjusted page size - EditionsListActions.fetchEditionList(pieceId, 1, prevEditionListLength, - this.editionList[pieceId].orderBy, - this.editionList[pieceId].orderAsc, - filterBy) - .then(() => { - // reset back to the normal pageSize and page - this.editionList[pieceId].page = prevEditionListPage; - this.editionList[pieceId].pageSize = prevEditionListPageSize; - }) - .catch((err) => { - console.logGlobal(err); - }); + // refetch editions from the beginning with the previous settings + EditionsListActions + .fetchEditionList(pieceId, 1, pieceEditionList.pageSize, + pieceEditionList.orderBy, + pieceEditionList.orderAsc, + filterBy) + .catch(console.logGlobal); } onSelectEdition({pieceId, editionId, toValue}) {