style boxes when selecting item move target
This commit is contained in:
+15
-1
@@ -30,6 +30,10 @@ function App() {
|
|||||||
|
|
||||||
const [dragSource, setDragSource] = useState({});
|
const [dragSource, setDragSource] = useState({});
|
||||||
const [dragSourceElement, setDragSourceElement] = useState(undefined);
|
const [dragSourceElement, setDragSourceElement] = useState(undefined);
|
||||||
|
|
||||||
|
const [isMoving, setIsMoving] = useState(false);
|
||||||
|
const [moveItem, setMoveItem] = useState(null);
|
||||||
|
|
||||||
//fetch all box data
|
//fetch all box data
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const fetchData = async () => {
|
const fetchData = async () => {
|
||||||
@@ -177,6 +181,11 @@ function App() {
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
const handleSelectMoveBox = (boxData, event) => {
|
||||||
|
console.log(`move item: ${moveItem} to box ${boxData._id}`);
|
||||||
|
setMoveItem(null);
|
||||||
|
setIsMoving(false);
|
||||||
|
}
|
||||||
const boxHandler = {
|
const boxHandler = {
|
||||||
handleSubmit: handleSubmitBox,
|
handleSubmit: handleSubmitBox,
|
||||||
handleRemove: handleRemoveBox,
|
handleRemove: handleRemoveBox,
|
||||||
@@ -185,7 +194,8 @@ function App() {
|
|||||||
handleEdit: handleEditBox,
|
handleEdit: handleEditBox,
|
||||||
handleDragStart: handleDragStartBox,
|
handleDragStart: handleDragStartBox,
|
||||||
handleDragOver: handleDragOverBox,
|
handleDragOver: handleDragOverBox,
|
||||||
handleDrop: handleDropBox
|
handleDrop: handleDropBox,
|
||||||
|
handleSelectMove: handleSelectMoveBox,
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleModalCloseBox = () => {
|
const handleModalCloseBox = () => {
|
||||||
@@ -251,6 +261,9 @@ function App() {
|
|||||||
setShowModalItem(true);
|
setShowModalItem(true);
|
||||||
}
|
}
|
||||||
const handleMoveItem = (boxID, itemID) => {
|
const handleMoveItem = (boxID, itemID) => {
|
||||||
|
setMoveItem(itemID);
|
||||||
|
setIsMoving(true);
|
||||||
|
/*highlight which boxes available to move to*/
|
||||||
/*...*/
|
/*...*/
|
||||||
}
|
}
|
||||||
const handleViewItem = (boxID, itemID) => {
|
const handleViewItem = (boxID, itemID) => {
|
||||||
@@ -372,6 +385,7 @@ function App() {
|
|||||||
{filteredData.map((box, index) => {
|
{filteredData.map((box, index) => {
|
||||||
return (
|
return (
|
||||||
<Box
|
<Box
|
||||||
|
isMoving={isMoving}
|
||||||
key={index}
|
key={index}
|
||||||
boxData={box}
|
boxData={box}
|
||||||
boxHandler={boxHandler}
|
boxHandler={boxHandler}
|
||||||
|
|||||||
+4
-3
@@ -1,7 +1,7 @@
|
|||||||
import React, { useState, useRef, useEffect } from 'react';
|
import React, { useState, useRef, useEffect } from 'react';
|
||||||
import Item from './item';
|
import Item from './item';
|
||||||
|
|
||||||
const Box = ({ boxData, boxHandler, itemHandler }) => {
|
const Box = ({ boxData, boxHandler, itemHandler, isMoving }) => {
|
||||||
const menu = useRef(null);
|
const menu = useRef(null);
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
document.addEventListener('mousedown', handleClick);
|
document.addEventListener('mousedown', handleClick);
|
||||||
@@ -40,10 +40,11 @@ const Box = ({ boxData, boxHandler, itemHandler }) => {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
return (
|
return (
|
||||||
<li className='box' draggable='true'
|
<li className={`${isMoving ? "target" : null} box`} draggable='true'
|
||||||
onDragStart={(event) => boxHandler.handleDragStart(boxData, event)}
|
onDragStart={(event) => boxHandler.handleDragStart(boxData, event)}
|
||||||
onDragOver={boxHandler.handleDragOver}
|
onDragOver={boxHandler.handleDragOver}
|
||||||
onDrop={(event) => boxHandler.handleDrop(boxData, event)}>
|
onDrop={(event) => boxHandler.handleDrop(boxData, event)}
|
||||||
|
onClick={(event) => isMoving && boxHandler.handleSelectMove(boxData, event)}>
|
||||||
{false && <span>{boxData.sort}</span>}
|
{false && <span>{boxData.sort}</span>}
|
||||||
<div ref={menu} className='menu-more-container'>{showMenu && moreMenu()}</div>
|
<div ref={menu} className='menu-more-container'>{showMenu && moreMenu()}</div>
|
||||||
<div className='box-header'>
|
<div className='box-header'>
|
||||||
|
|||||||
@@ -114,7 +114,13 @@ li.box {
|
|||||||
list-style: none;
|
list-style: none;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
li.box.target {
|
||||||
|
border-color: green;
|
||||||
|
}
|
||||||
|
li.box.target:hover {
|
||||||
|
cursor: pointer;
|
||||||
|
border-width: 2px;
|
||||||
|
}
|
||||||
.item-menu-more-container {
|
.item-menu-more-container {
|
||||||
z-index: 1;
|
z-index: 1;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user