Skip to content

Commit

Permalink
chore(): address UI flow review
Browse files Browse the repository at this point in the history
  • Loading branch information
didd committed Sep 19, 2024
1 parent 836d193 commit d1e52ee
Showing 1 changed file with 14 additions and 31 deletions.
45 changes: 14 additions & 31 deletions libs/design-system-components/src/components/Editor/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ import { MarkButton, BlockButton } from './formatting-buttons';

const MAX_TEXT_LENGTH = 500;

const MENTION_CHARACTER = '@';

type Node = Descendant | { children: Descendant[] };

export type EditorBoxProps = {
Expand Down Expand Up @@ -361,7 +359,7 @@ const EditorBox: React.FC<EditorBoxProps> = props => {
const afterText = Editor.string(editor, afterRange);
const afterMatch = afterText.match(/^(\s|$)/);

//check whether the last @ character is removed which happens when the value is anything but null or an array
//check whether the @ character at the current selection is removed which happens when the value of beforeMentionMatch is anything but null or an array
if (
beforeMentionMatch !== null &&
!Array.isArray(beforeMentionMatch) &&
Expand All @@ -370,18 +368,23 @@ const EditorBox: React.FC<EditorBoxProps> = props => {
setMentionsLimitReached(false);
}

if (
!mentionsLimitReached &&
beforeMentionMatch &&
afterMatch &&
beforeRange &&
typeof getMentions === 'function'
) {
if (beforeMentionMatch && afterMatch && beforeRange && typeof getMentions === 'function') {
if (mentionsLimit) {
if (
countMentions({
children: editorState,
}) === mentionsLimit.count
) {
setMentionsLimitReached(true);
return;
}
}
setMentionTargetRange(beforeRange);
getMentions(beforeMentionMatch[1]);
setIndex(0);
return;
} else {
setMentionsLimitReached(false);
setMentionTargetRange(null);
}

Expand All @@ -405,16 +408,6 @@ const EditorBox: React.FC<EditorBoxProps> = props => {

const onKeyDown = useCallback(
event => {
if (mentionsLimit && event.key === MENTION_CHARACTER) {
if (
countMentions({
children: editorState,
}) === mentionsLimit.count
) {
setMentionsLimitReached(true);
}
}

/**
* key handler for the mention popover
* inserts the mention on tab, enter or space keypress
Expand Down Expand Up @@ -508,17 +501,7 @@ const EditorBox: React.FC<EditorBoxProps> = props => {
setTagTargetRange(null);
}
},
[
index,
mentionTargetRange,
tagTargetRange,
mentions,
tags,
editor,
createTag,
editorState,
mentionsLimit,
],
[index, mentionTargetRange, tagTargetRange, mentions, tags, editor, createTag],
);

/**
Expand Down

0 comments on commit d1e52ee

Please sign in to comment.