Files
plane/web/ee/hooks/use-workspace-mention.ts
Aaryan Khandelwal b9ce8ea8b1 fix: merge conflicts and build errors (#1469)
* dev: private bucket implementation (#1339)

* chore: migrations and backmigration to move attachments to file asset

* chore: move attachments to file assets

* chore: update migration file to include created by and updated by and size

* chore: remove uninmport errors

* chore: make size as float field

* fix: file asset uploads

* chore: asset uploads migration changes

* chore: v2 assets endpoint

* chore: remove unused imports

* chore: issue attachments

* chore: issue attachments

* chore: workspace logo endpoints

* chore: private bucket changes

* chore: user asset endpoint

* chore: add logo_url validation

* chore: cover image urlk

* chore: change asset max length

* chore: pages endpoint

* chore: store the storage_metadata only when none

* chore: attachment asset apis

* chore: update create private bucket

* chore: make bucket private

* chore: fix response of user uploads

* fix: response of user uploads

* fix: job to fix file asset uploads

* fix: user asset endpoints

* chore: avatar for user profile

* chore: external apis user url endpoint

* chore: upload workspace and user asset actions updated

* chore: analytics endpoint

* fix: analytics export

* chore: avatar urls

* chore: update user avatar instances

* chore: avatar urls for assignees and creators

* chore: bucket permission script

* fix: all user avatr instances in the web app

* chore: update project cover image logic

* fix: issue attachment endpoint

* chore: patch endpoint for issue attachment

* chore: attachments

* chore: change attachment storage class

* chore: update issue attachment endpoints

* fix: issue attachment

* chore: update issue attachment implementation

* chore: page asset endpoints

* fix: web build errors

* chore: attachments

* chore: page asset urls

* chore: comment and issue asset endpoints

* chore: asset endpoints

* chore: attachment endpoints

* chore: bulk asset endpoint

* chore: restore endpoint

* chore: project assets endpoints

* chore: asset url

* chore: add delete asset endpoints

* chore: fix asset upload endpoint

* chore: update patch endpoints

* chore: update patch endpoint

* chore: update editor image handling

* chore: asset restore endpoints

* chore: avatar url for space assets

* chore: space app assets migration

* fix: space app urls

* chore: space endpoints

* fix: old editor images rendering logic

* fix: issue archive and attachment activity

* chore: asset deletes

* chore: update images

* chore: attachment delete

* fix: issue attachment

* fix: issue attachment get

* chore: cover image url for projects

* chore: remove duplicate py file

* fix: url check function

* chore: chore project cover asset delete

* fix: migrations

* chore: delete migration files

---------

Co-authored-by: pablohashescobar <nikhilschacko@gmail.com>

* fix: private bucket build errors (#1347)

* fix: private bucket build errors

* fix: build errors

* revert: issue type select changes. (#1355)

* chore: private bucket implementation for workspace level pages (#1371)

* chore: update project modal

* chore: update rich-text read-only editor

* chore: update workspace pages' components

* chore: remove entity identifier in favour of multiple columns of entities (#1405)

* fix: issue attachments (#1411)

* fix: issue attachments (#1422)

* chore: file size limit for pro workspaces (#1437)

* chore: file size limit for pro

* chore: update maximum file size logic

* chore: update editor max file size logic

* chore: update max file size limit logic

* chore: add comments

* fix: close modal after removing workspace logo

* chore: update uploaded asstes' status post issue creation

* chore: memoize max file size var

* chore: check for pro file size limits

* chore: added file size limit to the space app

---------

Co-authored-by: Aaryan Khandelwal <aaryankhandu123@gmail.com>

* chore: add max file size limit to workspace pages (#1440)

* fix: remove old workspace logo and user avatar (#1445)

* fix: intake exception error (#5810)

* chore: filtered active cycles for guest (#1468)

* fix: build error

---------

Co-authored-by: pablohashescobar <nikhilschacko@gmail.com>
Co-authored-by: Nikhil <118773738+pablohashescobar@users.noreply.github.com>
Co-authored-by: Prateek Shourya <prateekshourya29@gmail.com>
Co-authored-by: sriram veeraghanta <veeraghanta.sriram@gmail.com>
Co-authored-by: Anmol Singh Bhatia <121005188+anmolsinghbhatia@users.noreply.github.com>
Co-authored-by: Bavisetti Narayan <72156168+NarayanBavisetti@users.noreply.github.com>
2024-10-12 01:47:13 +05:30

102 lines
2.9 KiB
TypeScript

"use client";
import { useRef, useEffect } from "react";
// types
import { IUser, IUserLite } from "@plane/types";
// hooks
import { useMember } from "@/hooks/store";
type Props = {
workspaceSlug: string;
members?: IUserLite[] | undefined;
user?: IUser | undefined;
};
export const useWorkspaceMention = (props: Props) => {
const { workspaceSlug, members, user } = props;
// refs
const workspaceMembersRef = useRef<IUserLite[] | undefined>();
const userRef = useRef<IUser | undefined>();
const {
workspace: { fetchWorkspaceMembers },
} = useMember();
useEffect(() => {
if (members) workspaceMembersRef.current = members;
else {
if (!workspaceSlug) return;
fetchWorkspaceMembers(workspaceSlug);
}
}, [fetchWorkspaceMembers, members, workspaceSlug]);
useEffect(() => {
if (userRef) userRef.current = user;
}, [user]);
const waitForUserData = async () =>
new Promise<IUser>((resolve) => {
const checkData = () => {
if (userRef.current) resolve(userRef.current);
else setTimeout(checkData, 100);
};
checkData();
});
const mentionHighlights = async () => {
if (user && userRef.current) {
return [userRef.current.id];
} else {
const userData = await waitForUserData();
return [userData.id];
}
};
// Polling function to wait for workspaceMembersRef.current to be populated
const waitForData = async () =>
new Promise<IUserLite[]>((resolve) => {
const checkData = () => {
if (workspaceMembersRef.current && workspaceMembersRef.current.length > 0) {
resolve(workspaceMembersRef.current);
} else {
setTimeout(checkData, 100); // Check every 100ms
}
};
checkData();
});
const mentionSuggestions = async () => {
if (members && workspaceMembersRef.current && workspaceMembersRef.current.length > 0) {
// If data is already available, return it immediately
return workspaceMembersRef.current.map((memberDetails) => ({
entity_name: "user_mention",
entity_identifier: `${memberDetails?.id}`,
id: `${memberDetails?.id}`,
type: "User",
title: `${memberDetails?.display_name}`,
subtitle: memberDetails?.email ?? "",
avatar: `${memberDetails?.avatar_url}`,
redirect_uri: `/${workspaceSlug}/profile/${memberDetails?.id}`,
}));
} else {
// Wait for data to be available
const membersList = await waitForData();
return membersList.map((memberDetails) => ({
entity_name: "user_mention",
entity_identifier: `${memberDetails?.id}`,
id: `${memberDetails?.id}`,
type: "User",
title: `${memberDetails?.display_name}`,
subtitle: memberDetails?.email ?? "",
avatar: `${memberDetails?.avatar_url}`,
redirect_uri: `/${workspaceSlug}/profile/${memberDetails?.id}`,
}));
}
};
return {
mentionSuggestions,
mentionHighlights,
};
};