From 9861494e341b482a522d0ecc6a2194bb12a769fb Mon Sep 17 00:00:00 2001
From: Samuel Newman <mozzius@protonmail.com>
Date: Tue, 14 May 2024 18:55:43 +0100
Subject: [🐴] Message drafts (#3993)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

* drafts

* don't throw if no convo ID

* Remove labs package

---------

Co-authored-by: Eric Bailey <git@esb.lol>
---
 src/screens/Messages/Conversation/MessageInput.web.tsx | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

(limited to 'src/screens/Messages/Conversation/MessageInput.web.tsx')

diff --git a/src/screens/Messages/Conversation/MessageInput.web.tsx b/src/screens/Messages/Conversation/MessageInput.web.tsx
index 2ee03bb31..b9506b5bb 100644
--- a/src/screens/Messages/Conversation/MessageInput.web.tsx
+++ b/src/screens/Messages/Conversation/MessageInput.web.tsx
@@ -6,6 +6,10 @@ import Graphemer from 'graphemer'
 import TextareaAutosize from 'react-textarea-autosize'
 
 import {MAX_DM_GRAPHEME_LENGTH} from '#/lib/constants'
+import {
+  useMessageDraft,
+  useSaveMessageDraft,
+} from '#/state/messages/message-drafts'
 import * as Toast from '#/view/com/util/Toast'
 import {atoms as a, useTheme} from '#/alf'
 import {PaperPlane_Stroke2_Corner0_Rounded as PaperPlane} from '#/components/icons/PaperPlane'
@@ -18,7 +22,8 @@ export function MessageInput({
 }) {
   const {_} = useLingui()
   const t = useTheme()
-  const [message, setMessage] = React.useState('')
+  const {getDraft, clearDraft} = useMessageDraft()
+  const [message, setMessage] = React.useState(getDraft)
 
   const onSubmit = React.useCallback(() => {
     if (message.trim() === '') {
@@ -28,9 +33,10 @@ export function MessageInput({
       Toast.show(_(msg`Message is too long`))
       return
     }
+    clearDraft()
     onSendMessage(message.trimEnd())
     setMessage('')
-  }, [message, onSendMessage, _])
+  }, [message, onSendMessage, _, clearDraft])
 
   const onKeyDown = React.useCallback(
     (e: React.KeyboardEvent<HTMLTextAreaElement>) => {
@@ -50,6 +56,8 @@ export function MessageInput({
     [],
   )
 
+  useSaveMessageDraft(message)
+
   return (
     <View style={a.p_sm}>
       <View
-- 
cgit 1.4.1

