1
0
Fork 0
web2019/static/js/shop/Shop.jsx

76 lines
2.9 KiB
React
Raw Permalink Normal View History

import React, {useEffect} from 'react';
import {DragDropContext} from "@hello-pangea/dnd";
// #!render_count
import {useRenderCount} from "@uidotdev/usehooks";
2023-12-12 18:21:09 +08:00
import {Layout} from "./Layout";
import {Catalog} from "./Catalog";
2023-12-12 18:21:09 +08:00
import {OrderPanel} from "./OrderPanel";
import {useShopStore} from "./shop_store";
import {DomainedEmail} from "./Domained";
/**
* Component that renders the entire shop
*/
export function Shop() {
// #!render_count
const renderCount = useRenderCount();
const addCardFromCatalog = useShopStore((state) => state.addCardFromCatalog);
const initExtData = useShopStore((state) => state.initExtData);
const moveCard = useShopStore((state) => state.moveCard);
const deleteCard = useShopStore((state) => state.deleteCard);
const cardIndexById = useShopStore((state) => state.cardIndexById);
const handleOnDragEnd = (drop_result, _provided) => {
if (!drop_result.destination) {
console.warn("No drop destination");
console.log(drop_result)
return;
}
if (drop_result.source.droppableId === "catalog")
addCardFromCatalog(drop_result.destination.droppableId, drop_result.source.index, drop_result.destination.index);
else if (drop_result.destination.droppableId === "catalog")
deleteCard(drop_result.source.droppableId, drop_result.source.index);
else
moveCard(drop_result.source.droppableId, drop_result.source.index, drop_result.destination.droppableId, drop_result.destination.index)
}
useEffect(() => {
addCardFromCatalog(null, [cardIndexById("eem_pwr_mod"), cardIndexById("kasli")], -1, true);
initExtData();
}, []);
// #!render_count
console.log("Shop renders: ", renderCount)
return (
<DragDropContext onDragEnd={handleOnDragEnd}>
<Layout
aside={
<Catalog/>
}
main={(
<OrderPanel
title="Order hardware"
description={(
<p className="description">
Drag and drop the cards you want into the crate below to see how
the combination would look like. Configure the card settings by tapping on the top of
the card; many of the options can be adjusted even after the card has been shipped.
If you have any issues with this ordering system, or if you need other configurations,
email us directly anytime at <DomainedEmail address="sales"/>.
2024-02-15 12:36:09 +08:00
The price excludes shipping, is estimated, and must be confirmed by a quote.
</p>
)}
/>
)}>
</Layout>
</DragDropContext>
);
2024-02-15 12:36:09 +08:00
}