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:
negue
2019-03-31 20:41:37 +02:00
committed by Matteo Pagliazzi
parent 5656b9c6ca
commit f35ef3a046
7 changed files with 54 additions and 11 deletions

View File

@@ -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,
};