Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
extract message content to variable
Browse files Browse the repository at this point in the history
  • Loading branch information
Alun Turner committed Jun 15, 2023
1 parent eeabf03 commit 62a948b
Showing 1 changed file with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@ import { useRoomContext } from "../../../../../contexts/RoomContext";
import defaultDispatcher from "../../../../../dispatcher/dispatcher";
import { Action } from "../../../../../dispatcher/actions";
import { parsePermalink } from "../../../../../utils/permalinks/Permalinks";
import { isNotNull } from "../../../../../Typeguards";

interface WysiwygComposerProps {
disabled?: boolean;
onChange?: (content: string) => void;
onChange: (content: string) => void;
onSend: () => void;
placeholder?: string;
initialContent?: string;
Expand All @@ -60,10 +61,11 @@ export const WysiwygComposer = memo(function WysiwygComposer({
const autocompleteRef = useRef<Autocomplete | null>(null);

const inputEventProcessor = useInputEventProcessor(onSend, autocompleteRef, initialContent, eventRelation);
const { ref, isWysiwygReady, content, actionStates, wysiwyg, suggestion } = useWysiwyg({
const { ref, isWysiwygReady, content, actionStates, wysiwyg, suggestion, getMessageHTMLContent } = useWysiwyg({
initialContent,
inputEventProcessor,
});

const { isFocused, onFocus } = useIsFocused();

const isReady = isWysiwygReady && !disabled;
Expand All @@ -72,10 +74,11 @@ export const WysiwygComposer = memo(function WysiwygComposer({
useSetCursorPosition(!isReady, ref);

useEffect(() => {
if (!disabled && content !== null) {
onChange?.(content);
const messageContent = getMessageHTMLContent();
if (!disabled && isNotNull(messageContent)) {
onChange(messageContent);
}
}, [onChange, content, disabled]);
}, [onChange, getMessageHTMLContent, disabled]);

useEffect(() => {
function handleClick(e: Event): void {
Expand Down

0 comments on commit 62a948b

Please sign in to comment.