From ea6582545420253a37631c2e642f7abe57c06738 Mon Sep 17 00:00:00 2001 From: Paul Date: Tue, 6 Jul 2021 11:07:42 +0100 Subject: [PATCH] Fix: Avoid going through react-redux to update draft. --- .../common/messaging/MessageBox.tsx | 22 ++++++------------- src/redux/index.ts | 4 ++++ 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/src/components/common/messaging/MessageBox.tsx b/src/components/common/messaging/MessageBox.tsx index 1243cbb3..d6cad740 100644 --- a/src/components/common/messaging/MessageBox.tsx +++ b/src/components/common/messaging/MessageBox.tsx @@ -20,8 +20,7 @@ import { SMOOTH_SCROLL_ON_RECEIVE, } from "../../../lib/renderer/Singleton"; -import { dispatch } from "../../../redux"; -import { connectState } from "../../../redux/connector"; +import { dispatch, getState } from "../../../redux"; import { Reply } from "../../../redux/reducers/queue"; import { SoundContext } from "../../../context/Settings"; @@ -44,7 +43,6 @@ import ReplyBar from "./bars/ReplyBar"; type Props = { channel: Channel; - draft?: string; }; export type UploadState = @@ -94,9 +92,11 @@ const Action = styled.div` `; // ! FIXME: add to app config and load from app config -export const CAN_UPLOAD_AT_ONCE = 5; +export const CAN_UPLOAD_AT_ONCE = 4; + +export default function MessageBox({ channel }: Props) { + const [draft, setDraft] = useState(getState().drafts[channel._id] ?? ''); -function MessageBox({ channel, draft }: Props) { const [uploadState, setUploadState] = useState({ type: "none", }); @@ -124,6 +124,8 @@ function MessageBox({ channel, draft }: Props) { } function setMessage(content?: string) { + setDraft(content ?? ''); + if (content) { dispatch({ type: "SET_DRAFT", @@ -486,13 +488,3 @@ function MessageBox({ channel, draft }: Props) { ); } - -export default connectState>( - MessageBox, - (state, { channel }) => { - return { - draft: state.drafts[channel._id], - }; - }, - true, -); diff --git a/src/redux/index.ts b/src/redux/index.ts index 24db71bf..171acfb9 100644 --- a/src/redux/index.ts +++ b/src/redux/index.ts @@ -82,3 +82,7 @@ store.subscribe(() => { export function dispatch(action: Action) { store.dispatch(action); } + +export function getState(): State { + return store.getState(); +}