Skip to content

Commit

Permalink
chore: edition specific mention content handler
Browse files Browse the repository at this point in the history
  • Loading branch information
aaryan610 committed Dec 17, 2024
1 parent 3f96129 commit 906cc05
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 2 deletions.
23 changes: 22 additions & 1 deletion web/ce/hooks/use-additional-editor-mention.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,40 @@ import { useCallback } from "react";
// plane editor
import { TMentionSection } from "@plane/editor";
// plane types
import { TSearchResponse } from "@plane/types";
import { TSearchEntities, TSearchResponse } from "@plane/types";

export type TAdditionalEditorMentionHandlerArgs = {
response: TSearchResponse;
sections: TMentionSection[];
};

export type TAdditionalParseEditorContentArgs = {
id: string;
entityType: TSearchEntities;
};

export type TAdditionalParseEditorContentReturnType =
| {
redirectionPath: string;
textContent: string;
}
| undefined;

export const useAdditionalEditorMention = () => {
const updateAdditionalSections = useCallback((args: TAdditionalEditorMentionHandlerArgs) => {
const {} = args;
}, []);

const parseAdditionalEditorContent = useCallback(
(args: TAdditionalParseEditorContentArgs): TAdditionalParseEditorContentReturnType => {
const {} = args;
return undefined;
},
[]
);

return {
updateAdditionalSections,
parseAdditionalEditorContent,
};
};
24 changes: 23 additions & 1 deletion web/core/hooks/use-parse-editor-content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,16 @@ import { TSearchEntities } from "@plane/types";
import { getBase64Image } from "@/helpers/file.helper";
// hooks
import { useMember } from "@/hooks/store";
// plane web hooks
import { useAdditionalEditorMention } from "@/plane-web/hooks/use-additional-editor-mention";

export const useParseEditorContent = () => {
// params
const { workspaceSlug } = useParams();
// store hooks
const { getUserDetails } = useMember();
// parse additional content
const { parseAdditionalEditorContent } = useAdditionalEditorMention();

/**
* @description function to replace all the custom components from the html component to make it pdf compatible
Expand All @@ -38,6 +42,14 @@ export const useParseEditorContent = () => {
if (entityType === "user_mention") {
const userDetails = getUserDetails(id);
textContent = userDetails?.display_name ?? "";
} else {
const mentionDetails = parseAdditionalEditorContent({
id,
entityType,
});
if (mentionDetails) {
textContent = mentionDetails.textContent;
}
}
span.textContent = `@${textContent}`;
// replace the mention-component with the span element
Expand Down Expand Up @@ -160,8 +172,18 @@ export const useParseEditorContent = () => {
const userDetails = getUserDetails(id);
if (!userDetails) return "";
return `[${userDetails.display_name}](${originUrl}/${workspaceSlug}/profile/${id})`;
} else {
const mentionDetails = parseAdditionalEditorContent({
id,
entityType,
});
if (!mentionDetails) {
return "";
} else {
const { redirectionPath, textContent } = mentionDetails;
return `[${textContent}](${originUrl}/${redirectionPath})`;
}
}
return "";
});
// replace the matched image components with <img src={src} >
const imageComponentRegex = /<image-component[^>]*src="([^"]+)"[^>]*>[^]*<\/image-component>/g;
Expand Down

0 comments on commit 906cc05

Please sign in to comment.