From 18bd98a204a3b0bb9770f6cddc4a5e0e4215cb2e Mon Sep 17 00:00:00 2001 From: Egor Savkin Date: Thu, 11 Jul 2024 17:30:34 +0800 Subject: [PATCH] Automatically open spare cards for crateless items Signed-off-by: Egor Savkin --- static/js/shop/shop_store.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/static/js/shop/shop_store.js b/static/js/shop/shop_store.js index 1e5c267..78e189b 100644 --- a/static/js/shop/shop_store.js +++ b/static/js/shop/shop_store.js @@ -2,7 +2,7 @@ import {createWithEqualityFn} from "zustand/traditional"; import {DATA as shared_data, itemsUnfoldedList, API_RFQ} from "./utils"; -import {FillExtCrateData, FillExtOrderData, true_type_of} from "./options/utils"; +import {FillExtCrateData, FillExtOrderData} from "./options/utils"; import {v4 as uuidv4} from "uuid"; import {FillResources} from "./count_resources"; import {FillExtCardData} from "./options/utils"; @@ -19,6 +19,10 @@ const cards_to_pn_map = (cards) => { return result; }; +const toArray = (arg) => { + return Array.isArray(arg) ? arg : [arg]; +}; + const useCatalog = ((set, get) => ({ cards: shared_data.items, groups: shared_data.columns.catalog, @@ -385,7 +389,7 @@ const useCart = ((set, get) => ({ })), setActiveCrate: (id) => set(state => ({active_crate: id})), _addCardFromCatalog: (crate_to, index_from, index_to) => set(state => { - const take_from = (true_type_of(index_from) === "array" ? index_from : [index_from]).map((item, _i) => (state.cards_list[item])); + const take_from = toArray(index_from).map((item, _i) => (state.cards_list[item])); const dest = crate_to || state.active_crate; if (!dest) return {}; return { @@ -557,7 +561,8 @@ const useCart = ((set, get) => ({ }, addCardFromCatalog: (crate_to, index_from, index_to, just_mounted) => { - const dest = crate_to || get().active_crate; + const isCrateless = toArray(index_from).some(value => get().getCardDescription(value).crateless === true); + const dest = isCrateless ? "spare" : crate_to || get().active_crate; if (!dest) { console.warn("No destination"); get().noDestinationWarning();