submitCompose: accept an options object

This commit is contained in:
Alex Gleason 2023-10-13 11:47:24 -05:00
parent 7863e6225e
commit 181df09039
No known key found for this signature in database
GPG Key ID: 7211D1F99744FBB7
2 changed files with 12 additions and 5 deletions

View File

@ -299,8 +299,15 @@ const validateSchedule = (state: RootState, composeId: string) => {
return schedule.getTime() > fiveMinutesFromNow.getTime(); return schedule.getTime() > fiveMinutesFromNow.getTime();
}; };
const submitCompose = (composeId: string, routerHistory?: History, force = false) => interface SubmitComposeOpts {
history?: History;
force?: boolean;
}
const submitCompose = (composeId: string, opts: SubmitComposeOpts = {}) =>
(dispatch: AppDispatch, getState: () => RootState) => { (dispatch: AppDispatch, getState: () => RootState) => {
const { history, force = false } = opts;
if (!isLoggedIn(getState)) return; if (!isLoggedIn(getState)) return;
const state = getState(); const state = getState();
@ -324,7 +331,7 @@ const submitCompose = (composeId: string, routerHistory?: History, force = false
dispatch(openModal('MISSING_DESCRIPTION', { dispatch(openModal('MISSING_DESCRIPTION', {
onContinue: () => { onContinue: () => {
dispatch(closeModal('MISSING_DESCRIPTION')); dispatch(closeModal('MISSING_DESCRIPTION'));
dispatch(submitCompose(composeId, routerHistory, true)); dispatch(submitCompose(composeId, { history, force: true }));
}, },
})); }));
return; return;
@ -361,8 +368,8 @@ const submitCompose = (composeId: string, routerHistory?: History, force = false
} }
dispatch(createStatus(params, idempotencyKey, statusId)).then(function(data) { dispatch(createStatus(params, idempotencyKey, statusId)).then(function(data) {
if (!statusId && data.visibility === 'direct' && getState().conversations.mounted <= 0 && routerHistory) { if (!statusId && data.visibility === 'direct' && getState().conversations.mounted <= 0 && history) {
routerHistory.push('/messages'); history.push('/messages');
} }
handleComposeSubmit(dispatch, getState, composeId, data, status, !!statusId); handleComposeSubmit(dispatch, getState, composeId, data, status, !!statusId);
}).catch(function(error) { }).catch(function(error) {

View File

@ -152,7 +152,7 @@ const ComposeForm = <ID extends string>({ id, shouldCondense, autoFocus, clickab
return; return;
} }
dispatch(submitCompose(id, history)); dispatch(submitCompose(id, { history }));
editorRef.current?.dispatchCommand(CLEAR_EDITOR_COMMAND, undefined); editorRef.current?.dispatchCommand(CLEAR_EDITOR_COMMAND, undefined);
}; };