@@ -318,6 +318,7 @@ function DatosGenerales({
|
||||
<div className="space-y-6">
|
||||
{/* Tarjeta de Requisitos */}
|
||||
<InfoCard
|
||||
asignaturaId={asignaturaId}
|
||||
title="Requisitos y Seriación"
|
||||
type="requirements"
|
||||
initialContent={pre}
|
||||
@@ -342,6 +343,7 @@ function DatosGenerales({
|
||||
|
||||
{/* Tarjeta de Evaluación */}
|
||||
<InfoCard
|
||||
asignaturaId={asignaturaId}
|
||||
title="Sistema de Evaluación"
|
||||
type="evaluation"
|
||||
initialContent={criteriosEvaluacion}
|
||||
@@ -517,16 +519,25 @@ function InfoCard({
|
||||
}
|
||||
|
||||
const handleIARequest = (campoClave: string) => {
|
||||
console.log(placeholder)
|
||||
console.log(campoClave)
|
||||
|
||||
let targetClave = campoClave
|
||||
if (type === 'evaluation' && !targetClave) {
|
||||
targetClave = 'criterios_de_evaluacion'
|
||||
}
|
||||
|
||||
if (targetClave === 'contenido') {
|
||||
targetClave = 'contenido_tematico'
|
||||
}
|
||||
console.log(targetClave)
|
||||
console.log(asignaturaId)
|
||||
|
||||
// Añadimos un timestamp a la state para forzar que la navegación
|
||||
// genere una nueva ubicación incluso si la ruta y los params son iguales.
|
||||
navigate({
|
||||
to: '/planes/$planId/asignaturas/$asignaturaId/iaasignatura',
|
||||
params: { planId, asignaturaId: asignaturaId! },
|
||||
state: {
|
||||
activeTab: 'ia',
|
||||
prefillCampo: campoClave,
|
||||
prefillCampo: targetClave,
|
||||
prefillContenido: data,
|
||||
_ts: Date.now(),
|
||||
} as any,
|
||||
@@ -581,19 +592,21 @@ function InfoCard({
|
||||
|
||||
{!isEditing && (
|
||||
<div className="flex gap-1">
|
||||
<Tooltip>
|
||||
<TooltipTrigger asChild>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
className="h-8 w-8 text-blue-500 hover:bg-blue-100"
|
||||
onClick={() => clave && handleIARequest(clave)}
|
||||
>
|
||||
<Sparkles className="h-4 w-4" />
|
||||
</Button>
|
||||
</TooltipTrigger>
|
||||
<TooltipContent>Mejorar con IA</TooltipContent>
|
||||
</Tooltip>
|
||||
{type !== 'requirements' && (
|
||||
<Tooltip>
|
||||
<TooltipTrigger asChild>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
className="h-8 w-8 text-blue-500 hover:bg-blue-100"
|
||||
onClick={() => handleIARequest(clave)}
|
||||
>
|
||||
<Sparkles className="h-4 w-4" />
|
||||
</Button>
|
||||
</TooltipTrigger>
|
||||
<TooltipContent>Mejorar con IA</TooltipContent>
|
||||
</Tooltip>
|
||||
)}
|
||||
|
||||
<Tooltip>
|
||||
<TooltipTrigger asChild>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { useQueryClient } from '@tanstack/react-query'
|
||||
import { useParams } from '@tanstack/react-router'
|
||||
import { useLocation, useParams } from '@tanstack/react-router'
|
||||
import {
|
||||
Sparkles,
|
||||
Send,
|
||||
@@ -58,7 +58,7 @@ export function IAAsignaturaTab() {
|
||||
const { asignaturaId } = useParams({
|
||||
from: '/planes/$planId/asignaturas/$asignaturaId',
|
||||
})
|
||||
|
||||
const location = useLocation()
|
||||
// --- ESTADOS ---
|
||||
const [activeChatId, setActiveChatId] = useState<string | undefined>(
|
||||
undefined,
|
||||
@@ -269,6 +269,30 @@ export function IAAsignaturaTab() {
|
||||
)
|
||||
}, [availableFields, input, showSuggestions])
|
||||
|
||||
useEffect(() => {
|
||||
const state = location.state as any
|
||||
|
||||
// Verificamos si existe el timestamp (_ts) para saber que es una acción nueva
|
||||
if (state?.activeTab === 'ia' && state?._ts) {
|
||||
// Si el campo no está ya seleccionado, lo agregamos
|
||||
if (state.prefillCampo) {
|
||||
const fieldToSelect = availableFields.find(
|
||||
(f) => f.key === state.prefillCampo,
|
||||
)
|
||||
|
||||
if (fieldToSelect) {
|
||||
setSelectedFields([fieldToSelect]) // Reemplaza o añade según prefieras
|
||||
|
||||
// Generamos un prompt inicial automático
|
||||
const autoPrompt = `Mejora el contenido de: ${fieldToSelect.label}`
|
||||
setInput(autoPrompt)
|
||||
|
||||
// Opcional: Si quieres que dispare la IA inmediatamente al llegar:
|
||||
// handleSend(autoPrompt)
|
||||
}
|
||||
}
|
||||
}
|
||||
}, [location.state, availableFields])
|
||||
// 2. Efecto para cerrar con ESC
|
||||
useEffect(() => {
|
||||
const handleKeyDown = (e: KeyboardEvent) => {
|
||||
|
||||
Reference in New Issue
Block a user