From 2b91004129ca6f1baa804a602d84b4a4babd6b42 Mon Sep 17 00:00:00 2001 From: "Roberto.silva" Date: Thu, 19 Mar 2026 14:18:21 -0600 Subject: [PATCH] Que no haga scroll #193 --- src/routes/planes/$planId/_detalle/iaplan.tsx | 81 +++++++++++-------- .../asignaturas/$asignaturaId/route.tsx | 22 ++--- 2 files changed, 52 insertions(+), 51 deletions(-) diff --git a/src/routes/planes/$planId/_detalle/iaplan.tsx b/src/routes/planes/$planId/_detalle/iaplan.tsx index e42398b..d139f68 100644 --- a/src/routes/planes/$planId/_detalle/iaplan.tsx +++ b/src/routes/planes/$planId/_detalle/iaplan.tsx @@ -15,6 +15,7 @@ import { Archive, Loader2, Sparkles, + RotateCcw, } from 'lucide-react' import { useState, useEffect, useRef, useMemo } from 'react' @@ -128,6 +129,7 @@ function RouteComponent() { const [pendingSuggestion, setPendingSuggestion] = useState(null) const queryClient = useQueryClient() const scrollRef = useRef(null) + const isInitialLoad = useRef(true) const [showArchived, setShowArchived] = useState(false) const [editingChatId, setEditingChatId] = useState(null) const editableRef = useRef(null) @@ -204,20 +206,20 @@ function RouteComponent() { return messages }) }, [mensajesDelChat, activeChatId, availableFields]) - const scrollToBottom = () => { + const scrollToBottom = (behavior = 'smooth') => { if (scrollRef.current) { - // Buscamos el viewport interno del ScrollArea de Radix const scrollContainer = scrollRef.current.querySelector( '[data-radix-scroll-area-viewport]', ) if (scrollContainer) { scrollContainer.scrollTo({ top: scrollContainer.scrollHeight, - behavior: 'smooth', + behavior: behavior, // 'instant' para carga inicial, 'smooth' para mensajes nuevos }) } } } + const { activeChats, archivedChats } = useMemo(() => { const allChats = lastConversation || [] return { @@ -229,22 +231,22 @@ function RouteComponent() { }, [lastConversation]) useEffect(() => { - console.log(mensajesDelChat) - - scrollToBottom() - }, [chatMessages, isLoading]) - - /* useEffect(() => { - // Verificamos cuáles campos de la lista "selectedFields" ya no están presentes en el texto del input - const camposActualizados = selectedFields.filter((field) => - input.includes(field.label), - ) - - // Solo actualizamos el estado si hubo un cambio real (para evitar bucles infinitos) - if (camposActualizados.length !== selectedFields.length) { - setSelectedFields(camposActualizados) + if (chatMessages.length > 0) { + if (isInitialLoad.current) { + // Si es el primer render con mensajes, vamos al final al instante + scrollToBottom('instant') + isInitialLoad.current = false + } else { + // Si ya estaba cargado y llegan nuevos, hacemos el smooth + scrollToBottom('smooth') + } } - }, [input, selectedFields]) */ + }, [chatMessages]) + + // 2. Resetear el flag cuando cambies de chat activo + useEffect(() => { + isInitialLoad.current = true + }, [activeChatId]) useEffect(() => { if (isLoadingConv || isSending) return @@ -508,27 +510,38 @@ function RouteComponent() { -
+
+ {' '} + {/* Agregamos un pr-2 para que el scrollbar no tape botones */} {!showArchived ? ( activeChats.map((chat) => (
setActiveChatId(chat.id)} - className={`group relative flex w-full items-center justify-between overflow-hidden rounded-lg px-3 py-3 text-sm transition-colors ${ + className={`group relative flex w-full items-center overflow-hidden 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' }`} > - {/* LADO IZQUIERDO: Icono + Texto con Tooltip */} -
+ {/* LADO IZQUIERDO: Icono + Texto */} +
+ {/* pr-12 reserva espacio para los botones absolutos */} - - - {/* Este contenedor es el que obliga al span a truncarse */} -
+ +
- - {/* Tooltip: Solo aparece si no estás editando y el texto es largo */} {editingChatId !== chat.id && (
- {/* LADO DERECHO: Acciones con shrink-0 para que no se muevan */} + {/* LADO DERECHO: Acciones ABSOLUTAS */}
@@ -614,7 +625,7 @@ function RouteComponent() {
)) ) : ( - /* Sección de archivados */ + /* Sección de archivados (Simplificada para mantener consistencia) */

Archivados @@ -622,18 +633,18 @@ function RouteComponent() { {archivedChats.map((chat) => (

-
+
- + {chat.nombre || `Archivado ${chat.creado_en.split('T')[0]}`}
diff --git a/src/routes/planes/$planId/asignaturas/$asignaturaId/route.tsx b/src/routes/planes/$planId/asignaturas/$asignaturaId/route.tsx index 3117ab2..6f99511 100644 --- a/src/routes/planes/$planId/asignaturas/$asignaturaId/route.tsx +++ b/src/routes/planes/$planId/asignaturas/$asignaturaId/route.tsx @@ -166,30 +166,20 @@ function AsignaturaLayout() { onSave={(val) => handleUpdateHeader('nombre', val)} /> + { + // console.log(headerData), + console.log(asignaturaApi.planes_estudio?.nombre) + }
+ Pertenece al plan:{' '} - {(asignaturaApi.planes_estudio?.datos as DatosPlan) - .nombre || ''} - - - - - - {(asignaturaApi.planes_estudio?.datos as DatosPlan) - .nombre ?? ''} + {(asignaturaApi.planes_estudio as DatosPlan).nombre || ''}
- -

- Pertenece al plan:{' '} - - {asignaturaApi.planes_estudio?.nombre} - -