up
This commit is contained in:
+13
-20
@@ -2692,9 +2692,8 @@ if (!isset($_SESSION['user_id'])) {
|
||||
try {
|
||||
const prevScrollTop = container.scrollTop;
|
||||
const prevScrollHeight = container.scrollHeight;
|
||||
// Only reset to top if literally at position 0 (or within one pixel)
|
||||
const wasAtTop = prevScrollTop <= 4;
|
||||
|
||||
|
||||
container.innerHTML = html;
|
||||
void container.offsetHeight; // forzar repaint
|
||||
|
||||
@@ -2704,29 +2703,18 @@ if (!isset($_SESSION['user_id'])) {
|
||||
if (wasAtTop) {
|
||||
container.scrollTop = 0;
|
||||
} else {
|
||||
// Preservar posición visual exacta compensando cambio de altura
|
||||
const restoredPos = Math.max(0, prevScrollTop + scrollDelta);
|
||||
container.scrollTop = restoredPos;
|
||||
// Si el ítem activo está ahora fuera de vista (más de 2 alturas de pantalla),
|
||||
// acercarlo de forma suave sin regresar al tope
|
||||
const activeItem = container.querySelector('.conversation-item.active');
|
||||
if (activeItem) {
|
||||
const rect = activeItem.getBoundingClientRect();
|
||||
const listRect = container.getBoundingClientRect();
|
||||
const isVisible = rect.top >= listRect.top && rect.bottom <= listRect.bottom;
|
||||
if (!isVisible) {
|
||||
activeItem.scrollIntoView({ block: 'nearest', behavior: 'smooth' });
|
||||
}
|
||||
}
|
||||
// Restaurar posición visual exacta compensando cambio de altura del contenido
|
||||
container.scrollTop = Math.max(0, prevScrollTop + scrollDelta);
|
||||
// NOTA: NO llamar scrollIntoView aquí — se ejecuta en cada update SSE
|
||||
// y causa que el scroll baje solo continuamente hasta el fondo.
|
||||
// scrollIntoView solo se llama manualmente al abrir una conversación.
|
||||
}
|
||||
|
||||
|
||||
console.log('✅ renderConversations COMPLETADO');
|
||||
} catch (e) {
|
||||
// fallback to naive replace if anything failed
|
||||
console.warn('renderConversations: scroll preservation failed', e);
|
||||
container.innerHTML = html;
|
||||
void container.offsetHeight;
|
||||
console.log('⚠️ renderConversations COMPLETADO con fallback');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2848,7 +2836,12 @@ if (!isset($_SESSION['user_id'])) {
|
||||
document.querySelectorAll('.conversation-item').forEach(item => {
|
||||
item.classList.remove('active');
|
||||
});
|
||||
document.querySelector(`[data-user-id="${userId}"]`)?.classList.add('active');
|
||||
const activeItem = document.querySelector(`[data-user-id="${userId}"]`);
|
||||
if (activeItem) {
|
||||
activeItem.classList.add('active');
|
||||
// Scroll al ítem activo solo al abrirlo (no en cada re-render)
|
||||
activeItem.scrollIntoView({ block: 'nearest', behavior: 'smooth' });
|
||||
}
|
||||
|
||||
// Actualizar estado del toggle del bot según datos de la conversación (ya obtuvimos conv arriba)
|
||||
if (conv) {
|
||||
|
||||
Reference in New Issue
Block a user