diff --git a/src/app/api/cards/from-message/route.ts b/src/app/api/cards/from-message/route.ts index f39a59b9..c705eeac 100644 --- a/src/app/api/cards/from-message/route.ts +++ b/src/app/api/cards/from-message/route.ts @@ -24,7 +24,7 @@ export async function POST(request: NextRequest) { const userId = session.user.id; const body = await request.json(); - const { content, workspaceId } = body; + const { content, workspaceId, folderId } = body; @@ -99,7 +99,7 @@ Return ONLY the reformatted note content in markdown format. Do not include any workspaceId, title, content: cleanedContent, - + folderId, }); logger.debug("📝 [CREATE-CARD-FROM-MESSAGE] Card created successfully", { diff --git a/src/app/api/notes/create/route.ts b/src/app/api/notes/create/route.ts index ead62618..2790e661 100644 --- a/src/app/api/notes/create/route.ts +++ b/src/app/api/notes/create/route.ts @@ -8,7 +8,7 @@ const createNoteSchema = z.object({ workspaceId: z.string().uuid(), title: z.string().min(1), content: z.string().optional(), - + folderId: z.string().uuid().optional(), }); export async function POST(req: Request) { @@ -31,7 +31,7 @@ export async function POST(req: Request) { }); } - const { workspaceId, title, content } = result.data; + const { workspaceId, title, content, folderId } = result.data; logger.info("📝 [API] Creating note via manual confirmation:", { workspaceId, title }); @@ -39,7 +39,7 @@ export async function POST(req: Request) { workspaceId, title, content, - + folderId, }); if (!workerResult.success) { diff --git a/src/components/assistant-ui/AssistantTextSelectionManager.tsx b/src/components/assistant-ui/AssistantTextSelectionManager.tsx index 89bef680..cf701b64 100644 --- a/src/components/assistant-ui/AssistantTextSelectionManager.tsx +++ b/src/components/assistant-ui/AssistantTextSelectionManager.tsx @@ -640,15 +640,18 @@ export default function AssistantTextSelectionManager({ setIsProcessing(true); // Call the API endpoint that uses the workspace worker (same as createNote tool) + // Get the current active folder ID + const activeFolderId = useUIStore.getState().activeFolderId; + const response = await fetch("/api/cards/from-message", { method: "POST", headers: { "Content-Type": "application/json", - }, body: JSON.stringify({ content: currentSelection.text, workspaceId, + folderId: activeFolderId ?? undefined, }), }); @@ -742,15 +745,18 @@ export default function AssistantTextSelectionManager({ } // Call the API endpoint that uses the workspace worker (same as createNote tool) + // Get the current active folder ID + const activeFolderId = useUIStore.getState().activeFolderId; + const response = await fetch("/api/cards/from-message", { method: "POST", headers: { "Content-Type": "application/json", - }, body: JSON.stringify({ content: combinedContent, workspaceId, + folderId: activeFolderId ?? undefined, }), }); diff --git a/src/hooks/ai/use-create-card-from-message.ts b/src/hooks/ai/use-create-card-from-message.ts index 04260cc5..167c41df 100644 --- a/src/hooks/ai/use-create-card-from-message.ts +++ b/src/hooks/ai/use-create-card-from-message.ts @@ -4,6 +4,7 @@ import { useState, useCallback, useRef } from "react"; import { useMessage } from "@assistant-ui/react"; import { toast } from "sonner"; import { useWorkspaceStore } from "@/lib/stores/workspace-store"; +import { useUIStore } from "@/lib/stores/ui-store"; import { useQueryClient } from "@tanstack/react-query"; import { logger } from "@/lib/utils/logger"; @@ -19,7 +20,7 @@ export function useCreateCardFromMessage(options: CreateCardOptions = {}) { const { debounceMs = 300 } = options; // Reduced from 1000ms to 300ms const [isCreating, setIsCreating] = useState(false); const debounceTimerRef = useRef(null); - + const message = useMessage(); const currentWorkspaceId = useWorkspaceStore((state) => state.currentWorkspaceId); const queryClient = useQueryClient(); @@ -58,6 +59,9 @@ export function useCreateCardFromMessage(options: CreateCardOptions = {}) { const toastId = toast.loading("Creating card..."); try { + // Get the current active folder ID + const activeFolderId = useUIStore.getState().activeFolderId; + const response = await fetch("/api/cards/from-message", { method: "POST", headers: { @@ -66,6 +70,7 @@ export function useCreateCardFromMessage(options: CreateCardOptions = {}) { body: JSON.stringify({ content, workspaceId: currentWorkspaceId, + folderId: activeFolderId ?? undefined, }), }); @@ -75,21 +80,21 @@ export function useCreateCardFromMessage(options: CreateCardOptions = {}) { } const result = await response.json(); - + // Invalidate React Query cache to refresh the UI immediately if (currentWorkspaceId) { logger.debug("🔄 [CREATE-CARD-BUTTON] Invalidating workspace cache", { workspaceId: currentWorkspaceId.substring(0, 8), }); - + // Force refetch workspace events to show the new card queryClient.invalidateQueries({ queryKey: ["workspace", currentWorkspaceId, "events"], }); } - + toast.success("Card created successfully!", { id: toastId }); - + return result; } catch (error) { console.error("Error creating card:", error);