diff --git a/src/routes/planes/$planId/_detalle/iaplan.tsx b/src/routes/planes/$planId/_detalle/iaplan.tsx index e6724af..44faa3a 100644 --- a/src/routes/planes/$planId/_detalle/iaplan.tsx +++ b/src/routes/planes/$planId/_detalle/iaplan.tsx @@ -1,3 +1,4 @@ +/* eslint-disable jsx-a11y/no-static-element-interactions */ import { createFileRoute, useRouterState } from '@tanstack/react-router' import { Sparkles, @@ -10,6 +11,8 @@ import { BookOpen, Check, X, + MessageSquarePlus, + Trash2, } from 'lucide-react' import { useState, useEffect, useRef, useMemo } from 'react' @@ -84,6 +87,52 @@ function RouteComponent() { const [pendingSuggestion, setPendingSuggestion] = useState(null) const scrollRef = useRef(null) + const [activeChatId, setActiveChatId] = useState('1') + const [chatHistory, setChatHistory] = useState([ + { id: '1', title: 'Chat inicial' }, + ]) + const [allMessages, setAllMessages] = useState<{ [key: string]: Array }>( + { + '1': [ + { + id: 'm1', + role: 'assistant', + content: '¡Hola! Soy tu asistente de IA en este chat inicial.', + }, + ], + }, + ) + const currentMessages = allMessages[activeChatId] || [] + + const createNewChat = () => { + const newId = Date.now().toString() + const newChat = { id: newId, title: `Nuevo chat ${chatHistory.length + 1}` } + + setChatHistory([newChat, ...chatHistory]) + setAllMessages({ + ...allMessages, + [newId]: [ + { + id: '1', + role: 'assistant', + content: '¡Nuevo chat creado! ¿En qué puedo ayudarte?', + }, + ], + }) + setActiveChatId(newId) + } + + const deleteChat = (e: React.MouseEvent, id: string) => { + e.stopPropagation() // Evita que se seleccione el chat al borrarlo + + const newHistory = chatHistory.filter((chat) => chat.id !== id) + setChatHistory(newHistory) + + // Si borramos el chat activo, pasamos al primero disponible + if (activeChatId === id && newHistory.length > 0) { + setActiveChatId(newHistory[0].id) + } + } // 1. Transformar datos de la API para el menú de selección const availableFields = useMemo(() => { @@ -208,6 +257,49 @@ ${fieldsText} } return (
+ {/* --- PANEL IZQUIERDO: HISTORIAL (NUEVO) --- */} +
+
+

+ Chats +

+ +
+ + +
+ {chatHistory.map((chat) => ( + // eslint-disable-next-line jsx-a11y/click-events-have-key-events +
setActiveChatId(chat.id)} + className={`group relative flex w-full cursor-pointer items-center gap-3 rounded-lg px-3 py-3 text-sm transition-colors ${ + activeChatId === chat.id + ? 'bg-slate-100 font-medium text-slate-900' + : 'text-slate-600 hover:bg-slate-50' + }`} + > + + {chat.title} + + {/* Botón de borrar que aparece al hacer hover */} + +
+ ))} +
+
+
{/* PANEL DE CHAT PRINCIPAL */}
{/* NUEVO: Barra superior de campos seleccionados */} @@ -285,7 +377,6 @@ ${fieldsText} )}
- {/* INPUT FIJO AL FONDO CON SUGERENCIAS : */} {/* INPUT FIJO AL FONDO CON SUGERENCIAS : */}