mirror of
https://github.com/stoatchat/for-legacy-web.git
synced 2026-03-07 01:15:28 +00:00
Fix: Avoid going through react-redux to update draft.
This commit is contained in:
@@ -20,8 +20,7 @@ import {
|
|||||||
SMOOTH_SCROLL_ON_RECEIVE,
|
SMOOTH_SCROLL_ON_RECEIVE,
|
||||||
} from "../../../lib/renderer/Singleton";
|
} from "../../../lib/renderer/Singleton";
|
||||||
|
|
||||||
import { dispatch } from "../../../redux";
|
import { dispatch, getState } from "../../../redux";
|
||||||
import { connectState } from "../../../redux/connector";
|
|
||||||
import { Reply } from "../../../redux/reducers/queue";
|
import { Reply } from "../../../redux/reducers/queue";
|
||||||
|
|
||||||
import { SoundContext } from "../../../context/Settings";
|
import { SoundContext } from "../../../context/Settings";
|
||||||
@@ -44,7 +43,6 @@ import ReplyBar from "./bars/ReplyBar";
|
|||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
channel: Channel;
|
channel: Channel;
|
||||||
draft?: string;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export type UploadState =
|
export type UploadState =
|
||||||
@@ -94,9 +92,11 @@ const Action = styled.div`
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
// ! FIXME: add to app config and load from app config
|
// ! 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<UploadState>({
|
const [uploadState, setUploadState] = useState<UploadState>({
|
||||||
type: "none",
|
type: "none",
|
||||||
});
|
});
|
||||||
@@ -124,6 +124,8 @@ function MessageBox({ channel, draft }: Props) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function setMessage(content?: string) {
|
function setMessage(content?: string) {
|
||||||
|
setDraft(content ?? '');
|
||||||
|
|
||||||
if (content) {
|
if (content) {
|
||||||
dispatch({
|
dispatch({
|
||||||
type: "SET_DRAFT",
|
type: "SET_DRAFT",
|
||||||
@@ -486,13 +488,3 @@ function MessageBox({ channel, draft }: Props) {
|
|||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default connectState<Omit<Props, "dispatch" | "draft">>(
|
|
||||||
MessageBox,
|
|
||||||
(state, { channel }) => {
|
|
||||||
return {
|
|
||||||
draft: state.drafts[channel._id],
|
|
||||||
};
|
|
||||||
},
|
|
||||||
true,
|
|
||||||
);
|
|
||||||
|
|||||||
@@ -82,3 +82,7 @@ store.subscribe(() => {
|
|||||||
export function dispatch(action: Action) {
|
export function dispatch(action: Action) {
|
||||||
store.dispatch(action);
|
store.dispatch(action);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getState(): State {
|
||||||
|
return store.getState();
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user