Store original quantities, to avoid reordering in Inventory Items screen (#12205)

* Store original quantities, to avoid reordering

Create a quantity snapshot when loading the screen.
Sort based on the snapshot after updates.

Fixes: 12040

* Avoid initial branching

Co-authored-by: Bart Enkelaar <benkelaar@gmail.com>

* Add comment

Co-authored-by: Bart Enkelaar <benkelaar@gmail.com>
This commit is contained in:
Frank Maximus
2020-06-01 17:25:55 +02:00
committed by GitHub
parent 44eb245184
commit 3a4abac8b0

View File

@@ -419,6 +419,11 @@ export default {
cardType: '',
messageOptions: 0,
},
quantitySnapshot: {
eggs: null,
hatchingPotions: null,
food: null,
},
};
},
computed: {
@@ -443,7 +448,9 @@ export default {
if (itemQuantity > 0 && isAllowed) {
const item = contentItems[itemKey];
const isSearched = !searchText || item.text().toLowerCase().indexOf(searchText) !== -1;
const isSearched = !searchText || item.text()
.toLowerCase()
.indexOf(searchText) !== -1;
if (isSearched) {
itemsArray.push({
...item,
@@ -458,12 +465,16 @@ export default {
}
});
itemsArray.sort((a, b) => {
if (this.sortBy === 'quantity') {
return b.quantity - a.quantity;
} // AZ
return a.text.localeCompare(b.text);
});
// Store original quantities, to avoid reordering when using items.
const quantitySnapshot = this.quantitySnapshot[groupKey] || Object.fromEntries(
itemsArray.map(item => [item.key, item.quantity]),
);
itemsArray.sort((a, b) => quantitySnapshot[b.key] - quantitySnapshot[a.key]);
this.quantitySnapshot[groupKey] = quantitySnapshot;
} else {
itemsArray.sort((a, b) => a.text.localeCompare(b.text));
}
});
const specialArray = itemsByType.special;