27 lines
1.1 KiB
TypeScript
27 lines
1.1 KiB
TypeScript
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<ChatMentionType>(["user", "project", "contact", "company"]);
|
|
|
|
export async function loader({ request, params }: LoaderFunctionArgs): Promise<Response> {
|
|
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 };
|