From f74643a91d44196909cb82c3170bf93f77353e0c Mon Sep 17 00:00:00 2001 From: TheCodeTherapy Date: Wed, 9 Oct 2024 08:50:55 +0100 Subject: [PATCH] improves MML live code editor UI --- .../EditorPanelComponent.module.css | 25 ++++++++++++ .../EditorPanel/EditorPanelComponent.tsx | 38 ++++++++++++++++--- 2 files changed, 58 insertions(+), 5 deletions(-) diff --git a/packages/3d-web-client-editor/src/editor-ui/components/EditorPanel/EditorPanelComponent.module.css b/packages/3d-web-client-editor/src/editor-ui/components/EditorPanel/EditorPanelComponent.module.css index b7473a3..3c8fe0e 100644 --- a/packages/3d-web-client-editor/src/editor-ui/components/EditorPanel/EditorPanelComponent.module.css +++ b/packages/3d-web-client-editor/src/editor-ui/components/EditorPanel/EditorPanelComponent.module.css @@ -127,6 +127,31 @@ height: 30px; padding: 0px 0px 0px 12px; line-height: 30px; + display: inline-flex; + flex-direction: row; +} + +.controls { + margin: 0px 3px 0px auto; +} + +.button { + color: #dde; + cursor: pointer; + background-color: rgba(30, 30, 30, 0.3); + border: none; + border-radius: 5px; + transition: all .3s ease-in-out; + padding: 4px; +} + +.button:hover { + background-color: rgba(119, 170, 255, 0.9); +} + +.actionText { + font-weight: 900; + color: white; } .headerTitle { diff --git a/packages/3d-web-client-editor/src/editor-ui/components/EditorPanel/EditorPanelComponent.tsx b/packages/3d-web-client-editor/src/editor-ui/components/EditorPanel/EditorPanelComponent.tsx index 6969a8d..8da05bc 100644 --- a/packages/3d-web-client-editor/src/editor-ui/components/EditorPanel/EditorPanelComponent.tsx +++ b/packages/3d-web-client-editor/src/editor-ui/components/EditorPanel/EditorPanelComponent.tsx @@ -33,6 +33,8 @@ const EditorPanelComponent = (props: EditorPanelProps, ref: ForwardedRef([]); const [selectedDocument, setSelectedDocument] = useState(""); // Controls currently selected doc const [fetching, setFetching] = useState(true); + const [fetchedValue, setFetchedValue] = useState(""); + const [canApply, setCanApply] = useState(false); const { onUpdate } = props; @@ -48,8 +50,9 @@ const EditorPanelComponent = (props: EditorPanelProps, ref: ForwardedRef { + if (content === fetchedValue) { + return; + } try { const response = await fetch(`/mml-documents/${docName}`, { method: "POST", @@ -98,12 +104,14 @@ const EditorPanelComponent = (props: EditorPanelProps, ref: ForwardedRef fetchDocumentContent(docName)} // Moved onClick here + onClick={() => fetchDocumentContent(docName)} > {docName} {documentsWithCopies.includes(docName) && ( + )} + +
setEditorValue(val)} + onChange={(val) => { + setCanApply(val !== fetchedValue); + setEditorValue(val); + }} autoFocus={true} />