2023-12-12 16:09:29 +08:00
|
|
|
import React, {useEffect} from 'react';
|
2023-12-01 11:52:37 +08:00
|
|
|
import {DragDropContext} from "@hello-pangea/dnd";
|
2023-12-14 16:29:32 +08:00
|
|
|
|
|
|
|
// #!render_count
|
2023-12-14 16:09:33 +08:00
|
|
|
import {useRenderCount} from "@uidotdev/usehooks";
|
2023-11-30 17:26:17 +08:00
|
|
|
|
|
|
|
|
2023-12-12 18:21:09 +08:00
|
|
|
import {Layout} from "./Layout";
|
|
|
|
import {Backlog} from "./Backlog";
|
|
|
|
import {OrderPanel} from "./OrderPanel";
|
2023-12-11 17:47:16 +08:00
|
|
|
import {useShopStore} from "./shop_store";
|
2023-11-30 17:26:17 +08:00
|
|
|
|
|
|
|
/**
|
2023-12-13 12:39:15 +08:00
|
|
|
* Component that renders the entire shop
|
2023-11-30 17:26:17 +08:00
|
|
|
*/
|
|
|
|
|
2023-12-11 17:05:35 +08:00
|
|
|
export function Shop() {
|
2023-12-14 16:29:32 +08:00
|
|
|
// #!render_count
|
2023-12-14 16:09:33 +08:00
|
|
|
const renderCount = useRenderCount();
|
|
|
|
|
|
|
|
const addCardFromBacklog = useShopStore((state) => state.addCardFromBacklog);
|
2024-01-30 13:02:01 +08:00
|
|
|
const initExtData = useShopStore((state) => state.initExtData);
|
2023-12-14 16:09:33 +08:00
|
|
|
const moveCard = useShopStore((state) => state.moveCard);
|
|
|
|
const deleteCard = useShopStore((state) => state.deleteCard);
|
|
|
|
const cardIndexById = useShopStore((state) => state.cardIndexById);
|
|
|
|
|
2023-12-13 12:39:15 +08:00
|
|
|
const handleOnDragEnd = (drop_result, _provided) => {
|
2023-12-13 15:17:14 +08:00
|
|
|
if (!drop_result.destination) {
|
|
|
|
console.warn("No drop destination");
|
2024-02-07 16:23:17 +08:00
|
|
|
console.log(drop_result)
|
2023-12-13 15:17:14 +08:00
|
|
|
return;
|
|
|
|
}
|
2023-12-11 17:47:16 +08:00
|
|
|
if (drop_result.source.droppableId === "backlog")
|
|
|
|
addCardFromBacklog(drop_result.destination.droppableId, drop_result.source.index, drop_result.destination.index);
|
2023-12-14 16:09:33 +08:00
|
|
|
else if (drop_result.destination.droppableId === "backlog")
|
2024-01-02 17:13:50 +08:00
|
|
|
deleteCard(drop_result.source.droppableId, drop_result.source.index);
|
2023-12-11 17:47:16 +08:00
|
|
|
else
|
|
|
|
moveCard(drop_result.source.droppableId, drop_result.source.index, drop_result.destination.droppableId, drop_result.destination.index)
|
2023-11-30 17:26:17 +08:00
|
|
|
}
|
|
|
|
|
2023-12-12 16:09:29 +08:00
|
|
|
useEffect(() => {
|
2023-12-13 15:17:14 +08:00
|
|
|
addCardFromBacklog(null, [cardIndexById("eem_pwr_mod"), cardIndexById("kasli")], -1, true);
|
2024-01-30 13:02:01 +08:00
|
|
|
initExtData();
|
2023-12-12 16:09:29 +08:00
|
|
|
}, []);
|
|
|
|
|
2023-12-14 16:29:32 +08:00
|
|
|
// #!render_count
|
2023-12-14 16:09:33 +08:00
|
|
|
console.log("Shop renders: ", renderCount)
|
2023-12-14 16:29:32 +08:00
|
|
|
|
2023-12-11 17:05:35 +08:00
|
|
|
return (
|
2023-12-11 17:47:16 +08:00
|
|
|
<DragDropContext onDragEnd={handleOnDragEnd}>
|
2023-12-11 17:05:35 +08:00
|
|
|
<Layout
|
|
|
|
aside={
|
|
|
|
<Backlog/>
|
|
|
|
}
|
|
|
|
main={(
|
|
|
|
<OrderPanel
|
|
|
|
title="Order hardware"
|
2023-12-14 16:09:33 +08:00
|
|
|
description={(
|
2024-01-23 11:36:56 +08:00
|
|
|
<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 <a href="mailto:sales@m-labs.hk">sales@m-labs.hk</a>.
|
2024-02-15 12:36:09 +08:00
|
|
|
The price excludes shipping, is estimated, and must be confirmed by a quote.
|
2024-01-23 11:36:56 +08:00
|
|
|
</p>
|
|
|
|
)}
|
2023-12-14 16:09:33 +08:00
|
|
|
/>
|
2023-12-11 17:05:35 +08:00
|
|
|
)}>
|
|
|
|
</Layout>
|
|
|
|
</DragDropContext>
|
|
|
|
);
|
|
|
|
|
2024-02-15 12:36:09 +08:00
|
|
|
}
|