]> Repos - mime-chat/commitdiff
scroll v1
authorAndrew Gundersen <gundersena@xavier.edu>
Sun, 14 Mar 2021 18:21:38 +0000 (13:21 -0500)
committerAndrew Gundersen <gundersena@xavier.edu>
Sun, 14 Mar 2021 18:21:38 +0000 (13:21 -0500)
src/components/messageItem.vue
src/modules/messages.ts
src/views/messenger.vue

index e8941fea91ee3379dcab03ace5d49bca494fe77d..63c58bd80a3118866bf0a0852c66606b3ae82f1d 100644 (file)
   .messageBox {
     display: flex;
     flex-direction: column;
+
+    // Animate on render.
+    animation-name: appear;
+    animation-duration: 0.25s;
   }
 
   #aiMessageBox {
     padding: 10px;
 
     border-radius: 18px;
-
-    // Animate on render.
-    animation-name: appear;
-    animation-duration: 0.25s;
   }
 
   @keyframes appear {
-    from {
+    10% {
       transform: scale(0.3);
     }
-    to {
+    100% {
       transform: scale(1);
     }
   }
index 654ca5952e77c0cd67453360823da2ff463af2f0..cdfb6f239cf2c14f6a9db5795917dc8a4a328b1f 100644 (file)
@@ -25,74 +25,52 @@ function deleteOldest() {
    messages.value.delete(lastKey);
 }
 
-
-
-
-
-
 // Is the message div scrolled to the bottom?
 let isScrolledToBottom: boolean;
 
 // Update isScrolledToBottom
 const updateScrollRef = () => {
   const e = document.getElementById("messenger")
-
   if (e) {
     isScrolledToBottom = e.scrollHeight - e.clientHeight <= e.scrollTop + 1
   }
-
 }
 
 // Adjust scroll after we add content to the messenger.
 const adjustScroll = () => {
   const e = document.getElementById("messenger")
-
   if (e) {
-
-    console.log(`Bottom? : ${isScrolledToBottom}`)
-    console.log(e.scrollHeight)
-    console.log(e.clientHeight)
-    console.log(e.scrollTop)
-
-    // // Scroll to bottom if isScrolledToBottom is true
     if (isScrolledToBottom) {
-      e.scrollTop = e.scrollHeight - e.clientHeight
+      e.scrollTo({
+        top: e.scrollHeight - e.clientHeight,
+        behavior: 'smooth'
+      });
     }
-
   }
-
 }
 
-
-
-
-
 export default function useMessages() {
 
     const addMessage = (m: RenderMessage) => {
       updateScrollRef() // must update before we add new elements.
 
-      console.log(`Adding message: ${m.content.text}`)
-
       // check for message limit before setting a new message.
       if (messages.value.size >= sizeLimit) deleteOldest();
-      
+
       messages.value.set(m.uid, m);
 
-      adjustScroll()
+      setTimeout(adjustScroll, 10);
     }
 
     const updateMessage = (a: Annotation) => {
         updateScrollRef()
 
-        console.log(`Updating message...`)
-
         // update message if in the map.
         const m = messages.value.get(a.uid)
         m.context = a.context
         m.text = a.text
 
-        adjustScroll()
+        setTimeout(adjustScroll, 10);
 
         return m
     }
index 1e1e70b976d62b3d3fb9aa8a0fb8e13f5e4bb98a..1e5b56bdd1a5d80adc8e619ad5eb8cb1485e4d9d 100644 (file)
@@ -103,7 +103,6 @@ export default defineComponent({
 #messenger {
   width: 100vw;
   height: 100vh;
-
   overflow: auto;
 }