mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-16 06:07:21 +01:00
Cleanup pinned items that are no longer for purchase
This commit is contained in:
50
website/common/script/libs/cleanupPinnedItems.js
Normal file
50
website/common/script/libs/cleanupPinnedItems.js
Normal file
@@ -0,0 +1,50 @@
|
||||
import getItemByPathAndType from './getItemByPathAndType';
|
||||
import { getAllScheduleMatchingGroups } from '../content/constants/schedule';
|
||||
|
||||
const simpleSeasonalPins = [
|
||||
'background',
|
||||
'premiumHatchingPotion',
|
||||
'mystery_set',
|
||||
'bundles',
|
||||
'seasonalQuest',
|
||||
];
|
||||
|
||||
const detailSeasonalPins = [
|
||||
'quests',
|
||||
'gear',
|
||||
];
|
||||
|
||||
export default function cleanupPinnedItems (user) {
|
||||
const matchers = getAllScheduleMatchingGroups();
|
||||
|
||||
const items = user.pinnedItems
|
||||
.filter(pinnedItem => {
|
||||
const { type } = pinnedItem;
|
||||
const key = pinnedItem.path.split('.').slice(-1)[0];
|
||||
if (simpleSeasonalPins.indexOf(type) != -1) {
|
||||
if (type === 'background') {
|
||||
return matchers.backgrounds.match(pinnedItem.path.split('.')[1]);
|
||||
} if (type === 'premiumHatchingPotion') {
|
||||
return matchers.premiumHatchingPotions.match(key);
|
||||
} if (type === 'mystery_set') {
|
||||
return matchers.timeTravelers.match(key);
|
||||
} if (type === 'seasonalQuest') {
|
||||
return matchers.seasonalQuests.match(key);
|
||||
}
|
||||
return matchers[type].match(key);
|
||||
} if (detailSeasonalPins.indexOf(type) != -1) {
|
||||
const item = getItemByPathAndType(type, pinnedItem.path);
|
||||
if (type === 'gear' && item.klass === 'special') {
|
||||
return matchers.seasonalGear.match(item.set);
|
||||
} if (type === 'quests' && item.category === 'pet') {
|
||||
return matchers.petQuests.match(item.key);
|
||||
} if (type === 'quests' && item.category === 'hatchingPotion') {
|
||||
return matchers.hatchingPotionQuests.match(item.key);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
|
||||
return items;
|
||||
}
|
||||
Reference in New Issue
Block a user