|
@@ -32,62 +32,79 @@ const MessageItem = ({
|
|
// date.getSeconds().toString().padStart(2, 0);
|
|
// date.getSeconds().toString().padStart(2, 0);
|
|
|
|
|
|
return (
|
|
return (
|
|
- <div
|
|
|
|
- className={`messageItem list-group-item m-2 gradient shadow-sm border-2 ${
|
|
|
|
- myId === ownerId ? "start-right list-group-item-success text-success" : " list-group-item-light"
|
|
|
|
- }`}
|
|
|
|
- >
|
|
|
|
- {/* */}
|
|
|
|
-
|
|
|
|
- <div className="roundIcon">
|
|
|
|
- {avatar && avatar.url ? (
|
|
|
|
- <img
|
|
|
|
- src={`${urlUploadConst}/${avatar.url}`}
|
|
|
|
- className="bg-success border border-2 border-success"
|
|
|
|
- ></img>
|
|
|
|
- ) : (
|
|
|
|
- <div className="bg-success border border-2 border-success gradient middleHeight">
|
|
|
|
- <p className="fs-5 text-light fw-bolder">
|
|
|
|
- {`${nick.split(" ")[0][0].toUpperCase()}` +
|
|
|
|
- `${
|
|
|
|
- (nick.split(" ").slice(1).pop() &&
|
|
|
|
- nick.split(" ").slice(1).pop()[0].toUpperCase()) ||
|
|
|
|
- ""
|
|
|
|
- }`}
|
|
|
|
- </p>
|
|
|
|
- </div>
|
|
|
|
- )}
|
|
|
|
|
|
+ <div className={`d-flex align-items-end ${myId === ownerId ? "justify-content-end" : ""}`}>
|
|
|
|
+ <div>
|
|
|
|
+ <div className="avatarka">
|
|
|
|
+ {avatar && avatar.url ? (
|
|
|
|
+ <img
|
|
|
|
+ src={`${urlUploadConst}/${avatar.url}`}
|
|
|
|
+ className="bg-success border border-2 border-success mb-1"
|
|
|
|
+ ></img>
|
|
|
|
+ ) : (
|
|
|
|
+ <div className="d-flex justify-content-center align-items-center bg-success border border-2 border-success gradient mb-2">
|
|
|
|
+ <div className="fs-5 text-light fw-bolder">
|
|
|
|
+ {`${nick.split(" ")[0][0].toUpperCase()}` +
|
|
|
|
+ `${
|
|
|
|
+ (nick.split(" ").slice(1).pop() &&
|
|
|
|
+ nick.split(" ").slice(1).pop()[0].toUpperCase()) ||
|
|
|
|
+ ""
|
|
|
|
+ }`}
|
|
|
|
+ </div>
|
|
|
|
+ </div>
|
|
|
|
+ )}
|
|
|
|
+ </div>
|
|
</div>
|
|
</div>
|
|
-
|
|
|
|
- {/* */}
|
|
|
|
- {/* <span>{`myid: ${myId}`}</span> */}
|
|
|
|
-
|
|
|
|
- {/* <p>{`Login: ${login}, Nick: ${nick}, ownerId: ${ownerId}`}</p> */}
|
|
|
|
- <div className="middleHeight mb-3">
|
|
|
|
- <p className="text-dark fs-5 lh-sm">{`${nick}`}</p>
|
|
|
|
|
|
+ <div
|
|
|
|
+ className={`messageItem list-group-item m-1 gradient shadow-sm border-2 ${
|
|
|
|
+ myId === ownerId ? "list-group-item-success" : " list-group-item-light"
|
|
|
|
+ }`}
|
|
|
|
+ >
|
|
|
|
+ {/* <span>{`myid: ${myId}`}</span> */}
|
|
|
|
+ {/* <p>{`Login: ${login}, Nick: ${nick}, ownerId: ${ownerId}`}</p> */}
|
|
|
|
+ <div className="lh-sm mb-2 text-success fw-bolder">{`${nick}`}</div>
|
|
|
|
+ <div className="text-dark fs-5 lh-sm">{text}</div>
|
|
|
|
+ <span className="text-success">{`message id: ${_id}`}</span>
|
|
|
|
+ <span className="position-absolute bottom-0 end-0 badge rounded-pill bg-secondary">
|
|
|
|
+ {dateStr} <span className="visually-hidden">дата сообщения</span>
|
|
|
|
+ </span>
|
|
</div>
|
|
</div>
|
|
- <div className="text-dark fs-5 lh-sm">{text}</div>
|
|
|
|
- <span>{`message id: ${_id}`}</span>
|
|
|
|
- <span className="position-absolute bottom-0 end-0 badge rounded-pill bg-secondary">
|
|
|
|
- {dateStr} <span className="visually-hidden">id чата</span>
|
|
|
|
- </span>
|
|
|
|
- {/* <div className="fs-6 text-end text-secondary">{dateStr}</div> */}
|
|
|
|
</div>
|
|
</div>
|
|
);
|
|
);
|
|
};
|
|
};
|
|
|
|
|
|
const MessagesList = ({ messages, myId, chatId }) => {
|
|
const MessagesList = ({ messages, myId, chatId }) => {
|
|
const messagesEndRef = useRef(null); // указатель на пустой div в коце сообщений для перемотки
|
|
const messagesEndRef = useRef(null); // указатель на пустой div в коце сообщений для перемотки
|
|
|
|
+ const messagesListBlockRef = useRef(null); // для отслеживания скролла
|
|
|
|
+ const [offset, setOffset] = useState(0); // для отслеживания скролла
|
|
|
|
+
|
|
|
|
+ // const height = messagesListBlockRef.current.scrollHeight - messagesListBlockRef.current.clientHeight;
|
|
|
|
+ // console.log(height);
|
|
|
|
+ console.log(offset);
|
|
|
|
|
|
let arrayOfMessages = messages[chatId];
|
|
let arrayOfMessages = messages[chatId];
|
|
|
|
|
|
// скролл в самый низ при приходе новых сообщений
|
|
// скролл в самый низ при приходе новых сообщений
|
|
const scrollToBottom = () => messagesEndRef.current.scrollIntoView({ behavior: "smooth" });
|
|
const scrollToBottom = () => messagesEndRef.current.scrollIntoView({ behavior: "smooth" });
|
|
-
|
|
|
|
useEffect(scrollToBottom, [arrayOfMessages]);
|
|
useEffect(scrollToBottom, [arrayOfMessages]);
|
|
|
|
|
|
|
|
+ useEffect(() => {
|
|
|
|
+ //отслеживает событие скролла
|
|
|
|
+ messagesListBlockRef.current.onscroll = () => {
|
|
|
|
+ setOffset(Math.floor(messagesListBlockRef.current.scrollTop));
|
|
|
|
+ };
|
|
|
|
+
|
|
|
|
+ // if (height === offset) {
|
|
|
|
+ // getUsers(skip, limit); // actionAllUsers= (skipArg, limitArg)=>{...}
|
|
|
|
+ // setSkip(limit);
|
|
|
|
+ // setLimit((prev) => prev + 10);
|
|
|
|
+ // // console.log(allUsers, "getUs");
|
|
|
|
+ // // console.log(height, "height");
|
|
|
|
+ // // console.log(offset);
|
|
|
|
+ // }
|
|
|
|
+ }, [offset]);
|
|
|
|
+
|
|
return (
|
|
return (
|
|
- <div className="Messages_map">
|
|
|
|
|
|
+ <div className="MessagesList" ref={messagesListBlockRef}>
|
|
{!!arrayOfMessages && arrayOfMessages.map((mess) => <MessageItem key={mess._id} {...mess} myId={myId} />)}
|
|
{!!arrayOfMessages && arrayOfMessages.map((mess) => <MessageItem key={mess._id} {...mess} myId={myId} />)}
|
|
<div ref={messagesEndRef} />
|
|
<div ref={messagesEndRef} />
|
|
</div>
|
|
</div>
|
|
@@ -97,7 +114,7 @@ const MessagesList = ({ messages, myId, chatId }) => {
|
|
// скролл вниз при новых сообщениях только если мы ща уже внизу
|
|
// скролл вниз при новых сообщениях только если мы ща уже внизу
|
|
// const MessagesList = ({ arrayOfMessages }) => {
|
|
// const MessagesList = ({ arrayOfMessages }) => {
|
|
// return (
|
|
// return (
|
|
-// <div className="Messages_map">
|
|
|
|
|
|
+// <div className="MessagesList">
|
|
// <ScrollableFeed>
|
|
// <ScrollableFeed>
|
|
// {!!arrayOfMessages && arrayOfMessages.map((mess) => <MessageItem key={mess._id} {...mess} />)}
|
|
// {!!arrayOfMessages && arrayOfMessages.map((mess) => <MessageItem key={mess._id} {...mess} />)}
|
|
// </ScrollableFeed>
|
|
// </ScrollableFeed>
|
|
@@ -136,38 +153,35 @@ const Messages = ({ _id = "", messages, getMsg }) => {
|
|
}
|
|
}
|
|
}, [_id]);
|
|
}, [_id]);
|
|
|
|
|
|
- // useEffect(() => {
|
|
|
|
- // if (typeof doSearchMsg === "function") doSearchMsg(_id, searchMsgStr);
|
|
|
|
- // }, []);
|
|
|
|
-
|
|
|
|
return (
|
|
return (
|
|
- <div className="Messages">
|
|
|
|
- <div className="position-relative">
|
|
|
|
- <div className="messagesTitle mb-3 border-bottom border-2 border-success p-2 roundIcon">
|
|
|
|
- {avatar && avatar.url ? (
|
|
|
|
- <img src={`${urlUploadConst}/${avatar.url}`}></img>
|
|
|
|
- ) : (
|
|
|
|
- <div className="bg-success border border-2 border-success gradient">
|
|
|
|
- <p className="fs-5 text-light fw-bolder">
|
|
|
|
- {title &&
|
|
|
|
- `${title.split(" ")[0][0].toUpperCase()}` +
|
|
|
|
- `${
|
|
|
|
- (title.split(" ").slice(1).pop() &&
|
|
|
|
- title.split(" ").slice(1).pop()[0].toUpperCase()) ||
|
|
|
|
- ""
|
|
|
|
- }`}
|
|
|
|
- </p>
|
|
|
|
- </div>
|
|
|
|
- )}
|
|
|
|
- <div className="middleHeight">
|
|
|
|
- <p className="fs-4 fw-bolder">{`${title}`}</p>
|
|
|
|
|
|
+ <div>
|
|
|
|
+ <div className="position-relative mb-3 border-bottom border-2 border-success ">
|
|
|
|
+ <div className="d-flex justify-content-start align-items-center">
|
|
|
|
+ <div className="avatarka">
|
|
|
|
+ {avatar && avatar.url ? (
|
|
|
|
+ <img src={`${urlUploadConst}/${avatar.url}`}></img>
|
|
|
|
+ ) : (
|
|
|
|
+ <div className="d-flex justify-content-center align-items-center bg-success border border-2 border-success gradient">
|
|
|
|
+ <div className="fs-5 text-light fw-bolder">
|
|
|
|
+ {title &&
|
|
|
|
+ `${title.split(" ")[0][0].toUpperCase()}` +
|
|
|
|
+ `${
|
|
|
|
+ (title.split(" ").slice(1).pop() &&
|
|
|
|
+ title.split(" ").slice(1).pop()[0].toUpperCase()) ||
|
|
|
|
+ ""
|
|
|
|
+ }`}
|
|
|
|
+ </div>
|
|
|
|
+ </div>
|
|
|
|
+ )}
|
|
</div>
|
|
</div>
|
|
|
|
+
|
|
|
|
+ <div className="fs-4 fw-bolder ms-2">{`${title}`}</div>
|
|
</div>
|
|
</div>
|
|
|
|
+
|
|
<span className="position-absolute bottom-0 end-0 badge rounded-pill bg-secondary">
|
|
<span className="position-absolute bottom-0 end-0 badge rounded-pill bg-secondary">
|
|
{` _chatId: ${_id}`} <span className="visually-hidden">id чата</span>
|
|
{` _chatId: ${_id}`} <span className="visually-hidden">id чата</span>
|
|
</span>
|
|
</span>
|
|
</div>
|
|
</div>
|
|
-
|
|
|
|
<div>
|
|
<div>
|
|
<CMessagesList />
|
|
<CMessagesList />
|
|
</div>
|
|
</div>
|
|
@@ -180,8 +194,4 @@ const CMessages = connect((s) => ({ _id: s.curChatId.curChatId, messages: s.msg
|
|
})(Messages);
|
|
})(Messages);
|
|
// - id chata
|
|
// - id chata
|
|
|
|
|
|
-export const ChatContain = ({ _chatId = "" }) => (
|
|
|
|
- <div className="ChatContain">
|
|
|
|
- <div>{!!_chatId && <CMessages />}</div>
|
|
|
|
- </div>
|
|
|
|
-);
|
|
|
|
|
|
+export const ChatContain = ({ _chatId = "" }) => <div>{!!_chatId && <CMessages />}</div>;
|