diff --git a/static/js/shop/ProductItem.jsx b/static/js/shop/ProductItem.jsx
index 872fdb5..9b429d6 100644
--- a/static/js/shop/ProductItem.jsx
+++ b/static/js/shop/ProductItem.jsx
@@ -6,9 +6,33 @@ import {useShopStore} from "./shop_store";
// #!render_count
import {useRenderCount} from "@uidotdev/usehooks";
+
+function DatasheetLink({datasheet_file, datasheet_name}) {
+ return datasheet_file && datasheet_name && (
)
+}
+
+function CardSpecs({specs}) {
+ return specs && specs.length > 0 && (
+ {specs.map((spec, index) =>
+ - {spec}
+ )}
+
)
+}
+
+function AddButton({onAdd}) {
+ return
+}
+
/**
* Component that renders a product.
- * Used in the aside (e.g catalog of product)
+ * Used in the aside (e.g catalog of products)
*/
export function ProductItem({card_index}) {
// #!render_count
@@ -16,33 +40,14 @@ export function ProductItem({card_index}) {
const getCardDescription = useShopStore((state) => state.getCardDescription);
const currency = useShopStore((state) => state.currency);
- const onAddCard = useShopStore((state) => state.addCardFromCatalog);
+ const addCardFromCatalog = useShopStore((state) => state.addCardFromCatalog);
const card = getCardDescription(card_index);
// #!render_count
console.log("ProductItem renders: ", renderCount)
-
- const render_specs = (card.specs && card.specs.length > 0 && (
-
- {card.specs.map((spec, index) =>
- - {spec}
- )}
-
- ));
-
- const render_datasheet_link = (card.datasheet_file && card.datasheet_name && (
-
- ));
-
return (
-
{card.name_number} {card.name}
{card.name_codename ? (
@@ -51,16 +56,13 @@ export function ProductItem({card_index}) {
{`${currency} ${formatMoney(card.price)}`}
- {render_specs}
+
- {render_datasheet_link}
+
-
-
+
addCardFromCatalog(null, card_index, null)} />
{(provided, snapshot) => (
@@ -83,10 +85,7 @@ export function ProductItem({card_index}) {
)}
-
-
);
-
}
\ No newline at end of file
diff --git a/static/js/shop/shop_store.js b/static/js/shop/shop_store.js
index 08171d2..657db72 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} 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";
@@ -18,6 +18,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,
@@ -384,7 +388,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 {
@@ -555,7 +559,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();