feat(composer): persist text + reply target per chat across restarts
This commit is contained in:
@@ -78,6 +78,7 @@ import { markRead as markMessagesReadRemote, useMessageReads } from '../lib/useM
|
||||
import { usePeerPresence } from '../lib/usePeerPresence';
|
||||
import { usePinnedMessages } from '../lib/usePinnedMessages';
|
||||
import { useTypingChannel } from '../lib/useTypingChannel';
|
||||
import { clearDraft, getDraftSync, setDraft } from '../lib/composerDraftStore';
|
||||
|
||||
// Discriminated union for rows inside the virtualized message list. Keeping
|
||||
// pending bubbles and the "load older" tile inside the same Virtuoso
|
||||
@@ -200,7 +201,10 @@ export function ConversationPage() {
|
||||
});
|
||||
}, [id, messages, myId]);
|
||||
|
||||
const [text, setText] = useState('');
|
||||
const [text, setText] = useState<string>(() => {
|
||||
if (!id) return '';
|
||||
return getDraftSync(id)?.text ?? '';
|
||||
});
|
||||
const [sending, setSending] = useState(false);
|
||||
const [sendError, setSendError] = useState<string | null>(null);
|
||||
const [stickToBottom, setStickToBottom] = useState(true);
|
||||
@@ -304,6 +308,21 @@ export function ConversationPage() {
|
||||
const fileInputRef = useRef<HTMLInputElement>(null);
|
||||
const composerRef = useRef<HTMLTextAreaElement>(null);
|
||||
|
||||
useEffect(() => {
|
||||
if (!id) return;
|
||||
const draft = getDraftSync(id);
|
||||
const savedReplyToId = draft?.replyToId ?? null;
|
||||
if (!savedReplyToId) return;
|
||||
if (replyTo?.id === savedReplyToId) return;
|
||||
const match = messages.find((m) => m.id === savedReplyToId);
|
||||
if (match) setReplyTo(match);
|
||||
}, [id, messages, replyTo?.id]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!id) return;
|
||||
setDraft(id, { text, replyToId: replyTo?.id ?? null });
|
||||
}, [id, text, replyTo?.id]);
|
||||
|
||||
useEffect(() => {
|
||||
if (firstUnreadComputedRef.current) return;
|
||||
if (!id || messages.length === 0) return;
|
||||
@@ -753,6 +772,7 @@ export function ConversationPage() {
|
||||
if (fileInputRef.current) fileInputRef.current.value = '';
|
||||
setStickToBottom(true);
|
||||
notifyStopTyping();
|
||||
if (id) clearDraft(id);
|
||||
} catch (err: unknown) {
|
||||
const code = extractErrorCode(err);
|
||||
setSendError(
|
||||
|
||||
Reference in New Issue
Block a user