quivr/frontend/lib/components/MentionInput/utils/getEditorText.ts
Mamadou DICKO 14e44ac6ec
feat: add FeedBrainInput component (#1101)
* feat: add FeedBrainInput component

* feat: add upload button

* feat: update translations add feed_brain_placeholder

* refactor(uploadPage): add config.ts

* feat(lib): add MentionInput

* feat: add <BrainSelector/> component

* feat: update FeedBrainInput
2023-09-04 15:27:06 +02:00

23 lines
674 B
TypeScript

import { MentionData } from "@draft-js-plugins/mention";
import { EditorState } from "draft-js";
export const getEditorText = (editorState: EditorState): string => {
const mentions: string[] = [];
const editorEntities = editorState.getCurrentContent().getAllEntities();
editorEntities.forEach((entity) => {
const entityData = entity?.getData() as { mention?: MentionData };
if (entityData.mention !== undefined) {
mentions.push(entityData.mention.name);
}
});
let content = editorState.getCurrentContent().getPlainText();
for (const mention of mentions) {
content = content.replace(`@#${mention}`, "");
}
return content.trim();
};