[WIKI-773] refactor: editor mention components and hooks (#8111)
This commit is contained in:
parent
c04ae51d20
commit
c65e2c4aab
17 changed files with 84 additions and 96 deletions
|
|
@ -7,26 +7,27 @@ import type { TSearchEntities, TSearchEntityRequestPayload, TSearchResponse, TUs
|
|||
import { Avatar } from "@plane/ui";
|
||||
// helpers
|
||||
import { getFileURL } from "@plane/utils";
|
||||
// plane web constants
|
||||
import { EDITOR_MENTION_TYPES } from "@/plane-web/constants/editor";
|
||||
// plane web hooks
|
||||
import { useAdditionalEditorMention } from "@/plane-web/hooks/use-additional-editor-mention";
|
||||
|
||||
type TArgs = {
|
||||
enableAdvancedMentions?: boolean;
|
||||
searchEntity: (payload: TSearchEntityRequestPayload) => Promise<TSearchResponse>;
|
||||
};
|
||||
|
||||
export const useEditorMention = (args: TArgs) => {
|
||||
const { searchEntity } = args;
|
||||
const { enableAdvancedMentions = false, searchEntity } = args;
|
||||
// additional mentions
|
||||
const { updateAdditionalSections } = useAdditionalEditorMention();
|
||||
const { editorMentionTypes, updateAdditionalSections } = useAdditionalEditorMention({
|
||||
enableAdvancedMentions,
|
||||
});
|
||||
// fetch mentions handler
|
||||
const fetchMentions = useCallback(
|
||||
async (query: string): Promise<TMentionSection[]> => {
|
||||
try {
|
||||
const res = await searchEntity({
|
||||
count: 5,
|
||||
query_type: EDITOR_MENTION_TYPES,
|
||||
query_type: editorMentionTypes,
|
||||
query,
|
||||
});
|
||||
const suggestionSections: TMentionSection[] = [];
|
||||
|
|
@ -57,17 +58,16 @@ export const useEditorMention = (args: TArgs) => {
|
|||
});
|
||||
}
|
||||
});
|
||||
updateAdditionalSections({
|
||||
const { sections } = updateAdditionalSections({
|
||||
response: res,
|
||||
sections: suggestionSections,
|
||||
});
|
||||
return suggestionSections;
|
||||
return [...suggestionSections, ...sections];
|
||||
} catch (error) {
|
||||
console.error("Error in fetching mentions for project pages:", error);
|
||||
console.error("Error in fetching mentions:", error);
|
||||
throw error;
|
||||
}
|
||||
},
|
||||
[searchEntity, updateAdditionalSections]
|
||||
[editorMentionTypes, searchEntity, updateAdditionalSections]
|
||||
);
|
||||
|
||||
return {
|
||||
|
|
|
|||
|
|
@ -15,7 +15,9 @@ export const useParseEditorContent = () => {
|
|||
// store hooks
|
||||
const { getUserDetails } = useMember();
|
||||
// parse additional content
|
||||
const { parseAdditionalEditorContent } = useAdditionalEditorMention();
|
||||
const { parseAdditionalEditorContent } = useAdditionalEditorMention({
|
||||
enableAdvancedMentions: true,
|
||||
});
|
||||
|
||||
/**
|
||||
* @description function to replace all the custom components from the html component to make it pdf compatible
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue