Support pasting images as attachments. Fixes #87.
authorjamesjulich <51384945+jamesjulich@users.noreply.github.com>
Mon, 13 Sep 2021 14:34:08 +0000 (09:34 -0500)
committerjamesjulich <51384945+jamesjulich@users.noreply.github.com>
Mon, 13 Sep 2021 14:34:08 +0000 (09:34 -0500)
src/app/organisms/room/RoomViewInput.jsx

index a72f1e34eaeb842b5ee25cdb407dd0fbe782d114..1e0f1269942907f1a494b37e567fdc9f3a79465e 100644 (file)
@@ -285,6 +285,32 @@ function RoomViewInput({
     }
   }
 
+  function handlePaste(e) {
+    if (e.clipboardData === false) {
+      return;
+    }
+
+    if (e.clipboardData.items === undefined) {
+      return;
+    }
+
+    for (let i = 0; i < e.clipboardData.items.length; i += 1) {
+      const item = e.clipboardData.items[i];
+      if (item.type.indexOf('image') !== -1) {
+        const image = item.getAsFile();
+        if (attachment === null) {
+          setAttachment(image);
+          if (image !== null) {
+            roomsInput.setAttachment(roomId, image);
+            return;
+          }
+        } else {
+          return;
+        }
+      }
+    }
+  }
+
   function addEmoji(emoji) {
     textAreaRef.current.value += emoji.unicode;
   }
@@ -315,6 +341,7 @@ function RoomViewInput({
               <TextareaAutosize
                 ref={textAreaRef}
                 onChange={handleMsgTyping}
+                onPaste={handlePaste}
                 onResize={() => timelineScroll.autoReachBottom()}
                 onKeyDown={handleKeyDown}
                 placeholder="Send a message..."