From a2a4696fdbd6440269d576aeba7b25b2ea40d9bf Mon Sep 17 00:00:00 2001
From: Kristóf Marussy <kristof@marussy.com>
Date: Tue, 12 Sep 2023 21:59:50 +0200
Subject: feat: connect model generator to UI

---
 subprojects/frontend/src/editor/GenerateButton.tsx | 20 ++++++++++++++++++--
 1 file changed, 18 insertions(+), 2 deletions(-)

(limited to 'subprojects/frontend/src/editor/GenerateButton.tsx')

diff --git a/subprojects/frontend/src/editor/GenerateButton.tsx b/subprojects/frontend/src/editor/GenerateButton.tsx
index 5bac0464..b8dcd531 100644
--- a/subprojects/frontend/src/editor/GenerateButton.tsx
+++ b/subprojects/frontend/src/editor/GenerateButton.tsx
@@ -5,6 +5,7 @@
  */
 
 import CancelIcon from '@mui/icons-material/Cancel';
+import CloseIcon from '@mui/icons-material/Close';
 import PlayArrowIcon from '@mui/icons-material/PlayArrow';
 import { observer } from 'mobx-react-lite';
 
@@ -28,8 +29,10 @@ const GenerateButton = observer(function GenerateButton({
     );
   }
 
-  const { analyzing, errorCount, warningCount, semanticsError } =
-    editorStore.delayedErrors;
+  const {
+    delayedErrors: { analyzing, errorCount, warningCount, semanticsError },
+    generating,
+  } = editorStore;
 
   if (analyzing) {
     return (
@@ -39,6 +42,18 @@ const GenerateButton = observer(function GenerateButton({
     );
   }
 
+  if (generating) {
+    return (
+      <AnimatedButton
+        color="inherit"
+        onClick={() => editorStore.cancelModelGeneration()}
+        startIcon={<CloseIcon />}
+      >
+        Cancel
+      </AnimatedButton>
+    );
+  }
+
   if (semanticsError !== undefined && editorStore.opened) {
     return (
       <AnimatedButton
@@ -83,6 +98,7 @@ const GenerateButton = observer(function GenerateButton({
       disabled={!editorStore.opened}
       color={warningCount > 0 ? 'warning' : 'primary'}
       startIcon={<PlayArrowIcon />}
+      onClick={() => editorStore.startModelGeneration()}
     >
       {summary === '' ? GENERATE_LABEL : `${GENERATE_LABEL} (${summary})`}
     </AnimatedButton>
-- 
cgit v1.2.3-70-g09d2

