mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-19 07:37:25 +01:00
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:
@@ -419,6 +419,11 @@ export default {
|
|||||||
cardType: '',
|
cardType: '',
|
||||||
messageOptions: 0,
|
messageOptions: 0,
|
||||||
},
|
},
|
||||||
|
quantitySnapshot: {
|
||||||
|
eggs: null,
|
||||||
|
hatchingPotions: null,
|
||||||
|
food: null,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
@@ -443,7 +448,9 @@ export default {
|
|||||||
if (itemQuantity > 0 && isAllowed) {
|
if (itemQuantity > 0 && isAllowed) {
|
||||||
const item = contentItems[itemKey];
|
const item = contentItems[itemKey];
|
||||||
|
|
||||||
const isSearched = !searchText || item.text().toLowerCase().indexOf(searchText) !== -1;
|
const isSearched = !searchText || item.text()
|
||||||
|
.toLowerCase()
|
||||||
|
.indexOf(searchText) !== -1;
|
||||||
if (isSearched) {
|
if (isSearched) {
|
||||||
itemsArray.push({
|
itemsArray.push({
|
||||||
...item,
|
...item,
|
||||||
@@ -458,12 +465,16 @@ export default {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
itemsArray.sort((a, b) => {
|
|
||||||
if (this.sortBy === 'quantity') {
|
if (this.sortBy === 'quantity') {
|
||||||
return b.quantity - a.quantity;
|
// Store original quantities, to avoid reordering when using items.
|
||||||
} // AZ
|
const quantitySnapshot = this.quantitySnapshot[groupKey] || Object.fromEntries(
|
||||||
return a.text.localeCompare(b.text);
|
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;
|
const specialArray = itemsByType.special;
|
||||||
|
|||||||
Reference in New Issue
Block a user