forked from M-Labs/web2019
Automatically open spare cards for crateless items
Signed-off-by: Egor Savkin <es@m-labs.hk>
This commit is contained in:
parent
f29807a913
commit
18bd98a204
|
@ -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();
|
||||
|
|
Loading…
Reference in New Issue