bb-plane-fork/apps/space/core/hooks/use-mention.tsx
Prateek Shourya 9f41e92d21
[WEB-5135] refactor: update sites ESLint configuration and refactor imports to use type imports (#7956)
- Enhanced ESLint configuration by adding new rules for import consistency and type imports.
- Refactored multiple files to replace regular imports with type imports for better clarity and performance.
- Ensured consistent use of type imports across the application to align with TypeScript best practices.

Co-authored-by: sriram veeraghanta <veeraghanta.sriram@gmail.com>
2025-10-14 00:40:30 +05:30

43 lines
1 KiB
TypeScript

import { useRef, useEffect } from "react";
import useSWR from "swr";
// plane imports
import { UserService } from "@plane/services";
import type { IUser } from "@plane/types";
export const useMention = () => {
const userService = new UserService();
const { data: user, isLoading: userDataLoading } = useSWR("currentUser", async () => userService.me());
const userRef = useRef<IUser | undefined>();
useEffect(() => {
if (userRef) {
userRef.current = user;
}
}, [user]);
const waitForUserDate = async () =>
new Promise<IUser>((resolve) => {
const checkData = () => {
if (userRef.current) {
resolve(userRef.current);
} else {
setTimeout(checkData, 100);
}
};
checkData();
});
const mentionHighlights = async () => {
if (!userDataLoading && userRef.current) {
return [userRef.current.id];
} else {
const user = await waitForUserDate();
return [user.id];
}
};
return {
mentionHighlights,
};
};