Skip to content

Commit

Permalink
[MA-22]: Added aria-live property for message sent status
Browse files Browse the repository at this point in the history
  • Loading branch information
ayush-chauhan233 committed Dec 19, 2024
1 parent 76a3af6 commit 08cd563
Showing 1 changed file with 29 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {haveIChannelPermission} from 'mattermost-redux/selectors/entities/roles'
import {getCurrentUserId, isCurrentUserGuestUser, getStatusForUserId, makeGetDisplayName} from 'mattermost-redux/selectors/entities/users';

import * as GlobalActions from 'actions/global_actions';
import type {CreatePostOptions} from 'actions/post_actions';
import {actionOnGlobalItemsWithPrefix} from 'actions/storage';
import type {SubmitPostReturnType} from 'actions/views/create_comment';
import {removeDraft, updateDraft} from 'actions/views/drafts';
Expand Down Expand Up @@ -342,6 +343,19 @@ const AdvancedTextEditor = ({
isInEditMode,
);

const onSubmit = useCallback((submittingDraft?: PostDraft, schedulingInfo?: SchedulingInfo, options?: CreatePostOptions) => {
handleSubmit(submittingDraft, schedulingInfo, options);
if (!errorClass) {
const messageStatusElement = document.getElementById('sentMessageStatus');
const messageStatusInnerText = messageStatusElement?.innerText;
if (messageStatusInnerText === 'Message Sent') {
messageStatusElement!.innerHTML = 'Message Sent  ';
} else {
messageStatusElement!.innerText = 'Message Sent';
}
}
}, [errorClass, handleSubmit]);

const handleCancel = useCallback(() => {
// This resets the draft to the post's original content
handleDraftChange({
Expand All @@ -367,8 +381,8 @@ const AdvancedTextEditor = ({
return;
}

handleSubmit();
}, [dispatch, draft, handleSubmit, isInEditMode, isRHS]);
onSubmit();
}, [dispatch, draft, onSubmit, isInEditMode, isRHS]);

const [handleKeyDown, postMsgKeyPress] = useKeyHandler(
draft,
Expand All @@ -393,8 +407,8 @@ const AdvancedTextEditor = ({

const handleSubmitWithEvent = useCallback((e: React.FormEvent) => {
e.preventDefault();
handleSubmit();
}, [handleSubmit]);
onSubmit();
}, [onSubmit]);

const handlePostError = useCallback((err: React.ReactNode) => {
setPostError(err);
Expand Down Expand Up @@ -548,7 +562,9 @@ const AdvancedTextEditor = ({
draftRef.current = draft;
}, [draft]);

const handleSubmitPostAndScheduledMessage = useCallback((schedulingInfo?: SchedulingInfo) => handleSubmit(undefined, schedulingInfo), [handleSubmit]);
const handleSubmitPostAndScheduledMessage = useCallback((schedulingInfo?: SchedulingInfo) => {
onSubmit(undefined, schedulingInfo);
}, [onSubmit]);

// Set the draft from store when changing post or channels, and store the previous one
useEffect(() => {
Expand Down Expand Up @@ -837,6 +853,14 @@ const AdvancedTextEditor = ({
noArgumentHandleSubmit={handleSubmitWrapper}
isInEditMode={isInEditMode}
/>
<div
id='sentMessageStatus'
aria-live='assertive'
style={{
position: 'absolute',
top: '-1000px',
}}
>{ }</div>
</form>
);
};
Expand Down

0 comments on commit 08cd563

Please sign in to comment.