Se corrigen incidencias 35, 36, 33, 32
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
import {
|
import {
|
||||||
createFileRoute,
|
createFileRoute,
|
||||||
Link,
|
Link,
|
||||||
|
useNavigate,
|
||||||
useParams,
|
useParams,
|
||||||
useRouterState,
|
useRouterState,
|
||||||
} from '@tanstack/react-router'
|
} from '@tanstack/react-router'
|
||||||
@@ -59,13 +60,17 @@ function EditableHeaderField({
|
|||||||
onSave: (val: string) => void
|
onSave: (val: string) => void
|
||||||
className?: string
|
className?: string
|
||||||
}) {
|
}) {
|
||||||
|
const textValue = String(value)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<input
|
<input
|
||||||
type="text"
|
type="text"
|
||||||
value={String(value)}
|
value={textValue}
|
||||||
|
// El truco es usar el atributo "size" o calcular el ancho dinámicamente
|
||||||
|
style={{ width: `${Math.max(textValue.length, 1)}ch` }}
|
||||||
onChange={(e) => onSave(e.target.value)}
|
onChange={(e) => onSave(e.target.value)}
|
||||||
onBlur={(e) => onSave(e.target.value)}
|
onBlur={(e) => onSave(e.target.value)}
|
||||||
className={` w-[${String(value).length || 1}ch] max-w-[6ch] border-none bg-transparent text-center outline-none focus:ring-2 focus:ring-blue-400 ${className ?? ''} `}
|
className={`border-none bg-transparent outline-none focus:ring-2 focus:ring-blue-400 ${className ?? ''}`}
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -91,6 +96,7 @@ export default function MateriaDetailPage() {
|
|||||||
const [messages, setMessages] = useState<Array<IAMessage>>([])
|
const [messages, setMessages] = useState<Array<IAMessage>>([])
|
||||||
const [datosGenerales, setDatosGenerales] = useState({})
|
const [datosGenerales, setDatosGenerales] = useState({})
|
||||||
const [campos, setCampos] = useState<Array<CampoEstructura>>([])
|
const [campos, setCampos] = useState<Array<CampoEstructura>>([])
|
||||||
|
const [activeTab, setActiveTab] = useState('datos')
|
||||||
|
|
||||||
// Dentro de MateriaDetailPage
|
// Dentro de MateriaDetailPage
|
||||||
const [headerData, setHeaderData] = useState({
|
const [headerData, setHeaderData] = useState({
|
||||||
@@ -100,6 +106,13 @@ export default function MateriaDetailPage() {
|
|||||||
ciclo: 0,
|
ciclo: 0,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
// Si en el state de la ruta viene una pestaña específica, cámbiate a ella
|
||||||
|
if (state?.activeTab) {
|
||||||
|
setActiveTab(state.activeTab)
|
||||||
|
}
|
||||||
|
}, [state])
|
||||||
|
|
||||||
// Sincronizar cuando llegue la API
|
// Sincronizar cuando llegue la API
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (asignaturasApi) {
|
if (asignaturasApi) {
|
||||||
@@ -208,11 +221,23 @@ export default function MateriaDetailPage() {
|
|||||||
|
|
||||||
<div className="flex flex-wrap gap-4 text-sm text-blue-200">
|
<div className="flex flex-wrap gap-4 text-sm text-blue-200">
|
||||||
<span className="flex items-center gap-1">
|
<span className="flex items-center gap-1">
|
||||||
<GraduationCap className="h-4 w-4" />
|
<GraduationCap className="h-4 w-4 shrink-0" />
|
||||||
{asignaturasApi?.planes_estudio?.datos?.nombre}
|
{/* Eliminamos el max-w y dejamos que el flex-wrap haga su trabajo */}
|
||||||
|
<EditableHeaderField
|
||||||
|
value={asignaturasApi?.planes_estudio?.datos?.nombre || ''}
|
||||||
|
onSave={(val) => handleUpdateHeader('plan_nombre', val)}
|
||||||
|
className="min-w-[10ch] text-blue-100" // min-w para que sea clickeable si está vacío
|
||||||
|
/>
|
||||||
</span>
|
</span>
|
||||||
<span>
|
<span className="flex items-center gap-1">
|
||||||
{asignaturasApi?.planes_estudio?.carreras?.facultades?.nombre}
|
<EditableHeaderField
|
||||||
|
value={
|
||||||
|
asignaturasApi?.planes_estudio?.carreras?.facultades
|
||||||
|
?.nombre || ''
|
||||||
|
}
|
||||||
|
onSave={(val) => handleUpdateHeader('facultad_nombre', val)}
|
||||||
|
className="min-w-[10ch] text-blue-100"
|
||||||
|
/>
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -258,7 +283,11 @@ export default function MateriaDetailPage() {
|
|||||||
{/* ================= TABS ================= */}
|
{/* ================= TABS ================= */}
|
||||||
<section className="border-b bg-white">
|
<section className="border-b bg-white">
|
||||||
<div className="mx-auto max-w-7xl px-6">
|
<div className="mx-auto max-w-7xl px-6">
|
||||||
<Tabs defaultValue="datos">
|
<Tabs
|
||||||
|
value={activeTab}
|
||||||
|
onValueChange={setActiveTab}
|
||||||
|
className="w-full"
|
||||||
|
>
|
||||||
<TabsList className="h-auto gap-6 bg-transparent p-0">
|
<TabsList className="h-auto gap-6 bg-transparent p-0">
|
||||||
<TabsTrigger value="datos">Datos generales</TabsTrigger>
|
<TabsTrigger value="datos">Datos generales</TabsTrigger>
|
||||||
<TabsTrigger value="contenido">Contenido temático</TabsTrigger>
|
<TabsTrigger value="contenido">Contenido temático</TabsTrigger>
|
||||||
@@ -272,7 +301,11 @@ export default function MateriaDetailPage() {
|
|||||||
|
|
||||||
{/* ================= TAB: DATOS GENERALES ================= */}
|
{/* ================= TAB: DATOS GENERALES ================= */}
|
||||||
<TabsContent value="datos">
|
<TabsContent value="datos">
|
||||||
<DatosGenerales data={datosGenerales} isLoading={loadingAsig} />
|
<DatosGenerales
|
||||||
|
data={datosGenerales}
|
||||||
|
isLoading={loadingAsig}
|
||||||
|
asignaturaId={asignaturaId}
|
||||||
|
/>
|
||||||
</TabsContent>
|
</TabsContent>
|
||||||
|
|
||||||
<TabsContent value="contenido">
|
<TabsContent value="contenido">
|
||||||
@@ -330,10 +363,15 @@ export default function MateriaDetailPage() {
|
|||||||
|
|
||||||
/* ================= TAB CONTENT ================= */
|
/* ================= TAB CONTENT ================= */
|
||||||
interface DatosGeneralesProps {
|
interface DatosGeneralesProps {
|
||||||
|
asignaturaId: string
|
||||||
data: AsignaturaDatos
|
data: AsignaturaDatos
|
||||||
isLoading: boolean
|
isLoading: boolean
|
||||||
}
|
}
|
||||||
function DatosGenerales({ data, isLoading }: DatosGeneralesProps) {
|
function DatosGenerales({
|
||||||
|
data,
|
||||||
|
isLoading,
|
||||||
|
asignaturaId,
|
||||||
|
}: DatosGeneralesProps) {
|
||||||
const formatTitle = (key: string): string =>
|
const formatTitle = (key: string): string =>
|
||||||
key.replace(/_/g, ' ').replace(/\b\w/g, (l: string) => l.toUpperCase())
|
key.replace(/_/g, ' ').replace(/\b\w/g, (l: string) => l.toUpperCase())
|
||||||
|
|
||||||
@@ -360,7 +398,9 @@ function DatosGenerales({ data, isLoading }: DatosGeneralesProps) {
|
|||||||
{!isLoading &&
|
{!isLoading &&
|
||||||
Object.entries(data).map(([key, value]) => (
|
Object.entries(data).map(([key, value]) => (
|
||||||
<InfoCard
|
<InfoCard
|
||||||
|
asignaturaId={asignaturaId}
|
||||||
key={key}
|
key={key}
|
||||||
|
clave={key}
|
||||||
title={formatTitle(key)}
|
title={formatTitle(key)}
|
||||||
initialContent={value}
|
initialContent={value}
|
||||||
onEnhanceAI={(contenido) => {
|
onEnhanceAI={(contenido) => {
|
||||||
@@ -411,6 +451,8 @@ function DatosGenerales({ data, isLoading }: DatosGeneralesProps) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
interface InfoCardProps {
|
interface InfoCardProps {
|
||||||
|
asignaturaId?: string
|
||||||
|
clave: string
|
||||||
title: string
|
title: string
|
||||||
initialContent: any
|
initialContent: any
|
||||||
type?: 'text' | 'requirements' | 'evaluation'
|
type?: 'text' | 'requirements' | 'evaluation'
|
||||||
@@ -418,6 +460,8 @@ interface InfoCardProps {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function InfoCard({
|
function InfoCard({
|
||||||
|
asignaturaId,
|
||||||
|
clave,
|
||||||
title,
|
title,
|
||||||
initialContent,
|
initialContent,
|
||||||
type = 'text',
|
type = 'text',
|
||||||
@@ -428,11 +472,27 @@ function InfoCard({
|
|||||||
const [tempText, setTempText] = useState(
|
const [tempText, setTempText] = useState(
|
||||||
type === 'text' ? initialContent : JSON.stringify(initialContent, null, 2),
|
type === 'text' ? initialContent : JSON.stringify(initialContent, null, 2),
|
||||||
)
|
)
|
||||||
|
const navigate = useNavigate()
|
||||||
const handleSave = () => {
|
const handleSave = () => {
|
||||||
setData(tempText)
|
setData(tempText)
|
||||||
setIsEditing(false)
|
setIsEditing(false)
|
||||||
}
|
}
|
||||||
|
const handleIARequest = (data) => {
|
||||||
|
console.log(data)
|
||||||
|
console.log(asignaturaId)
|
||||||
|
|
||||||
|
navigate({
|
||||||
|
to: '/planes/$planId/asignaturas/$asignaturaId',
|
||||||
|
params: {
|
||||||
|
asignaturaId: asignaturaId,
|
||||||
|
},
|
||||||
|
state: {
|
||||||
|
activeTab: 'ia',
|
||||||
|
prefillCampo: data,
|
||||||
|
prefillContenido: data, // el contenido actual del card
|
||||||
|
} as any,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Card className="transition-all hover:border-slate-300">
|
<Card className="transition-all hover:border-slate-300">
|
||||||
@@ -448,7 +508,7 @@ function InfoCard({
|
|||||||
variant="ghost"
|
variant="ghost"
|
||||||
size="icon"
|
size="icon"
|
||||||
className="h-8 w-8 text-blue-500 hover:bg-blue-50 hover:text-blue-600"
|
className="h-8 w-8 text-blue-500 hover:bg-blue-50 hover:text-blue-600"
|
||||||
onClick={() => onEnhanceAI?.(data)} // Enviamos la data actual a la IA
|
onClick={() => handleIARequest(clave)} // Enviamos la data actual a la IA
|
||||||
title="Mejorar con IA"
|
title="Mejorar con IA"
|
||||||
>
|
>
|
||||||
<Sparkles className="h-4 w-4" />
|
<Sparkles className="h-4 w-4" />
|
||||||
|
|||||||
@@ -178,7 +178,7 @@ export async function plans_history(planId: UUID): Promise<Array<CambioPlan>> {
|
|||||||
const { data, error } = await supabase
|
const { data, error } = await supabase
|
||||||
.from('cambios_plan')
|
.from('cambios_plan')
|
||||||
.select(
|
.select(
|
||||||
'id,plan_estudio_id,cambiado_por,cambiado_en,tipo,campo,valor_anterior,valor_nuevo,interaccion_ia_id',
|
'id,plan_estudio_id,cambiado_por,cambiado_en,tipo,campo,valor_anterior,valor_nuevo',
|
||||||
)
|
)
|
||||||
.eq('plan_estudio_id', planId)
|
.eq('plan_estudio_id', planId)
|
||||||
.order('cambiado_en', { ascending: false })
|
.order('cambiado_en', { ascending: false })
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import {
|
|||||||
Clock,
|
Clock,
|
||||||
FileJson,
|
FileJson,
|
||||||
} from 'lucide-react'
|
} from 'lucide-react'
|
||||||
|
import { useCallback, useEffect, useState } from 'react'
|
||||||
|
|
||||||
import { Button } from '@/components/ui/button'
|
import { Button } from '@/components/ui/button'
|
||||||
import { Card, CardContent } from '@/components/ui/card'
|
import { Card, CardContent } from '@/components/ui/card'
|
||||||
@@ -19,9 +20,34 @@ export const Route = createFileRoute('/planes/$planId/_detalle/documento')({
|
|||||||
|
|
||||||
function RouteComponent() {
|
function RouteComponent() {
|
||||||
const { planId } = useParams({ from: '/planes/$planId/_detalle/documento' })
|
const { planId } = useParams({ from: '/planes/$planId/_detalle/documento' })
|
||||||
const handleDownloadPdf = async () => {
|
const [pdfUrl, setPdfUrl] = useState<string | null>(null)
|
||||||
console.log('entre aqui ')
|
const [isLoading, setIsLoading] = useState(true)
|
||||||
|
|
||||||
|
const loadPdfPreview = useCallback(async () => {
|
||||||
|
try {
|
||||||
|
setIsLoading(true)
|
||||||
|
const pdfBlob = await fetchPlanPdf({ plan_estudio_id: planId })
|
||||||
|
const url = window.URL.createObjectURL(pdfBlob)
|
||||||
|
|
||||||
|
// Limpiar URL anterior si existe para evitar fugas de memoria
|
||||||
|
if (pdfUrl) window.URL.revokeObjectURL(pdfUrl)
|
||||||
|
|
||||||
|
setPdfUrl(url)
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error cargando preview:', error)
|
||||||
|
} finally {
|
||||||
|
setIsLoading(false)
|
||||||
|
}
|
||||||
|
}, [planId])
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
loadPdfPreview()
|
||||||
|
return () => {
|
||||||
|
if (pdfUrl) window.URL.revokeObjectURL(pdfUrl)
|
||||||
|
}
|
||||||
|
}, [loadPdfPreview])
|
||||||
|
|
||||||
|
const handleDownloadPdf = async () => {
|
||||||
try {
|
try {
|
||||||
const pdfBlob = await fetchPlanPdf({
|
const pdfBlob = await fetchPlanPdf({
|
||||||
plan_estudio_id: planId,
|
plan_estudio_id: planId,
|
||||||
@@ -54,7 +80,12 @@ function RouteComponent() {
|
|||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex gap-2">
|
<div className="flex gap-2">
|
||||||
<Button variant="outline" size="sm" className="gap-2">
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
size="sm"
|
||||||
|
className="gap-2"
|
||||||
|
onClick={loadPdfPreview}
|
||||||
|
>
|
||||||
<RefreshCcw size={16} /> Regenerar
|
<RefreshCcw size={16} /> Regenerar
|
||||||
</Button>
|
</Button>
|
||||||
<Button variant="outline" size="sm" className="gap-2">
|
<Button variant="outline" size="sm" className="gap-2">
|
||||||
@@ -90,70 +121,42 @@ function RouteComponent() {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* CONTENEDOR DEL DOCUMENTO (Visor) */}
|
{/* CONTENEDOR DEL DOCUMENTO (Visor) */}
|
||||||
|
{/* CONTENEDOR DEL VISOR REAL */}
|
||||||
<Card className="overflow-hidden border-slate-200 shadow-sm">
|
<Card className="overflow-hidden border-slate-200 shadow-sm">
|
||||||
<div className="flex items-center justify-between border-b bg-slate-100/50 p-2 px-4">
|
<div className="flex items-center justify-between border-b bg-slate-100/50 p-2 px-4">
|
||||||
<div className="flex items-center gap-2 text-xs font-medium text-slate-500">
|
<div className="flex items-center gap-2 text-xs font-medium text-slate-500">
|
||||||
<FileText size={14} />
|
<FileText size={14} /> Preview_Documento.pdf
|
||||||
Plan_Estudios_ISC_2024.pdf
|
|
||||||
</div>
|
</div>
|
||||||
<Button variant="ghost" size="sm" className="h-7 gap-1 text-xs">
|
{pdfUrl && (
|
||||||
Abrir en nueva pestaña <ExternalLink size={12} />
|
<Button
|
||||||
</Button>
|
variant="ghost"
|
||||||
|
size="sm"
|
||||||
|
className="h-7 gap-1 text-xs"
|
||||||
|
onClick={() => window.open(pdfUrl, '_blank')}
|
||||||
|
>
|
||||||
|
Abrir en nueva pestaña <ExternalLink size={12} />
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<CardContent className="flex min-h-[800px] justify-center bg-slate-200/50 p-0 py-8">
|
<CardContent className="flex min-h-[800px] justify-center bg-slate-500 p-0">
|
||||||
{/* SIMULACIÓN DE HOJA DE PAPEL */}
|
{isLoading ? (
|
||||||
<div className="relative min-h-[1000px] w-full max-w-[800px] border bg-white p-12 shadow-2xl md:p-16">
|
<div className="flex flex-col items-center justify-center gap-4 text-white">
|
||||||
{/* Contenido del Plan */}
|
<RefreshCcw size={40} className="animate-spin opacity-50" />
|
||||||
<div className="mb-12 text-center">
|
<p className="animate-pulse">Generando vista previa del PDF...</p>
|
||||||
<p className="mb-1 text-xs font-bold tracking-widest text-slate-400 uppercase">
|
|
||||||
Universidad Tecnológica
|
|
||||||
</p>
|
|
||||||
<h2 className="text-2xl font-bold text-slate-800">
|
|
||||||
Plan de Estudios 2024
|
|
||||||
</h2>
|
|
||||||
<h3 className="text-lg font-semibold text-teal-700">
|
|
||||||
Ingeniería en Sistemas Computacionales
|
|
||||||
</h3>
|
|
||||||
<p className="mt-1 text-xs text-slate-500">
|
|
||||||
Facultad de Ingeniería
|
|
||||||
</p>
|
|
||||||
</div>
|
</div>
|
||||||
|
) : pdfUrl ? (
|
||||||
<div className="space-y-8 text-slate-700">
|
/* 3. VISOR DE PDF REAL */
|
||||||
<section>
|
<iframe
|
||||||
<h4 className="mb-2 text-sm font-bold">1. Objetivo General</h4>
|
src={`${pdfUrl}#toolbar=0&navpanes=0`}
|
||||||
<p className="text-justify text-sm leading-relaxed">
|
className="h-[1000px] w-full max-w-[1000px] border-none shadow-2xl"
|
||||||
Formar profesionales altamente capacitados en el desarrollo de
|
title="PDF Preview"
|
||||||
soluciones tecnológicas innovadoras, con sólidos conocimientos
|
/>
|
||||||
en programación, bases de datos, redes y seguridad
|
) : (
|
||||||
informática.
|
<div className="flex items-center justify-center p-20 text-slate-400">
|
||||||
</p>
|
No se pudo cargar la vista previa.
|
||||||
</section>
|
|
||||||
|
|
||||||
<section>
|
|
||||||
<h4 className="mb-2 text-sm font-bold">2. Perfil de Ingreso</h4>
|
|
||||||
<p className="text-justify text-sm leading-relaxed">
|
|
||||||
Egresados de educación media superior con conocimientos
|
|
||||||
básicos de matemáticas, razonamiento lógico y habilidades de
|
|
||||||
comunicación. Interés por la tecnología y la resolución de
|
|
||||||
problemas.
|
|
||||||
</p>
|
|
||||||
</section>
|
|
||||||
|
|
||||||
<section>
|
|
||||||
<h4 className="mb-2 text-sm font-bold">3. Perfil de Egreso</h4>
|
|
||||||
<p className="text-justify text-sm leading-relaxed">
|
|
||||||
Profesional capaz de diseñar, desarrollar e implementar
|
|
||||||
sistemas de software de calidad, administrar infraestructuras
|
|
||||||
de red y liderar proyectos tecnológicos multidisciplinarios.
|
|
||||||
</p>
|
|
||||||
</section>
|
|
||||||
</div>
|
</div>
|
||||||
|
)}
|
||||||
{/* Marca de agua o decoración lateral (opcional) */}
|
|
||||||
<div className="absolute top-0 left-0 h-full w-1 bg-slate-100" />
|
|
||||||
</div>
|
|
||||||
</CardContent>
|
</CardContent>
|
||||||
</Card>
|
</Card>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { useMemo, useState } from 'react'
|
|
||||||
import { createFileRoute } from '@tanstack/react-router'
|
import { createFileRoute } from '@tanstack/react-router'
|
||||||
|
import { format, formatDistanceToNow, parseISO } from 'date-fns'
|
||||||
|
import { es } from 'date-fns/locale'
|
||||||
import {
|
import {
|
||||||
GitBranch,
|
GitBranch,
|
||||||
Edit3,
|
Edit3,
|
||||||
@@ -12,19 +13,17 @@ import {
|
|||||||
History,
|
History,
|
||||||
Calendar,
|
Calendar,
|
||||||
} from 'lucide-react'
|
} from 'lucide-react'
|
||||||
|
import { useMemo, useState } from 'react'
|
||||||
|
|
||||||
import { Badge } from '@/components/ui/badge'
|
import { Badge } from '@/components/ui/badge'
|
||||||
import { Card, CardContent } from '@/components/ui/card'
|
import { Card, CardContent } from '@/components/ui/card'
|
||||||
import { Avatar, AvatarFallback } from '@/components/ui/avatar'
|
|
||||||
import {
|
import {
|
||||||
Dialog,
|
Dialog,
|
||||||
DialogContent,
|
DialogContent,
|
||||||
DialogHeader,
|
DialogHeader,
|
||||||
DialogTitle,
|
DialogTitle,
|
||||||
} from '@/components/ui/dialog'
|
} from '@/components/ui/dialog'
|
||||||
import { Button } from '@/components/ui/button'
|
|
||||||
import { usePlanHistorial } from '@/data/hooks/usePlans'
|
import { usePlanHistorial } from '@/data/hooks/usePlans'
|
||||||
import { format, formatDistanceToNow, parseISO } from 'date-fns'
|
|
||||||
import { es } from 'date-fns/locale'
|
|
||||||
|
|
||||||
export const Route = createFileRoute('/planes/$planId/_detalle/historial')({
|
export const Route = createFileRoute('/planes/$planId/_detalle/historial')({
|
||||||
component: RouteComponent,
|
component: RouteComponent,
|
||||||
@@ -58,9 +57,7 @@ const getEventConfig = (tipo: string, campo: string) => {
|
|||||||
|
|
||||||
function RouteComponent() {
|
function RouteComponent() {
|
||||||
const { planId } = Route.useParams()
|
const { planId } = Route.useParams()
|
||||||
const { data: rawData, isLoading } = usePlanHistorial(
|
const { data: rawData, isLoading } = usePlanHistorial(planId)
|
||||||
'0e0aea4d-b8b4-4e75-8279-6224c3ac769f',
|
|
||||||
)
|
|
||||||
|
|
||||||
// ESTADOS PARA EL MODAL
|
// ESTADOS PARA EL MODAL
|
||||||
const [selectedEvent, setSelectedEvent] = useState<any>(null)
|
const [selectedEvent, setSelectedEvent] = useState<any>(null)
|
||||||
|
|||||||
@@ -106,7 +106,7 @@ function RouteComponent() {
|
|||||||
if (field && !selectedFields.find((sf) => sf.key === field.key)) {
|
if (field && !selectedFields.find((sf) => sf.key === field.key)) {
|
||||||
setSelectedFields([field])
|
setSelectedFields([field])
|
||||||
}
|
}
|
||||||
setInput(`Mejora este campo: `)
|
setInput(`Mejora este campo: [${field?.label}] `)
|
||||||
}
|
}
|
||||||
}, [availableFields])
|
}, [availableFields])
|
||||||
|
|
||||||
@@ -121,46 +121,85 @@ function RouteComponent() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const injectFieldsIntoInput = (
|
||||||
|
input: string,
|
||||||
|
fields: Array<SelectedField>,
|
||||||
|
) => {
|
||||||
|
const baseText = input.replace(/\[[^\]]+]/g, '').trim()
|
||||||
|
|
||||||
|
const tags = fields.map((f) => `[${f.label}]`).join(' ')
|
||||||
|
|
||||||
|
return `${baseText} ${tags}`.trim()
|
||||||
|
}
|
||||||
const toggleField = (field: SelectedField) => {
|
const toggleField = (field: SelectedField) => {
|
||||||
setSelectedFields((prev) =>
|
setSelectedFields((prev) => {
|
||||||
prev.find((f) => f.key === field.key)
|
let nextFields
|
||||||
? prev.filter((f) => f.key !== field.key)
|
|
||||||
: [...prev, field],
|
if (prev.find((f) => f.key === field.key)) {
|
||||||
)
|
nextFields = prev.filter((f) => f.key !== field.key)
|
||||||
if (input.endsWith(':')) setInput(input.slice(0, -1))
|
} else {
|
||||||
|
nextFields = [...prev, field]
|
||||||
|
}
|
||||||
|
|
||||||
|
setInput((prevInput) =>
|
||||||
|
injectFieldsIntoInput(prevInput || 'Mejora este campo:', nextFields),
|
||||||
|
)
|
||||||
|
|
||||||
|
return nextFields
|
||||||
|
})
|
||||||
|
|
||||||
setShowSuggestions(false)
|
setShowSuggestions(false)
|
||||||
}
|
}
|
||||||
|
const buildPrompt = (userInput: string) => {
|
||||||
|
if (selectedFields.length === 0) return userInput
|
||||||
|
|
||||||
|
const fieldsText = selectedFields
|
||||||
|
.map((f) => `- ${f.label}: ${f.value || '(sin contenido)'}`)
|
||||||
|
.join('\n')
|
||||||
|
|
||||||
|
return `
|
||||||
|
${userInput || 'Mejora los siguientes campos:'}
|
||||||
|
|
||||||
|
Campos a analizar:
|
||||||
|
${fieldsText}
|
||||||
|
`.trim()
|
||||||
|
}
|
||||||
|
|
||||||
const handleSend = async (promptOverride?: string) => {
|
const handleSend = async (promptOverride?: string) => {
|
||||||
const textToSend = promptOverride || input
|
const rawText = promptOverride || input
|
||||||
if (!textToSend.trim() && selectedFields.length === 0) return
|
if (!rawText.trim() && selectedFields.length === 0) return
|
||||||
|
|
||||||
|
const finalPrompt = buildPrompt(rawText)
|
||||||
|
|
||||||
const userMsg = {
|
const userMsg = {
|
||||||
id: Date.now().toString(),
|
id: Date.now().toString(),
|
||||||
role: 'user',
|
role: 'user',
|
||||||
content: textToSend,
|
content: finalPrompt,
|
||||||
}
|
}
|
||||||
|
|
||||||
setMessages((prev) => [...prev, userMsg])
|
setMessages((prev) => [...prev, userMsg])
|
||||||
setInput('')
|
setInput('')
|
||||||
setIsLoading(true)
|
setIsLoading(true)
|
||||||
|
|
||||||
// Aquí simularías la llamada a la API enviando 'selectedFields' como contexto
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
const mockText =
|
const mockText =
|
||||||
'Sugerencia generada basada en los campos seleccionados...'
|
'Sugerencia generada basada en los campos seleccionados...'
|
||||||
|
|
||||||
setMessages((prev) => [
|
setMessages((prev) => [
|
||||||
...prev,
|
...prev,
|
||||||
{
|
{
|
||||||
id: Date.now().toString(),
|
id: Date.now().toString(),
|
||||||
role: 'assistant',
|
role: 'assistant',
|
||||||
content: `He analizado ${selectedFields.length > 0 ? selectedFields.map((f) => f.label).join(', ') : 'tu solicitud'}. Aquí tienes una propuesta:\n\n${mockText}`,
|
content: `He analizado ${selectedFields
|
||||||
|
.map((f) => f.label)
|
||||||
|
.join(', ')}. Aquí tienes una propuesta:\n\n${mockText}`,
|
||||||
},
|
},
|
||||||
])
|
])
|
||||||
|
|
||||||
setPendingSuggestion({ text: mockText })
|
setPendingSuggestion({ text: mockText })
|
||||||
setIsLoading(false)
|
setIsLoading(false)
|
||||||
}, 1200)
|
}, 1200)
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex h-[calc(100vh-160px)] max-h-[calc(100vh-160px)] w-full gap-6 overflow-hidden p-4">
|
<div className="flex h-[calc(100vh-160px)] max-h-[calc(100vh-160px)] w-full gap-6 overflow-hidden p-4">
|
||||||
{/* PANEL DE CHAT PRINCIPAL */}
|
{/* PANEL DE CHAT PRINCIPAL */}
|
||||||
@@ -169,27 +208,8 @@ function RouteComponent() {
|
|||||||
<div className="shrink-0 border-b bg-white p-3">
|
<div className="shrink-0 border-b bg-white p-3">
|
||||||
<div className="flex flex-wrap items-center gap-2">
|
<div className="flex flex-wrap items-center gap-2">
|
||||||
<span className="text-[10px] font-bold text-slate-400 uppercase">
|
<span className="text-[10px] font-bold text-slate-400 uppercase">
|
||||||
Campos a mejorar:
|
Mejorar con IA
|
||||||
</span>
|
</span>
|
||||||
{selectedFields.map((field) => (
|
|
||||||
<div
|
|
||||||
key={field.key}
|
|
||||||
className="animate-in zoom-in-95 flex items-center gap-1.5 rounded-lg border border-teal-100 bg-teal-50 px-2 py-1 text-xs font-medium text-teal-700"
|
|
||||||
>
|
|
||||||
{field.label}
|
|
||||||
<button
|
|
||||||
onClick={() => toggleField(field)}
|
|
||||||
className="hover:text-red-500"
|
|
||||||
>
|
|
||||||
<X size={12} />
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
))}
|
|
||||||
{selectedFields.length === 0 && (
|
|
||||||
<span className="text-xs text-slate-400 italic">
|
|
||||||
Escribe ":" para añadir campos
|
|
||||||
</span>
|
|
||||||
)}
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user