mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-15 21:57:22 +01:00
Multiple checks for pinnedItems (#11031)
* remove null/undefined entries from pinnedItems when an item is toggled - more inner checks + test * drawer: fix when there isn't a page available * rollback cleaning up pinnedEntries on item-toggle * remove "re-setting" pinnedItems * remove the filter
This commit is contained in:
@@ -27,6 +27,15 @@ function pathExistsInArray (array, path) {
|
||||
});
|
||||
}
|
||||
|
||||
function checkForNullEntries (array) {
|
||||
return array.filter(e => Boolean(e));
|
||||
}
|
||||
|
||||
function checkPinnedAreasForNullEntries (user) {
|
||||
user.pinnedItems = checkForNullEntries(user.pinnedItems);
|
||||
user.unpinnedItems = checkForNullEntries(user.unpinnedItems);
|
||||
}
|
||||
|
||||
function selectGearToPin (user) {
|
||||
let changes = [];
|
||||
|
||||
@@ -41,11 +50,10 @@ function selectGearToPin (user) {
|
||||
return sortBy(changes, (change) => sortOrder[change.type]);
|
||||
}
|
||||
|
||||
|
||||
function addPinnedGear (user, type, path) {
|
||||
const foundIndex = pathExistsInArray(user.pinnedItems, path);
|
||||
|
||||
if (foundIndex === -1) {
|
||||
if (foundIndex === -1 && type && path) {
|
||||
user.pinnedItems.push({
|
||||
type,
|
||||
path,
|
||||
@@ -176,5 +184,6 @@ module.exports = {
|
||||
togglePinnedItem,
|
||||
removeItemByPath,
|
||||
selectGearToPin,
|
||||
checkPinnedAreasForNullEntries,
|
||||
isPinned,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user