From 9453dd1349abec54b31477f0d71f7693ae84c956 Mon Sep 17 00:00:00 2001
From: YasinOnm08 <onmazyasin4@gmail.com>
Date: Tue, 1 Oct 2024 14:29:15 +0200
Subject: [PATCH] stop button

---
 app/backend/InputOutputHandler.tsx      |  8 +++-
 app/components/ConversationFrontend.tsx | 48 +++++++++++++++++------
 app/styles/output.css                   | 51 ++++++++++++++++++++++++-
 3 files changed, 94 insertions(+), 13 deletions(-)

diff --git a/app/backend/InputOutputHandler.tsx b/app/backend/InputOutputHandler.tsx
index 983a512..b8f22a8 100644
--- a/app/backend/InputOutputHandler.tsx
+++ b/app/backend/InputOutputHandler.tsx
@@ -176,7 +176,7 @@ const InputOutputBackend: React.FC = () => {
             }
           }
           setInputMessage("")
-          postWorkerRef.current.postMessage({ messages: [...messages, { role: "user", content: inputValue }], ai_model: localStorage.getItem('model'), model_type: type, access_token: accessToken, api_key: api_key })
+          postWorkerRef.current.postMessage({ messages: [...messages, { role: "user", content: inputValue }], ai_model: "llama3.2", model_type: type, access_token: accessToken, api_key: api_key })
           startGetWorker()
         }
       }
@@ -226,6 +226,11 @@ const InputOutputBackend: React.FC = () => {
     }
   };
 
+  const handleStopClick = () => { 
+    endGetWorker()
+    getNewToken()
+  }
+
   const handleResendClick = () => {
     var temporary_message = messages[messages.length - 2]['content']
     const updatedMessages = messages.slice(0, -2)
@@ -272,6 +277,7 @@ const InputOutputBackend: React.FC = () => {
       <ConversationFrontend
         ref={conversationRef}
         messages={messages}
+        onStopClick={handleStopClick}
         onResendClick={handleResendClick}
         onEditClick={handleEditClick}
         onCopyClick={handleCopyClick}
diff --git a/app/components/ConversationFrontend.tsx b/app/components/ConversationFrontend.tsx
index 5a5632f..1056c87 100644
--- a/app/components/ConversationFrontend.tsx
+++ b/app/components/ConversationFrontend.tsx
@@ -7,6 +7,7 @@ type Message = {
 
 interface ConversationProps {
   messages: Message[];
+  onStopClick: () => void;
   onResendClick: () => void;
   onEditClick: () => void;
   onCopyClick: () => void;
@@ -14,10 +15,21 @@ interface ConversationProps {
 }
 
 const ConversationFrontend = React.forwardRef<HTMLDivElement, ConversationProps>(
-  ({ messages, onResendClick, onEditClick, onCopyClick, isClicked }, ref: ForwardedRef<HTMLDivElement>) => {
+  ({ messages,onStopClick, onResendClick, onEditClick, onCopyClick, isClicked }, ref: ForwardedRef<HTMLDivElement>) => {
 
     const messagesEndRef = useRef<HTMLDivElement | null>(null)
 
+    useEffect(() => {
+    if (messagesEndRef.current) {
+      const rect = messagesEndRef.current.getBoundingClientRect();
+      console.log('Position of the target div:');
+      console.log('Top:', rect.top);      // Distance from the top of the viewport
+      console.log('Left:', rect.left);    // Distance from the left of the viewport
+      console.log('Width:', rect.width);   // Width of the element
+      console.log('Height:', rect.height); // Height of the element
+    }
+  }, [messages]);
+
     useEffect(() => {
       messagesEndRef.current?.scrollIntoView()
     }, [messages])
@@ -40,16 +52,30 @@ const ConversationFrontend = React.forwardRef<HTMLDivElement, ConversationProps>
           })}
 
           <div className="button-container">
-            <button type="button" onClick={onResendClick}>
-              <img src="/img/resend.svg" alt="resend" />
-            </button>
-            <button type="button" onClick={onEditClick}>
-              <img src="/img/edit.svg" alt="edit" />
-            </button>
-            <button type="button" onClick={onCopyClick}>
-              <img src="/img/copy.svg" alt="copy" />
-            </button>
-            <p id="copiedText" style={{ opacity: isClicked ? "1" : "0", transition: "all 0.3s ease-in-out" }}>Copied!</p>
+            <div className="tooltip">
+              <button type="button" onClick={onStopClick}>
+                <img src="/img/resend.svg" alt="stop" />
+              </button>
+              <span className="tooltiptext">Stop</span>
+            </div>
+            <div className="tooltip">
+              <button type="button" onClick={onResendClick}>
+                <img src="/img/resend.svg" alt="resend" />
+              </button>
+              <span className="tooltiptext">Resend</span>
+            </div>
+            <div className="tooltip">
+              <button type="button" onClick={onEditClick}>
+                <img src="/img/edit.svg" alt="edit" />
+              </button>
+              <span className="tooltiptext">Edit</span>
+            </div>
+            <div className="tooltip">
+              <button type="button" onClick={onCopyClick}>
+                <img src="/img/copy.svg" alt="copy" />
+              </button>
+              <span className="tooltiptext">{isClicked?"Copied!": "Copy" }</span>
+            </div>
           </div>
           <div ref={messagesEndRef} />
         </div>
diff --git a/app/styles/output.css b/app/styles/output.css
index 179f174..cb48ee8 100644
--- a/app/styles/output.css
+++ b/app/styles/output.css
@@ -20,7 +20,7 @@
     flex-direction: column;
     padding-left: 10px;
     overflow-y: auto;
-    max-height: 80vh;
+    height: 80vh;
     background-color: var(--output-background-color);
     border-radius: 10px;
     scroll-behavior: smooth;
@@ -72,6 +72,55 @@
     width: 20px;
 }
 
+.tooltip {
+    position: relative;
+    display: inline-block;
+    margin: 5px;
+    cursor: pointer;
+}
+
+.tooltip .tooltiptext {
+    visibility: hidden;
+    background-color: var(--user-message-background-color);
+    color: var(--text-color);
+    text-align: center;
+    padding: 5px;
+    border-radius: 4px;
+    font-size: calc(var(--font-size)*0.8);
+
+    /* Position the tooltip */
+    position: absolute;
+    top: 125%;
+    /* Adjusts tooltip to be below the button */
+    left: 50%;
+    transform: translateX(-50%);
+    /* Center the tooltip */
+    white-space: nowrap;
+    /* Prevent line breaks */
+
+    /* Add smooth transition */
+    opacity: 0;
+    transition: all 0.3s;
+}
+
+.tooltip .tooltiptext::after {
+    content: "";
+    position: absolute;
+    bottom: 100%;
+    /* Arrow on top of tooltip */
+    left: 50%;
+    transform: translateX(-50%);
+    border-width: 5px;
+    border-style: solid;
+    border-color: transparent transparent var(--user-message-background-color) transparent;
+}
+
+/* Show the tooltip on hover */
+.tooltip:hover .tooltiptext {
+    visibility: visible;
+    opacity: 1;
+}
+
 #copiedText{
     margin-top: 1em;
     cursor:default;