|
@@ -1,182 +1,111 @@
|
|
import { ButtonToMain } from "../Components";
|
|
import { ButtonToMain } from "../Components";
|
|
import { urlUploadConst } from "../const";
|
|
import { urlUploadConst } from "../const";
|
|
-import { actionGetAllUsers } from "../Actions";
|
|
|
|
|
|
+import { actionGetAllUsers, actionAllUsersFind } from "../Actions";
|
|
import { connect } from "react-redux";
|
|
import { connect } from "react-redux";
|
|
import { useEffect } from "react";
|
|
import { useEffect } from "react";
|
|
import { useState } from "react";
|
|
import { useState } from "react";
|
|
import { store } from "../Reducers";
|
|
import { store } from "../Reducers";
|
|
import { useRef } from "react";
|
|
import { useRef } from "react";
|
|
|
|
+import history from "../history";
|
|
|
|
+import { CUserInfo } from "../Layout";
|
|
|
|
+import { CAllUsersList } from "../Layout";
|
|
|
|
+import logo from "../images/logo23.png";
|
|
|
|
+import chat_square_text from "../icons/chat-square-text.svg";
|
|
|
|
|
|
-const ChatDashBoard = () => {
|
|
|
|
- return (
|
|
|
|
- <>
|
|
|
|
- <h4>ChatDashBoard</h4>
|
|
|
|
- </>
|
|
|
|
- );
|
|
|
|
-};
|
|
|
|
-
|
|
|
|
-const AllUsersConst = [
|
|
|
|
- {
|
|
|
|
- _id: "5e25e0a41719bf13be585729",
|
|
|
|
- login: "test3",
|
|
|
|
- nick: "",
|
|
|
|
- avatar: null,
|
|
|
|
- },
|
|
|
|
- {
|
|
|
|
- _id: "5e25bf671719bf13be5856c4",
|
|
|
|
- login: "t",
|
|
|
|
- nick: "t",
|
|
|
|
- avatar: null,
|
|
|
|
- },
|
|
|
|
- {
|
|
|
|
- _id: "5f3e4cd7c3de58221910d207",
|
|
|
|
- login: "Kiliar",
|
|
|
|
- nick: "Kiliar",
|
|
|
|
- avatar: null,
|
|
|
|
- },
|
|
|
|
- {
|
|
|
|
- _id: "5f528e96c3de58221910d20c",
|
|
|
|
- login: "mdm1",
|
|
|
|
- nick: "jj",
|
|
|
|
- avatar: null,
|
|
|
|
- },
|
|
|
|
- {
|
|
|
|
- _id: "5f568538c3de58221910d20e",
|
|
|
|
- login: "11",
|
|
|
|
- nick: "11",
|
|
|
|
- avatar: null,
|
|
|
|
- },
|
|
|
|
-];
|
|
|
|
|
|
+const MemberItem = ({ member }) => <pre>{member.login}</pre>;
|
|
|
|
|
|
-const UserItem = ({ _id, login, nick, avatar, myId }) => {
|
|
|
|
- const [isSelected, setIsSelected] = useState(false);
|
|
|
|
- const avatarUrl = avatar && avatar.url;
|
|
|
|
- nick = !!nick ? nick : login;
|
|
|
|
-
|
|
|
|
- const doSelectUser = () => {
|
|
|
|
- setIsSelected((prev) => !prev);
|
|
|
|
- };
|
|
|
|
|
|
+const ChatDashBoard = ({ members = {} }) => {
|
|
|
|
+ const [chatMembers, setChatMembers] = useState(Object.values(members));
|
|
|
|
+ useEffect(() => setChatMembers(Object.values(members)), [members]);
|
|
|
|
|
|
return (
|
|
return (
|
|
<>
|
|
<>
|
|
- <li
|
|
|
|
- className={`list-group-item list-group-item-${
|
|
|
|
- isSelected || _id === myId ? "success" : "light"
|
|
|
|
- } m-1 gradient shadow-sm border-2 `}
|
|
|
|
- onClick={doSelectUser}
|
|
|
|
- >
|
|
|
|
- <div className="d-flex justify-content-start align-items-center">
|
|
|
|
- <div className="avatarka ">
|
|
|
|
- {avatarUrl ? (
|
|
|
|
- <img
|
|
|
|
- src={`${urlUploadConst}/${avatarUrl}`}
|
|
|
|
- className="border border-2 border-success"
|
|
|
|
- ></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">
|
|
|
|
- {!!nick &&
|
|
|
|
- `${
|
|
|
|
- nick.split(" ")[0] &&
|
|
|
|
- nick.split(" ")[0][0] &&
|
|
|
|
- nick.split(" ")[0][0].toUpperCase()
|
|
|
|
- }` +
|
|
|
|
- `${
|
|
|
|
- (nick.split(" ").slice(1).pop() &&
|
|
|
|
- nick.split(" ").slice(1).pop()[0] &&
|
|
|
|
- nick.split(" ").slice(1).pop()[0].toUpperCase()) ||
|
|
|
|
- ""
|
|
|
|
- }`}
|
|
|
|
- </div>
|
|
|
|
- </div>
|
|
|
|
- )}
|
|
|
|
- </div>
|
|
|
|
- <div className="text-dark fs-5 ms-2">{`${nick}`}</div>
|
|
|
|
- </div>
|
|
|
|
- <span className="position-absolute bottom-0 end-0 badge rounded-pill bg-secondary">
|
|
|
|
- {_id}
|
|
|
|
- <span className="visually-hidden">всего сообщений</span>
|
|
|
|
- </span>
|
|
|
|
- </li>
|
|
|
|
|
|
+ <div className="ChatDashBoard bg-light">
|
|
|
|
+ <h4>ChatDashBoard</h4>
|
|
|
|
+ <table className="table table-bordered">
|
|
|
|
+ <tbody>
|
|
|
|
+ <tr>
|
|
|
|
+ <td>Chat title:</td>
|
|
|
|
+ <td>
|
|
|
|
+ <input
|
|
|
|
+ className="form-control mb-2 p-2 border border-success border-2"
|
|
|
|
+ placeholder="Input title for new chat"
|
|
|
|
+ ></input>
|
|
|
|
+ </td>
|
|
|
|
+ </tr>
|
|
|
|
+ <tr>
|
|
|
|
+ <td>Chat avatar:</td>
|
|
|
|
+ <td>
|
|
|
|
+ <span className="avatarka">
|
|
|
|
+ <img
|
|
|
|
+ src={chat_square_text}
|
|
|
|
+ className="border border-2 border-success bg-light "
|
|
|
|
+ alt="Avatar"
|
|
|
|
+ />
|
|
|
|
+ </span>
|
|
|
|
+ </td>
|
|
|
|
+ </tr>
|
|
|
|
+ <tr>
|
|
|
|
+ <td>Chat members:</td>
|
|
|
|
+ <td>
|
|
|
|
+ {chatMembers.map((member) => (
|
|
|
|
+ <MemberItem key={member._id} member={member} />
|
|
|
|
+ ))}
|
|
|
|
+ </td>
|
|
|
|
+ </tr>
|
|
|
|
+ </tbody>
|
|
|
|
+ </table>
|
|
|
|
+ </div>
|
|
</>
|
|
</>
|
|
);
|
|
);
|
|
};
|
|
};
|
|
|
|
|
|
-const AllUsers = ({ searchUserResultArr = [], findUsers = null, myId, myChats = [] }) => {
|
|
|
|
- const [users, setUsers] = useState([]);
|
|
|
|
- // console.log(myChats);
|
|
|
|
|
|
+const CChatDashBoard = connect((s) => ({ members: s.newChatUsers }))(ChatDashBoard);
|
|
|
|
|
|
- useEffect(() => {
|
|
|
|
- if (typeof getAllUsers === "function") findUsers();
|
|
|
|
- }, []);
|
|
|
|
|
|
+const PageNewChat = ({ doSearchUsers = null }) => {
|
|
|
|
+ const [searchUserStr, setSearchUserStr] = useState("");
|
|
|
|
+
|
|
|
|
+ // если не залогинены - вперед к регистрации/логину
|
|
|
|
+ if (!store.getState().auth || !store.getState().auth.login) {
|
|
|
|
+ history.push("/");
|
|
|
|
+ }
|
|
|
|
|
|
useEffect(() => {
|
|
useEffect(() => {
|
|
- if (!searchUserResultArr.length) {
|
|
|
|
- let tempObj = {};
|
|
|
|
- for (let chat of myChats) {
|
|
|
|
- for (let member of chat.members) {
|
|
|
|
- // console.log(members);
|
|
|
|
- let { _id, ...restData } = member;
|
|
|
|
- tempObj = { ...tempObj, [_id]: member };
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- // console.log("+++++++++++++++++++", tempObj);
|
|
|
|
- searchUserResultArr = Object.values(tempObj);
|
|
|
|
|
|
+ if (searchUserStr && typeof doSearchUsers === "function") {
|
|
|
|
+ doSearchUsers(0, searchUserStr);
|
|
}
|
|
}
|
|
- setUsers(
|
|
|
|
- searchUserResultArr
|
|
|
|
- .filter((el) => {
|
|
|
|
- if (!el.login) return false;
|
|
|
|
- if (el.nick && !el.nick.replace(/ +/g, " ").trim()) {
|
|
|
|
- return false;
|
|
|
|
- } else {
|
|
|
|
- return !!el.login.replace(/ +/g, " ").trim();
|
|
|
|
- }
|
|
|
|
- })
|
|
|
|
- .sort((a, b) => ((a.nick || a.login) > (b.nick || b.login) ? 1 : -1))
|
|
|
|
- );
|
|
|
|
- // выкидываем пользователей, у которых (ник из одних пробелов) или (нет ника но логин из одних пробелов)
|
|
|
|
- // console.log("+++++++++++++++++", users, searchUserResultArr);
|
|
|
|
- }, [searchUserResultArr]);
|
|
|
|
-
|
|
|
|
- return (
|
|
|
|
- <div className="bg-light">
|
|
|
|
- <h4>AllUsers</h4>
|
|
|
|
- <ul className="list-group allUsersList" role="tablist">
|
|
|
|
- {!!users && users.map((user) => <UserItem key={user._id} {...user} myId={myId} />)}
|
|
|
|
- </ul>
|
|
|
|
- </div>
|
|
|
|
- );
|
|
|
|
-};
|
|
|
|
|
|
+ }, [searchUserStr]);
|
|
|
|
|
|
-const CAllUsers = connect((s) => ({ searchUserResultArr: [], myId: s.auth.payloadId, myChats: s.auth.chats }), {
|
|
|
|
- findUsers: null,
|
|
|
|
-})(AllUsers);
|
|
|
|
-
|
|
|
|
-export const PageNewChat = () => {
|
|
|
|
- useEffect(() => {
|
|
|
|
- store.dispatch({ type: "CLEAR_USERS" });
|
|
|
|
- }, []);
|
|
|
|
|
|
+ //FIXME: это для чего???? уже не помню и похоже не надо ))))
|
|
|
|
+ // useEffect(() => {
|
|
|
|
+ // store.dispatch({ type: "CLEAR_USERS" });
|
|
|
|
+ // }, []);
|
|
|
|
|
|
return (
|
|
return (
|
|
<>
|
|
<>
|
|
- PageNewChat
|
|
|
|
- <ButtonToMain />
|
|
|
|
<div className="PageMain container-fluid">
|
|
<div className="PageMain container-fluid">
|
|
<div className="row g-3">
|
|
<div className="row g-3">
|
|
- <div className="col-md-4">
|
|
|
|
|
|
+ <div className="col-md-4 bg-light">
|
|
|
|
+ <CUserInfo />
|
|
|
|
+ <ButtonToMain />
|
|
|
|
+
|
|
<input
|
|
<input
|
|
className="form-control mb-2 p-2 border border-success border-2"
|
|
className="form-control mb-2 p-2 border border-success border-2"
|
|
- placeholder="Search user by nick/login/_id"
|
|
|
|
- onInput={(e) => {}}
|
|
|
|
|
|
+ placeholder="Search users by nick/login/_id"
|
|
|
|
+ onInput={(e) => {
|
|
|
|
+ setSearchUserStr(e.target.value);
|
|
|
|
+ }}
|
|
></input>
|
|
></input>
|
|
- <CAllUsers />
|
|
|
|
|
|
+
|
|
|
|
+ <CAllUsersList searchUserStr={searchUserStr} />
|
|
</div>
|
|
</div>
|
|
<div className="col-md-8">
|
|
<div className="col-md-8">
|
|
- <ChatDashBoard />
|
|
|
|
|
|
+ <CChatDashBoard />
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</>
|
|
</>
|
|
);
|
|
);
|
|
};
|
|
};
|
|
|
|
+
|
|
|
|
+export const CPageNewChat = connect(null, { doSearchUsers: actionAllUsersFind })(PageNewChat);
|