- 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>
43 lines
1 KiB
TypeScript
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,
|
|
};
|
|
};
|