import type { LoaderFunctionArgs } from "react-router"; import type { ChatMentionType } from "@hivegrid/realtime"; import { loadChatContext } from "~/modules/chat/routes/chatAccess.server"; import { CHAT_MODULE_KEY } from "~/modules/chat/routes/chatRoutePaths"; import { loadChatMentionSuggestions } from "~/modules/chat/services/ChatMentionsService.server"; const TYPES = new Set(["user", "project", "contact", "company"]); export async function loader({ request, params }: LoaderFunctionArgs): Promise { const context = await loadChatContext({ request, params }); const url = new URL(request.url); const query = (url.searchParams.get("q") ?? "").trim(); const rawType = url.searchParams.get("type"); const type = rawType && TYPES.has(rawType as ChatMentionType) ? (rawType as ChatMentionType) : null; const vm = await loadChatMentionSuggestions({ context, tenantSlug: params.tenant ?? "", chatId: params.id ?? "", query, type, }); return Response.json({ query, type, vm }); } export const handle = { moduleKey: CHAT_MODULE_KEY };