Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/editor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
"@tiptap/react": "^2.22.3",
"@tiptap/starter-kit": "^2.22.3",
"@tiptap/suggestion": "^2.22.3",
"lodash-es": "catalog:",
"buffer": "^6.0.3",
"emoji-regex": "^10.3.0",
"highlight.js": "^11.8.0",
Expand All @@ -85,6 +86,7 @@
"@types/node": "catalog:",
"@types/react": "catalog:",
"@types/react-dom": "catalog:",
"@types/lodash-es": "catalog:",
"postcss": "^8.4.38",
"tsdown": "catalog:",
"typescript": "catalog:"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { FloatingOverlay } from "@floating-ui/react";
import type { SuggestionProps } from "@tiptap/suggestion";
import { forwardRef, useCallback, useEffect, useImperativeHandle, useLayoutEffect, useRef, useState } from "react";
import { v4 as uuidv4 } from "uuid";
import { debounce } from "lodash-es";
// plane utils
import { useOutsideClickDetector } from "@plane/hooks";
import { cn } from "@plane/utils";
Expand Down Expand Up @@ -75,12 +76,12 @@ export const MentionsListDropdown = forwardRef(function MentionsListDropdown(pro
});
}, [sections]);

// fetch mention sections based on query
useEffect(() => {
const fetchSuggestions = async () => {
// debounced search callback
const debouncedSearchCallback = useCallback(
debounce(async (searchQuery: string) => {
setIsLoading(true);
try {
const sectionsResponse = await searchCallback?.(query);
const sectionsResponse = await searchCallback?.(searchQuery);
if (sectionsResponse) {
setSections(sectionsResponse);
}
Expand All @@ -89,9 +90,24 @@ export const MentionsListDropdown = forwardRef(function MentionsListDropdown(pro
} finally {
setIsLoading(false);
}
};
fetchSuggestions();
}, [query, searchCallback]);
}, 300),
[searchCallback]
);

// trigger debounced search when query changes
useEffect(() => {
if (query) {
void debouncedSearchCallback(query);
}
}, [query, debouncedSearchCallback]);

// cancel pending debounced calls on unmount
useEffect(
() => () => {
debouncedSearchCallback.cancel();
},
[debouncedSearchCallback]
);

// scroll to the dropdown item when navigating via keyboard
useLayoutEffect(() => {
Expand Down
6 changes: 6 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading