mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-15 13:47:33 +01:00
- Rewrite exports of debuffPotion functions
- Force clear debuffPotions in setDebuffPotionItems to make the same behavior as in develop branch
- Change class of debuffPotion items to shop_{key}
- Resolve lint warnings
31 lines
782 B
JavaScript
31 lines
782 B
JavaScript
import getDebuffPotionItems from './getDebuffPotionItems';
|
|
|
|
function clearDebuffPotion (user) {
|
|
return user.pinnedItems.filter(item => item.type !== 'debuffPotion');
|
|
}
|
|
|
|
|
|
export default function setDebuffPotionItems (user) {
|
|
user.pinnedItems = clearDebuffPotion(user);
|
|
|
|
const debuffPotionItems = getDebuffPotionItems(user);
|
|
|
|
if (debuffPotionItems.length) {
|
|
let isPresent = false;
|
|
const isUserHaveDebuffInPinnedItems = user.pinnedItems.find(pinnedItem => {
|
|
debuffPotionItems.forEach(debuffPotion => {
|
|
if (!isPresent) {
|
|
isPresent = debuffPotion.path === pinnedItem.path;
|
|
}
|
|
});
|
|
return isPresent;
|
|
});
|
|
|
|
if (!isUserHaveDebuffInPinnedItems) {
|
|
user.pinnedItems.push(...debuffPotionItems);
|
|
}
|
|
}
|
|
|
|
return user;
|
|
}
|