From 7b4446d9eef60a4d45717cb2b7c514fe6d12a9c2 Mon Sep 17 00:00:00 2001 From: paul Date: Fri, 27 Sep 2024 11:42:34 +0530 Subject: [PATCH] added file upload tool and fileUploadProvider --- src/App.js | 32 ++++---- src/canvas/activeWidgetContext.js | 2 +- src/canvas/constants/tools.js | 3 +- src/canvas/context/widgetContext.js | 2 +- src/canvas/resizeContainer.js | 5 +- src/canvas/toolbar.js | 86 +++++++++++++++++++- src/canvas/widgets/base.js | 2 +- src/canvas/widgets/draggableWidgetContext.js | 2 +- src/components/cards.js | 65 ++++++++------- src/contexts/fileUploadContext.js | 17 ++++ src/frameworks/tkinter/engine/code.js | 2 +- src/frameworks/tkinter/widgets/label.js | 14 +++- src/index.js | 5 +- src/sidebar/uploadsContainer.js | 38 ++++++--- 14 files changed, 205 insertions(+), 70 deletions(-) create mode 100644 src/contexts/fileUploadContext.js diff --git a/src/App.js b/src/App.js index 53395cc..0649cd7 100644 --- a/src/App.js +++ b/src/App.js @@ -16,6 +16,7 @@ import PluginsContainer from './sidebar/pluginsContainer' import TkinterPluginWidgets from './frameworks/tkinter/sidebarPlugins' import FrameWorks from './constants/frameworks' import generateTkinterCode from './frameworks/tkinter/engine/code' +import { FileUploadProvider, useFileUploadContext } from './contexts/fileUploadContext' function App() { @@ -28,18 +29,18 @@ function App() { const [projectName, setProjectName] = useState('untitled project') const [UIFramework, setUIFramework] = useState(FrameWorks.TKINTER) - const [uploadedAssets, setUploadedAssets] = useState([]) // a global storage for assets, since redux can't store files(serialize files) + // const [uploadedAssets, setUploadedAssets] = useState([]) // a global storage for assets, since redux can't store files(serialize files) const [sidebarWidgets, setSidebarWidgets] = useState(TkinterWidgets || []) + // NOTE: the below reference is no longer required const [canvasWidgets, setCanvasWidgets] = useState([]) // contains the reference to the widgets inside the canvas - const [canvasWidgetRefs, setCanvasWidgetRefs] = useState([]) const sidebarTabs = [ { name: "Widgets", icon: , - content: setSidebarWidgets(widgets)}/> + content: setSidebarWidgets(widgets)}/> }, { name: "Plugins", @@ -49,8 +50,7 @@ function App() { { name: "Uploads", icon: , - content: setUploadedAssets(assets)}/> + content: } ] @@ -160,18 +160,16 @@ function App() {

Are you sure you want to change the framework? This will clear the canvas.

*/} - -
- - - {/* */} - - {/* */} -
- - {/* dragOverlay (dnd-kit) helps move items from one container to another */} - -
+ +
+ + + {/* */} + + {/* */} +
+ {/* dragOverlay (dnd-kit) helps move items from one container to another */} +
) } diff --git a/src/canvas/activeWidgetContext.js b/src/canvas/activeWidgetContext.js index f82ed90..f9f4600 100644 --- a/src/canvas/activeWidgetContext.js +++ b/src/canvas/activeWidgetContext.js @@ -3,7 +3,7 @@ import React, { createContext, Component, useContext, useState, createRef, useMe // NOTE: using this context provider causes many re-rendering when the canvas is panned the toolbar updates unnecessarily - +// use draggable widgetcontext // Create the Context export const ActiveWidgetContext = createContext() diff --git a/src/canvas/constants/tools.js b/src/canvas/constants/tools.js index c7e4af9..01b4ec3 100644 --- a/src/canvas/constants/tools.js +++ b/src/canvas/constants/tools.js @@ -9,7 +9,8 @@ const Tools = { INPUT_LIST: "input_list", INPUT_RADIO_LIST: "input_radio_list", - LAYOUT_MANAGER: "layout_manager" + LAYOUT_MANAGER: "layout_manager", + UPLOADED_LIST: "uploaded_list", } diff --git a/src/canvas/context/widgetContext.js b/src/canvas/context/widgetContext.js index 6a9dbd9..c640dd0 100644 --- a/src/canvas/context/widgetContext.js +++ b/src/canvas/context/widgetContext.js @@ -2,7 +2,7 @@ import React, { createContext, Component } from 'react' const WidgetContext = createContext() -// NOTE: Don't use context provider +// NOTE: Don't use this context provider class WidgetProvider extends Component { state = { diff --git a/src/canvas/resizeContainer.js b/src/canvas/resizeContainer.js index 1996ae2..3a04150 100644 --- a/src/canvas/resizeContainer.js +++ b/src/canvas/resizeContainer.js @@ -2,7 +2,10 @@ import Cursor from "./constants/cursor" import Widget from "./widgets/base" import { useEffect, useState } from "react" -// FIXME: when using this if the widhet has invisible swappable area, this won't work + +// NOTE: Not in use + +// FIXME: when using this if the widget has invisible swappable area, this won't work /** * * @param {Widget} - selectedWidget diff --git a/src/canvas/toolbar.js b/src/canvas/toolbar.js index adb5944..95c73db 100644 --- a/src/canvas/toolbar.js +++ b/src/canvas/toolbar.js @@ -1,4 +1,4 @@ -import { memo, useEffect, useState } from "react" +import { memo, useEffect, useMemo, useState } from "react" import { Checkbox, ColorPicker, Input, @@ -10,6 +10,8 @@ import Tools from "./constants/tools.js" import { useActiveWidget } from "./activeWidgetContext.js" import { Layouts } from "./constants/layouts.js" import { DynamicRadioInputList } from "../components/inputs.js" +import { useFileUploadContext } from "../contexts/fileUploadContext.js" +import { AudioOutlined, FileImageOutlined, FileTextOutlined, VideoCameraOutlined } from "@ant-design/icons" // FIXME: Maximum recursion error @@ -28,6 +30,56 @@ const CanvasToolBar = memo(({ isOpen, widgetType, attrs = {} }) => { const [toolbarOpen, setToolbarOpen] = useState(isOpen) const [toolbarAttrs, setToolbarAttrs] = useState(attrs) + const {uploadedAssets} = useFileUploadContext() + + const uploadItems = useMemo(() => { + + const returnComponentBasedOnFileType = (file) => { + if (file.fileType === "image"){ + return ( +
+ + {file.name} +
+ ) + }else if (file.fileType === "video"){ + return ( +
+ + {file.name} +
+ ) + }else if (file.fileType === "audio"){ + + return ( +
+ + {file.name} +
+ ) + + }else{ + return ( +
+ + {file.name} +
+ ) + } + + } + + const uploadList = uploadedAssets.map((file, idx) => ({ + value: file.name, + label: returnComponentBasedOnFileType(file), + fileType: file.fileType, + type: file.type, + // previewUrl: file.previewUrl, + })) + + return uploadList + + }, [uploadedAssets]) useEffect(() => { setToolbarOpen(isOpen) @@ -45,6 +97,33 @@ const CanvasToolBar = memo(({ isOpen, widgetType, attrs = {} }) => { } + const renderUploadDropDown = (val, filter) => { + + + let uploadOptions = [...uploadItems] + + if (filter){ + uploadOptions = uploadOptions.filter((value, idx) => filter.includes(value.type)) + } + + return ( +
+ +