bb-plane-fork/space/core/hooks/use-mention.tsx
Aaryan Khandelwal c9cf7cc631
[WEB-1397] refactor: edition specific migration (#4847)
* refactor: edition specific migration

* revert: pagination from space endpoints

* fix: project publish

---------

Co-authored-by: pablohashescobar <nikhilschacko@gmail.com>
2024-06-17 20:09:15 +05:30

44 lines
1 KiB
TypeScript

import { useRef, useEffect } from "react";
import useSWR from "swr";
// types
import { IUser } from "@plane/types";
// services
import { UserService } from "@/services/user.service";
export const useMention = () => {
const userService = new UserService();
const { data: user, isLoading: userDataLoading } = useSWR("currentUser", async () => userService.currentUser());
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,
};
};