2023-12-12 16:09:29 +08:00
|
|
|
import React, {useEffect} from 'react';
|
2024-01-09 17:25:22 +08:00
|
|
|
//import {DragDropContext} from "@hello-pangea/dnd";
|
|
|
|
import {DndContext, useSensor, useSensors, TouchSensor, MouseSensor} from "@dnd-kit/core";
|
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);
|
|
|
|
const moveCard = useShopStore((state) => state.moveCard);
|
|
|
|
const deleteCard = useShopStore((state) => state.deleteCard);
|
|
|
|
const cardIndexById = useShopStore((state) => state.cardIndexById);
|
|
|
|
|
2024-01-09 17:25:22 +08:00
|
|
|
const mouseSensor = useSensor(MouseSensor);
|
|
|
|
const touchSensor = useSensor(TouchSensor);
|
|
|
|
const sensors = useSensors(
|
|
|
|
mouseSensor,
|
|
|
|
touchSensor,
|
|
|
|
);
|
|
|
|
|
|
|
|
const handleOnDragEnd = (event) => {
|
|
|
|
console.log(event);
|
|
|
|
|
2023-12-13 15:17:14 +08:00
|
|
|
if (!drop_result.destination) {
|
|
|
|
console.warn("No drop destination");
|
|
|
|
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);
|
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 (
|
2024-01-09 17:25:22 +08:00
|
|
|
<DndContext sensors={sensors} 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={(
|
|
|
|
<p className="description">Drag and drop the cards you want into the crate below to see how
|
|
|
|
the combination would look like. Setup card's configuration by tapping at the top of the
|
|
|
|
card, most of the options can be modified after shipment. 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>. The price is estimated and must
|
|
|
|
be confirmed by a quote.</p>)}
|
|
|
|
/>
|
2023-12-11 17:05:35 +08:00
|
|
|
)}>
|
|
|
|
</Layout>
|
2024-01-09 17:25:22 +08:00
|
|
|
</DndContext>
|
2023-12-11 17:05:35 +08:00
|
|
|
);
|
|
|
|
|
2023-11-30 17:26:17 +08:00
|
|
|
}
|