Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MA-22]: Added aria-live property for message sent status #27

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -191,6 +192,7 @@ const AdvancedTextEditor = ({
const draftRef = useRef(draftFromStore);
const storedDrafts = useRef<Record<string, PostDraft | undefined>>({});
const lastBlurAt = useRef(0);
const messageStatusRef = useRef<HTMLDivElement | null>(null);

const [draft, setDraft] = useState(draftFromStore);
const [caretPosition, setCaretPosition] = useState(draft.message.length);
Expand Down Expand Up @@ -342,6 +344,19 @@ const AdvancedTextEditor = ({
isInEditMode,
);

const onSubmit = useCallback((submittingDraft?: PostDraft, schedulingInfo?: SchedulingInfo, options?: CreatePostOptions) => {
handleSubmit(submittingDraft, schedulingInfo, options);
if (!errorClass) {
const messageStatusElement = messageStatusRef.current;
const messageStatusInnerText = messageStatusElement?.textContent;
if (messageStatusInnerText === 'Message Sent') {
messageStatusElement!.textContent = 'Message Sent &nbsp;';
} else {
messageStatusElement!.textContent = 'Message Sent';
}
}
}, [errorClass, handleSubmit]);

const handleCancel = useCallback(() => {
// This resets the draft to the post's original content
handleDraftChange({
Expand All @@ -367,8 +382,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 +408,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 +563,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 +854,11 @@ const AdvancedTextEditor = ({
noArgumentHandleSubmit={handleSubmitWrapper}
isInEditMode={isInEditMode}
/>
<div
ref={messageStatusRef}
aria-live='assertive'
className='sr-only'
/>
</form>
);
};
Expand Down
Loading