From 3d54a1abf375f94699b6ebd3eb9e8d66eefe59c9 Mon Sep 17 00:00:00 2001 From: Saksham Tyagi Date: Sat, 4 Nov 2023 02:33:56 +0530 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20widget?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/Setting.tsx | 125 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 122 insertions(+), 3 deletions(-) diff --git a/frontend/src/Setting.tsx b/frontend/src/Setting.tsx index a52bde02..f68df653 100644 --- a/frontend/src/Setting.tsx +++ b/frontend/src/Setting.tsx @@ -33,6 +33,11 @@ const Setting: React.FC = () => { setPrompts(prompts.filter((prompt) => prompt !== name)); setSelectedPrompt(''); // Clear the selected prompt }; + const [widgetScreenshot, setWidgetScreenshot] = useState(null); + + const updateWidgetScreenshot = (screenshot: File | null) => { + setWidgetScreenshot(screenshot); + }; // Function to add a new document const addDocument = () => { @@ -108,6 +113,13 @@ const Setting: React.FC = () => { onClose={toggleAddDocumentModal} /> )} + + {/* {activeTab === 'Widgets' && ( + + )} */} ); @@ -151,7 +163,12 @@ const Setting: React.FC = () => { /> ); case 'Widgets': - return ; + return ( + + ); default: return null; } @@ -498,6 +515,108 @@ const AddDocumentModal: React.FC = ({ ); }; -const Widgets: React.FC = () => { - return
This is widgets
; +const Widgets: React.FC<{ + widgetScreenshot: File | null; + onWidgetScreenshotChange: (screenshot: File | null) => void; +}> = ({ widgetScreenshot, onWidgetScreenshotChange }) => { + const widgetSources = ['Source 1', 'Source 2', 'Source 3']; + const widgetMethods = ['Method 1', 'Method 2', 'Method 3']; + const widgetTypes = ['Type 1', 'Type 2', 'Type 3']; + + const [selectedWidgetSource, setSelectedWidgetSource] = useState( + widgetSources[0], + ); + const [selectedWidgetMethod, setSelectedWidgetMethod] = useState( + widgetMethods[0], + ); + const [selectedWidgetType, setSelectedWidgetType] = useState(widgetTypes[0]); + + // const [widgetScreenshot, setWidgetScreenshot] = useState(null); + const [widgetCode, setWidgetCode] = useState(''); // Your widget code state + + const handleScreenshotChange = ( + event: React.ChangeEvent, + ) => { + const files = event.target.files; + + if (files && files.length > 0) { + const selectedScreenshot = files[0]; + onWidgetScreenshotChange(selectedScreenshot); // Update the screenshot in the parent component + } + }; + + const handleCopyToClipboard = () => { + // Create a new textarea element to select the text + const textArea = document.createElement('textarea'); + textArea.value = widgetCode; + document.body.appendChild(textArea); + + // Select and copy the text + textArea.select(); + document.execCommand('copy'); + + // Clean up the textarea element + document.body.removeChild(textArea); + }; + + return ( +
+
+

Widget Source

+ +
+
+

Widget Method

+ +
+
+

Widget Type

+ +
+
+

Widget Code Snippet

+