From 448cf9c29af5aa9b7119c96d44a079572a672dd0 Mon Sep 17 00:00:00 2001 From: Egor Savkin Date: Tue, 9 Jan 2024 17:43:02 +0800 Subject: [PATCH] Try make wrappers Signed-off-by: Egor Savkin --- static/js/shop/Backlog.jsx | 13 +++++-------- static/js/shop/Cart.jsx | 11 +++-------- static/js/shop/ProductCartItem.jsx | 10 +++------- static/js/shop/ProductItem.jsx | 11 +++-------- static/js/shop/dnd/Draggable.jsx | 15 +++++++++++++++ static/js/shop/dnd/Droppable.jsx | 14 ++++++++++++++ 6 files changed, 43 insertions(+), 31 deletions(-) create mode 100644 static/js/shop/dnd/Draggable.jsx create mode 100644 static/js/shop/dnd/Droppable.jsx diff --git a/static/js/shop/Backlog.jsx b/static/js/shop/Backlog.jsx index 2c81fab..148536e 100644 --- a/static/js/shop/Backlog.jsx +++ b/static/js/shop/Backlog.jsx @@ -1,6 +1,5 @@ import React from 'react'; -//import {Droppable} from "@hello-pangea/dnd"; -import {useDroppable} from '@dnd-kit/core'; +import {Droppable} from './dnd/Droppable'; import {ProductItem} from "./ProductItem"; import {useShopStore} from "./shop_store"; // #!render_count @@ -18,10 +17,6 @@ export function Backlog() { const onClickToggleMobileSideMenu = useShopStore((state) => state.switchSideMenu); const isMobile = useShopStore((state) => state.isMobile); - const {setNodeRef} = useDroppable({ - id: data.id, - }); - // #!render_count console.log("Backlog renders: ", renderCount) @@ -57,7 +52,9 @@ export function Backlog() { ); return ( -
+ {(provided) => (
)} -
+
); } \ No newline at end of file diff --git a/static/js/shop/Cart.jsx b/static/js/shop/Cart.jsx index a4ca908..ad35d33 100644 --- a/static/js/shop/Cart.jsx +++ b/static/js/shop/Cart.jsx @@ -1,6 +1,5 @@ import React from 'react' -//import {Droppable} from "@hello-pangea/dnd"; -import {useDroppable} from '@dnd-kit/core'; +import {Droppable} from './dnd/Droppable'; import {cartStyle, compareArraysWithIds} from "./utils"; import {ProductCartItem} from "./ProductCartItem"; import {FakePlaceholder} from "./FakePlaceholder"; @@ -23,10 +22,6 @@ export function Cart({crate_index}) { }); const crateParams = useShopStore((state) => state.crateParams); - const {setNodeRef} = useDroppable({ - id: crate.id, - }); - // #!render_count console.log("Cart renders: ", renderCount) @@ -47,7 +42,7 @@ export function Cart({crate_index}) { }); return ( -
+ {(provided, snapshot) => (
)} -
+
); } \ No newline at end of file diff --git a/static/js/shop/ProductCartItem.jsx b/static/js/shop/ProductCartItem.jsx index 10b3482..01acc23 100644 --- a/static/js/shop/ProductCartItem.jsx +++ b/static/js/shop/ProductCartItem.jsx @@ -1,6 +1,6 @@ import React from 'react' //import {Draggable} from "@hello-pangea/dnd"; -import {useDraggable} from '@dnd-kit/core'; +import {Draggable} from './dnd/Draggable'; import {compareObjectsEmptiness, productStyle} from "./utils"; import {Resources} from "./Resources"; import {CardWarnings} from "./CardWarnings"; @@ -32,10 +32,6 @@ export function ProductCartItem({card_index, crate_index, first, last}) { const removeHighlight = useShopStore((state) => state.highlightReset); const onCardRemove = useShopStore((state) => state.deleteCard); - const {attributes, listeners, setNodeRef, transform} = useDraggable({ - id: card.id, - }); - // #!render_count console.log("ProductCartItem renders: ", renderCount) @@ -45,7 +41,7 @@ export function ProductCartItem({card_index, crate_index, first, last}) { const resources = !options_disabled && card_counted_resources && card_counted_resources.length > 0; return ( -
+ {(provided, snapshot) => (
)} -
+
); } diff --git a/static/js/shop/ProductItem.jsx b/static/js/shop/ProductItem.jsx index 4d244da..3315c0b 100644 --- a/static/js/shop/ProductItem.jsx +++ b/static/js/shop/ProductItem.jsx @@ -1,6 +1,5 @@ import React from 'react'; -//import {Draggable} from "@hello-pangea/dnd"; -import {useDraggable} from '@dnd-kit/core'; +import {Draggable} from './dnd/Draggable'; import {formatMoney, productStyle} from "./utils"; import {useShopStore} from "./shop_store"; @@ -20,10 +19,6 @@ export function ProductItem({card_index}) { const onAddCard = useShopStore((state) => state.addCardFromBacklog); const card = getCardDescription(card_index); - const {attributes, listeners, setNodeRef, transform} = useDraggable({ - id: card.id, - }); - // #!render_count console.log("ProductItem renders: ", renderCount) @@ -67,7 +62,7 @@ export function ProductItem({card_index}) { add -
+ {(provided, snapshot) => ( )} -
+
diff --git a/static/js/shop/dnd/Draggable.jsx b/static/js/shop/dnd/Draggable.jsx new file mode 100644 index 0000000..8a5eb7b --- /dev/null +++ b/static/js/shop/dnd/Draggable.jsx @@ -0,0 +1,15 @@ +import React from 'react'; +import {useDraggable} from '@dnd-kit/core'; + +export function Draggable(props) { + const Element = props.element || 'div'; + const {attributes, listeners, setNodeRef} = useDraggable({ + id: props.id, + }); + + return ( + + {props.children} + + ); +} \ No newline at end of file diff --git a/static/js/shop/dnd/Droppable.jsx b/static/js/shop/dnd/Droppable.jsx new file mode 100644 index 0000000..eb46907 --- /dev/null +++ b/static/js/shop/dnd/Droppable.jsx @@ -0,0 +1,14 @@ +import {useDroppable} from '@dnd-kit/core'; +import React from 'react' + +export function Droppable(props) { + const {setNodeRef} = useDroppable({ + id: props.id, + }); + + return ( +
+ {props.children} +
+ ); +}