diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..af8dc9d --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,15 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "type": "msedge", + "request": "launch", + "name": "Launch Edge against localhost", + "url": "http://localhost:3000", + "webRoot": "${workspaceFolder}" + } + ] +} \ No newline at end of file diff --git a/src/components/planes/AddAsignaturaButton.tsx b/src/components/planes/AddAsignaturaButton.tsx index 28a9b80..17f5754 100644 --- a/src/components/planes/AddAsignaturaButton.tsx +++ b/src/components/planes/AddAsignaturaButton.tsx @@ -7,13 +7,14 @@ import { Textarea } from "@/components/ui/textarea" import { AuroraButton } from "@/components/effect/aurora-button" import confetti from "canvas-confetti" import { useQueryClient } from "@tanstack/react-query" -import { supabase } from "@/auth/supabase" +import { supabase, useSupabaseAuth } from "@/auth/supabase" import { Field } from "./Field" import { Tabs, TabsContent, TabsList, TabsTrigger } from "../ui/tabs" import { asignaturaKeys } from "./planQueries" export function AddAsignaturaButton({ planId, onAdded }: { planId: string; onAdded?: () => void }) { const qc = useQueryClient() + const supabaseAuth = useSupabaseAuth() const [open, setOpen] = useState(false) const [saving, setSaving] = useState(false) const [mode, setMode] = useState<"manual" | "ia">("manual") @@ -56,11 +57,13 @@ export function AddAsignaturaButton({ planId, onAdded }: { planId: string; onAdd async function createWithAI() { if (!canIA) return setSaving(true) + // inserte la asignatura generada directamente + // obtengas el uuid que se insertó try { const res = await fetch(`${import.meta.env.VITE_BACK_ORIGIN}/api/generar/asignatura`, { method: "POST", headers: { "Content-Type": "application/json" }, - body: JSON.stringify({ planEstudiosId: planId, prompt: iaPrompt, semestre: iaSemestre.trim() ? Number(iaSemestre) : undefined, insert: true }), + body: JSON.stringify({ planEstudiosId: planId, prompt: iaPrompt, semestre: iaSemestre.trim() ? Number(iaSemestre) : undefined, insert: true, uuid: supabaseAuth.user?.id }), }) if (!res.ok) throw new Error(await res.text()) confetti({ particleCount: 120, spread: 80, origin: { y: 0.6 } }) diff --git a/src/components/planes/CreatePlanDialog.tsx b/src/components/planes/CreatePlanDialog.tsx index 09d5c22..d4c7e83 100644 --- a/src/components/planes/CreatePlanDialog.tsx +++ b/src/components/planes/CreatePlanDialog.tsx @@ -165,6 +165,7 @@ export function CreatePlanDialog({ open, onOpenChange }: { open: boolean; onOpen prompt, insert: true, files: selectedFiles, + uuid: auth.user?.id, }) const newId = (res as any)?.id || (res as any)?.plan?.id || (res as any)?.data?.id if (newId) { diff --git a/src/routes/_authenticated/archivos.tsx b/src/routes/_authenticated/archivos.tsx index d7efef5..70e1510 100644 --- a/src/routes/_authenticated/archivos.tsx +++ b/src/routes/_authenticated/archivos.tsx @@ -1,7 +1,7 @@ // routes/_authenticated/archivos.tsx import { createFileRoute, useRouter } from "@tanstack/react-router" -import { useMemo, useState } from "react" -import { supabase } from "@/auth/supabase" +import { use, useMemo, useState } from "react" +import { supabase, useSupabaseAuth } from "@/auth/supabase" import * as Icons from "lucide-react" import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card" import { Input } from "@/components/ui/input" @@ -16,6 +16,7 @@ import { Select, SelectTrigger, SelectContent, SelectItem, SelectValue } from "@ import { DetailDialog } from "@/components/archivos/DetailDialog" import type { RefRow } from "@/types/RefRow" +import { uuid } from "zod" export const Route = createFileRoute("/_authenticated/archivos")({ component: RouteComponent, @@ -192,6 +193,7 @@ function RouteComponent() { function UploadDialog({ open, onOpenChange, onDone, }: { open: boolean; onOpenChange: (o: boolean) => void; onDone: () => void }) { + const supabaseAuth = useSupabaseAuth() const [file, setFile] = useState(null) const [instrucciones, setInstrucciones] = useState("") const [tags, setTags] = useState("") @@ -222,6 +224,7 @@ function UploadDialog({ prompt: instrucciones, fileBase64, insert: true, + uuid: supabaseAuth.user?.id ?? null, }), }) if (!res.ok) {