diff --git a/client/src/app.js b/client/src/app.js index d01cce7..6138768 100644 --- a/client/src/app.js +++ b/client/src/app.js @@ -8,9 +8,12 @@ import './styles/app.css'; function App() { const [data, setData] = useState([]); + const [boxID, setBoxID] = useState(undefined); const [boxName, setBoxName] = useState(''); const [boxDescription, setBoxDescription] = useState(''); + const [boxSort, setBoxSort] = useState(0); + const [showModalBox, setShowModalBox] = useState(false); const [showModalItem, setShowModalItem] = useState(false); @@ -24,14 +27,7 @@ function App() { const [filter, setFilter] = useState(''); const [filteredData, setFilteredData] = useState([]); - - - const handleName = (e) => { - setItemName(e.target.value) - } - const handleDescription = (e) => { - setItemDescription(e.target.value) - } + const [dragSource, setDragSource] = useState({}); //fetch all box data useEffect(() => { @@ -98,6 +94,15 @@ function App() { } } + const sortBox = async (target, source) => { + try { + const response = await axios.put(`${api.baseApiUrl}/${source._id}/sort`,target); + setData(response.data); + } + catch (error) { + + } + } const handleNameBox = (e) => { setBoxName(e.target.value); } @@ -146,13 +151,32 @@ function App() { setBoxID(undefined); } - + const handleDragStartBox = (dragSource, event) => { + setDragSource(dragSource); + event.dataTransfer.dropEffect = "move"; + } + const handleDragOverBox = (event) => { + event.preventDefault(); + event.dataTransfer.dropEffect = "move"; + } + const handleDropBox = async (dragTarget, event) => { + event.preventDefault(); + if(dragTarget._id !== dragSource._id) { + const target = dragTarget; + const source = dragSource; + await sortBox(target, source); + } + return false; + } const boxHandler = { handleSubmit: handleSubmitBox, handleRemove: handleRemoveBox, handleName: handleNameBox, handleDescription: handleBoxDescription, - handleEdit: handleEditBox + handleEdit: handleEditBox, + handleDragStart: handleDragStartBox, + handleDragOver: handleDragOverBox, + handleDrop: handleDropBox }; const handleModalCloseBox = () => { @@ -245,11 +269,20 @@ function App() { setItemDescription(''); } + + const handleNameItem = (e) => { + setItemName(e.target.value) + } + const handleDescriptionItem = (e) => { + setItemDescription(e.target.value) + } const itemHandler = { handleSubmit: handleSubmitItem, handleRemove: handleRemoveItem, handleAdd: handleAddItem, handleEdit: handleEditItem, + handleName: handleNameItem, + handleDescription: handleDescriptionItem, }; const handleFilterChange = (event) => { @@ -277,10 +310,10 @@ function App() {
@@ -289,7 +322,6 @@ function App() { <> {} {} -