mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 14:47:53 +01:00
* auto-remove officialPinned item from userPinned-array on pinning * hide event limited message if an item was already owned by the user
This commit is contained in:
@@ -225,7 +225,8 @@ div
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
limitedString () {
|
limitedString () {
|
||||||
return this.$t('limitedOffer', {date: moment(seasonalShopConfig.dateRange.end).format('LL')});
|
return this.item.owned === false ? '' :
|
||||||
|
this.$t('limitedOffer', {date: moment(seasonalShopConfig.dateRange.end).format('LL')});
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
|||||||
@@ -140,6 +140,8 @@ shops.checkMarketGearLocked = function checkMarketGearLocked (user, items) {
|
|||||||
if (itemOwned === false) {
|
if (itemOwned === false) {
|
||||||
gear.locked = false;
|
gear.locked = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gear.owned = itemOwned;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -16,6 +16,17 @@ let sortOrder = reduce(content.gearTypes, (accumulator, val, key) => {
|
|||||||
return accumulator;
|
return accumulator;
|
||||||
}, {});
|
}, {});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the index if found
|
||||||
|
* @param Array array
|
||||||
|
* @param String path
|
||||||
|
*/
|
||||||
|
function pathExistsInArray (array, path) {
|
||||||
|
return array.findIndex(item => {
|
||||||
|
return item.path === path;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function selectGearToPin (user) {
|
function selectGearToPin (user) {
|
||||||
let changes = [];
|
let changes = [];
|
||||||
|
|
||||||
@@ -32,9 +43,7 @@ function selectGearToPin (user) {
|
|||||||
|
|
||||||
|
|
||||||
function addPinnedGear (user, type, path) {
|
function addPinnedGear (user, type, path) {
|
||||||
const foundIndex = user.pinnedItems.findIndex(pinnedItem => {
|
const foundIndex = pathExistsInArray(user.pinnedItems, path);
|
||||||
return pinnedItem.path === path;
|
|
||||||
});
|
|
||||||
|
|
||||||
if (foundIndex === -1) {
|
if (foundIndex === -1) {
|
||||||
user.pinnedItems.push({
|
user.pinnedItems.push({
|
||||||
@@ -55,9 +64,7 @@ function addPinnedGearByClass (user) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function removeItemByPath (user, path) {
|
function removeItemByPath (user, path) {
|
||||||
const foundIndex = user.pinnedItems.findIndex(pinnedItem => {
|
const foundIndex = pathExistsInArray(user.pinnedItems, path);
|
||||||
return pinnedItem.path === path;
|
|
||||||
});
|
|
||||||
|
|
||||||
if (foundIndex >= 0) {
|
if (foundIndex >= 0) {
|
||||||
user.pinnedItems.splice(foundIndex, 1);
|
user.pinnedItems.splice(foundIndex, 1);
|
||||||
@@ -148,9 +155,7 @@ function togglePinnedItem (user, {item, type, path}, req = {}) {
|
|||||||
throw new BadRequest(i18n.t('cannotUnpinArmoirPotion', req.language));
|
throw new BadRequest(i18n.t('cannotUnpinArmoirPotion', req.language));
|
||||||
}
|
}
|
||||||
|
|
||||||
let isOfficialPinned = officialPinnedItems.find(officialPinnedItem => {
|
const isOfficialPinned = pathExistsInArray(officialPinnedItems, path) !== -1;
|
||||||
return officialPinnedItem.path === path;
|
|
||||||
}) !== undefined;
|
|
||||||
|
|
||||||
if (isOfficialPinned) {
|
if (isOfficialPinned) {
|
||||||
arrayToChange = user.unpinnedItems;
|
arrayToChange = user.unpinnedItems;
|
||||||
@@ -158,9 +163,16 @@ function togglePinnedItem (user, {item, type, path}, req = {}) {
|
|||||||
arrayToChange = user.pinnedItems;
|
arrayToChange = user.pinnedItems;
|
||||||
}
|
}
|
||||||
|
|
||||||
const foundIndex = arrayToChange.findIndex(pinnedItem => {
|
if (isOfficialPinned) {
|
||||||
return pinnedItem.path === path;
|
// if an offical item is also present in the user.pinnedItems array
|
||||||
});
|
const itemInUserItems = pathExistsInArray(user.pinnedItems, path);
|
||||||
|
|
||||||
|
if (itemInUserItems !== -1) {
|
||||||
|
removeItemByPath(user, path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const foundIndex = pathExistsInArray(arrayToChange, path);
|
||||||
|
|
||||||
if (foundIndex >= 0) {
|
if (foundIndex >= 0) {
|
||||||
arrayToChange.splice(foundIndex, 1);
|
arrayToChange.splice(foundIndex, 1);
|
||||||
|
|||||||
Reference in New Issue
Block a user