Skip to content

Commit

Permalink
Review Fixes: Updated the logic to programmatically change status ele…
Browse files Browse the repository at this point in the history
…ment's content.
  • Loading branch information
ayush-chauhan233 committed Dec 20, 2024
1 parent 55b564a commit e7ba7ac
Showing 1 changed file with 8 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -192,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 @@ -346,12 +347,12 @@ const AdvancedTextEditor = ({
const onSubmit = useCallback((submittingDraft?: PostDraft, schedulingInfo?: SchedulingInfo, options?: CreatePostOptions) => {
handleSubmit(submittingDraft, schedulingInfo, options);
if (!errorClass) {
const messageStatusElement = document.getElementById('sentMessageStatus');
const messageStatusInnerText = messageStatusElement?.innerText;
const messageStatusElement = messageStatusRef.current;
const messageStatusInnerText = messageStatusElement?.textContent;
if (messageStatusInnerText === 'Message Sent') {
messageStatusElement!.innerHTML = 'Message Sent &nbsp;';
messageStatusElement!.textContent = 'Message Sent &nbsp;';
} else {
messageStatusElement!.innerText = 'Message Sent';
messageStatusElement!.textContent = 'Message Sent';
}
}
}, [errorClass, handleSubmit]);
Expand Down Expand Up @@ -854,13 +855,10 @@ const AdvancedTextEditor = ({
isInEditMode={isInEditMode}
/>
<div
id='sentMessageStatus'
ref={messageStatusRef}
aria-live='assertive'
style={{
position: 'absolute',
top: '-1000px',
}}
>{ }</div>
className='sr-only'
/>
</form>
);
};
Expand Down

0 comments on commit e7ba7ac

Please sign in to comment.