Proyectos de Subversion LeadersLinked - Backend

Rev

Rev 16004 | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
16004 stevensc 1
import React, { useRef, useEffect } from "react";
15851 stevensc 2
import Message from "./Messages";
3
 
4
import styles from "../chat.module.scss";
5
 
16004 stevensc 6
const MessagesList = ({
7
  messages,
8
  onIntersection,
9
  isLastPage,
10
  scrollRef,
11
  isLoading,
12
}) => {
15851 stevensc 13
  const loadMoreEl = useRef();
14
 
15
  useEffect(() => {
16004 stevensc 16
    const observer = new IntersectionObserver(onIntersection);
15851 stevensc 17
 
18
    if (loadMoreEl.current) {
19
      observer.observe(loadMoreEl.current);
20
    }
21
 
22
    return () => {
23
      observer.disconnect();
24
    };
16005 stevensc 25
  }, [messages]);
16003 stevensc 26
 
15851 stevensc 27
  return (
16001 stevensc 28
    <div className={styles.messagesContainer} ref={scrollRef}>
29
      <div className={styles.messageWrapper}>
16004 stevensc 30
        {!isLastPage && !isLoading && <p ref={loadMoreEl}>Cargando...</p>}
16001 stevensc 31
        {messages.map((message) => (
32
          <Message message={message} key={message.id} />
33
        ))}
34
      </div>
15851 stevensc 35
    </div>
36
  );
37
};
38
 
39
export default MessagesList;