Se agrega componente de ia y pdf

This commit is contained in:
2025-11-13 10:02:26 -06:00
parent 0e884f20c5
commit 7105b286bf
6 changed files with 671 additions and 8 deletions

View File

@@ -8,6 +8,7 @@ import { supabase,useSupabaseAuth } from "@/auth/supabase"
import { toast } from "sonner"
import ReactMarkdown from 'react-markdown'
import { HistorialCambiosModal } from "../historico/HistorialCambiosModal"
import AIChatModal from "../ai/AIChatModal"
/* =====================================================
@@ -115,6 +116,7 @@ export function AcademicSections({ planId, color }: { planId: string; color?: st
const qc = useQueryClient()
const auth = useSupabaseAuth()
const [openHistorial, setOpenHistorial] = useState(false)
const [openModalIa, setopenModalIa] = useState(false)
if(!planId) return <div>Cargando</div>
const { data: plan } = useSuspenseQuery(planTextOptions(planId))
@@ -162,6 +164,8 @@ export function AcademicSections({ planId, color }: { planId: string; color?: st
],
[]
)
const [iaContext, setIaContext] = useState<{ key: keyof PlanTextFields; title: string; content: string } | null>(null)
return (
<>
@@ -171,9 +175,14 @@ export function AcademicSections({ planId, color }: { planId: string; color?: st
return (
<SectionPanel key={s.id} id={s.id} title={s.title} icon={s.icon} color={color}>
{s.key === "historico" ? (
<Button variant="outline" size="sm" onClick={() => setOpenHistorial(true)}>
Ver historial
</Button>
<>
<Button variant="outline" size="sm" onClick={() => setOpenHistorial(true)}>
Ver historial
</Button>
<Button variant="outline" size="sm" onClick={() => setopenModalIa(true)}>
Promt
</Button>
</>
) : (
<>
<ExpandableText text={text} mono={s.mono} />
@@ -190,7 +199,7 @@ export function AcademicSections({ planId, color }: { planId: string; color?: st
Copiar
</Button>
{s.key !== "prompt" && (
<Button
<Button
variant="ghost"
size="sm"
onClick={() => {
@@ -200,7 +209,7 @@ export function AcademicSections({ planId, color }: { planId: string; color?: st
}}
>
Editar
</Button>
</Button>
)}
</div>
</>
@@ -268,6 +277,24 @@ export function AcademicSections({ planId, color }: { planId: string; color?: st
>
{updateField.isPending ? "Guardando…" : "Guardar"}
</Button>
<Button
variant="secondary"
onClick={() => {
if (!editing) return
const current = draft
setIaContext({
key: editing.key,
title: editing.title,
content: current,
})
setopenModalIa(true)
setEditing(null) // 🔹 Cierra el modal de edición
}}
>
Mejorar con IA
</Button>
</DialogFooter>
</DialogContent>
</Dialog>
@@ -279,6 +306,24 @@ export function AcademicSections({ planId, color }: { planId: string; color?: st
updateField.mutate({ key, value })
}}
/>
<AIChatModal
open={openModalIa}
onClose={() => setopenModalIa(false)}
edgeFunctionUrl="https://exdkssurzmjnnhgtiama.supabase.co/functions/v1/simple-chat"
context={{
section: iaContext?.title,
fieldKey: iaContext?.key,
originalText: iaContext?.content,
}}
onAccept={(newText: string) => {
if (iaContext) {
updateField.mutate({ key: iaContext.key, value: newText })
setIaContext(null)
}
}}
/>
</>
)
}