2024-08-05 22:36:05 +05:30
|
|
|
import { useState } from 'react'
|
2024-08-04 22:47:43 +05:30
|
|
|
|
2024-08-05 22:36:05 +05:30
|
|
|
import { LayoutFilled, ProductFilled, CloudUploadOutlined } from "@ant-design/icons"
|
2024-08-04 22:47:43 +05:30
|
|
|
|
2024-08-05 22:36:05 +05:30
|
|
|
import Sidebar from './sidebar/sidebar'
|
|
|
|
|
import WidgetsContainer from './sidebar/widgetsContainer'
|
|
|
|
|
import UploadsContainer from './sidebar/uploadsContainer'
|
2024-08-08 16:21:19 +05:30
|
|
|
import Canvas from './canvas/canvas'
|
2024-09-08 21:58:53 +05:30
|
|
|
import Header from './components/header'
|
2024-09-11 19:06:04 +05:30
|
|
|
import { DndContext, useSensors, useSensor, PointerSensor, closestCorners, DragOverlay } from '@dnd-kit/core'
|
|
|
|
|
import { DraggableWidgetCard } from './components/cards'
|
|
|
|
|
|
2024-08-04 12:08:30 +05:30
|
|
|
|
|
|
|
|
function App() {
|
2024-08-04 22:47:43 +05:30
|
|
|
|
2024-08-05 22:36:05 +05:30
|
|
|
const [uploadedAssets, setUploadedAssets] = useState([]) // a global storage for assets, since redux can't store files(serialize files)
|
|
|
|
|
|
2024-09-11 19:06:04 +05:30
|
|
|
const [sidebarWidgets, setSidebarWidgets] = useState([])
|
|
|
|
|
const [canvasWidgets, setCanvasWidgets] = useState([]) // contains the reference to the widgets inside the canvas
|
|
|
|
|
|
|
|
|
|
const [activeSidebarWidget, setActiveSidebarWidget] = useState(null) // helps with the dnd overlay
|
|
|
|
|
|
|
|
|
|
const sensors = useSensors(
|
|
|
|
|
useSensor(PointerSensor)
|
|
|
|
|
)
|
2024-08-05 22:36:05 +05:30
|
|
|
|
2024-09-11 19:06:04 +05:30
|
|
|
const sidebarTabs = [
|
2024-08-04 22:47:43 +05:30
|
|
|
{
|
|
|
|
|
name: "Widgets",
|
|
|
|
|
icon: <LayoutFilled />,
|
2024-09-11 19:06:04 +05:30
|
|
|
content: <WidgetsContainer onWidgetsUpdate={(widgets) => setSidebarWidgets(widgets)}/>
|
2024-08-04 22:47:43 +05:30
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "Extensions",
|
|
|
|
|
icon: <ProductFilled />,
|
|
|
|
|
content: <></>
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "Uploads",
|
|
|
|
|
icon: <CloudUploadOutlined />,
|
2024-08-05 22:36:05 +05:30
|
|
|
content: <UploadsContainer assets={uploadedAssets}
|
|
|
|
|
onAssetUploadChange={(assets) => setUploadedAssets(assets)}/>
|
2024-08-04 22:47:43 +05:30
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
|
2024-09-11 19:06:04 +05:30
|
|
|
const handleDragStart = (event) => {
|
|
|
|
|
console.log("Dragging", event.active)
|
|
|
|
|
const draggedItem = sidebarWidgets.find((item) => item.name === event.active.id)
|
|
|
|
|
setActiveSidebarWidget(draggedItem)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const handleDragMove = (event) => {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const handleDragEnd = (event) => {
|
|
|
|
|
// add items to canvas from sidebar
|
|
|
|
|
const widgetItem = event.active.data.current?.title
|
|
|
|
|
|
|
|
|
|
if (event.over?.id !== "cart-droppable" || !widgetItem) return
|
|
|
|
|
// const temp = [...widgets]
|
|
|
|
|
// temp.push(widgetItem)
|
|
|
|
|
// setCanvasWidgets(temp)
|
|
|
|
|
setActiveSidebarWidget(null)
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2024-08-04 12:08:30 +05:30
|
|
|
return (
|
2024-09-08 21:58:53 +05:30
|
|
|
<div className="tw-w-full tw-h-[100vh] tw-flex tw-flex-col tw-bg-primaryBg">
|
|
|
|
|
<Header className="tw-h-[6vh]"/>
|
2024-09-11 19:06:04 +05:30
|
|
|
|
|
|
|
|
<DndContext sensors={sensors} collisionDetection={closestCorners}
|
|
|
|
|
onDragStart={handleDragStart}
|
|
|
|
|
onDragMove={handleDragMove}
|
|
|
|
|
onDragEnd={handleDragEnd}
|
|
|
|
|
>
|
|
|
|
|
<div className="tw-w-full tw-h-[94vh] tw-flex">
|
|
|
|
|
<Sidebar tabs={sidebarTabs}/>
|
|
|
|
|
<Canvas widgets={canvasWidgets}/>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
{/* dragOverlay (dnd-kit) helps move items from one container to another */}
|
|
|
|
|
<DragOverlay>
|
|
|
|
|
{activeSidebarWidget ? (
|
|
|
|
|
<DraggableWidgetCard name={activeSidebarWidget.name}
|
|
|
|
|
img={activeSidebarWidget.img}
|
|
|
|
|
url={activeSidebarWidget.url}
|
|
|
|
|
/>
|
|
|
|
|
):
|
|
|
|
|
null}
|
|
|
|
|
</DragOverlay>
|
|
|
|
|
|
|
|
|
|
</DndContext>
|
2024-08-04 12:08:30 +05:30
|
|
|
</div>
|
2024-09-11 19:06:04 +05:30
|
|
|
)
|
2024-08-04 12:08:30 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default App;
|