feat: lots updates
This commit is contained in:
@@ -1,186 +0,0 @@
|
||||
import { useEffect } from "react";
|
||||
import styled from "styled-components";
|
||||
import { useSelector } from "react-redux";
|
||||
|
||||
import Message from "../../common/component/Message";
|
||||
import ChannelIcon from "../../common/component/ChannelIcon";
|
||||
import Send from "../../common/component/Send";
|
||||
import { useGetContactsQuery } from "../../app/services/contact";
|
||||
// import msgs from "./channel.msg.mock.json";
|
||||
import Contact from "../../common/component/Contact";
|
||||
|
||||
const StyledWrapper = styled.article`
|
||||
position: relative;
|
||||
width: 100%;
|
||||
background: #fff;
|
||||
height: 100vh;
|
||||
overflow-y: scroll;
|
||||
overflow-x: hidden;
|
||||
.head {
|
||||
height: 56px;
|
||||
padding: 0 20px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
box-shadow: 0px 1px 0px rgba(0, 0, 0, 0.1);
|
||||
.txt {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 5px;
|
||||
.title {
|
||||
font-size: 16px;
|
||||
line-height: 24px;
|
||||
color: #1c1c1e;
|
||||
}
|
||||
.desc {
|
||||
margin-left: 8px;
|
||||
font-weight: normal;
|
||||
font-size: 16px;
|
||||
line-height: 24px;
|
||||
color: #616161;
|
||||
}
|
||||
}
|
||||
}
|
||||
.main {
|
||||
width: 100%;
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
justify-content: space-between;
|
||||
position: relative;
|
||||
padding: 0 0 20px 16px;
|
||||
.notification {
|
||||
padding: 3px 8px;
|
||||
font-style: normal;
|
||||
font-weight: 600;
|
||||
font-size: 12px;
|
||||
line-height: 18px;
|
||||
color: #fff;
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 10px;
|
||||
width: 900px;
|
||||
height: 24px;
|
||||
background: linear-gradient(135deg, #3c8ce7 0%, #00eaff 100%);
|
||||
border-radius: 0px 0px 8px 8px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
.clear {
|
||||
cursor: pointer;
|
||||
color: inherit;
|
||||
border: none;
|
||||
background: none;
|
||||
outline: none;
|
||||
}
|
||||
}
|
||||
.channel {
|
||||
width: 684px;
|
||||
.info {
|
||||
padding-top: 114px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: flex-start;
|
||||
gap: 8px;
|
||||
.title {
|
||||
font-weight: bold;
|
||||
font-size: 36px;
|
||||
line-height: 44px;
|
||||
}
|
||||
.desc {
|
||||
color: #78787c;
|
||||
font-weight: 500;
|
||||
font-size: 16px;
|
||||
line-height: 24px;
|
||||
}
|
||||
.edit {
|
||||
color: #3c8ce7;
|
||||
padding: 0;
|
||||
border: none;
|
||||
outline: none;
|
||||
background: none;
|
||||
font-style: normal;
|
||||
font-weight: 500;
|
||||
font-size: 16px;
|
||||
line-height: 24px;
|
||||
}
|
||||
}
|
||||
.chat {
|
||||
padding: 18px 0;
|
||||
}
|
||||
}
|
||||
.contacts {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 5px;
|
||||
/* todo */
|
||||
width: 226px;
|
||||
height: calc(100vh - 56px);
|
||||
overflow-y: scroll;
|
||||
background: #f5f6f7;
|
||||
padding: 16px;
|
||||
}
|
||||
}
|
||||
`;
|
||||
export default function ChannelChat({ cid = "", data = {} }) {
|
||||
const msgs = useSelector((store) => {
|
||||
return store.channelMsg[cid] || {};
|
||||
});
|
||||
const { data: users } = useGetContactsQuery();
|
||||
useEffect(() => {
|
||||
console.log({ cid });
|
||||
}, [cid]);
|
||||
const { name, description, is_public, members = [] } = data;
|
||||
const filteredUsers =
|
||||
members.length == 0
|
||||
? users
|
||||
: users.filter((u) => {
|
||||
return members.includes(u.uid);
|
||||
});
|
||||
console.log("channel message list", msgs);
|
||||
return (
|
||||
<StyledWrapper>
|
||||
<header className="head">
|
||||
<div className="txt">
|
||||
<ChannelIcon personal={!is_public} />
|
||||
<span className="title">{name}</span>
|
||||
|
||||
<span className="desc">{description}</span>
|
||||
</div>
|
||||
<ul className="members">members</ul>
|
||||
</header>
|
||||
<main className="main">
|
||||
<div className="notification">
|
||||
<div className="content">25+ new messages since 3:24 PM</div>
|
||||
<button className="clear">Mark As Read</button>
|
||||
</div>
|
||||
<div className="channel">
|
||||
<div className="info">
|
||||
<h2 className="title">Welcome to #{name} !</h2>
|
||||
<p className="desc">This is the start of the #{name} channel. </p>
|
||||
<button className="edit">Edit Channel</button>
|
||||
</div>
|
||||
<div className="chat">
|
||||
{Object.entries(msgs).map(([mid, msg]) => {
|
||||
if (!msg) return null;
|
||||
const { from_uid, content, created_at } = msg;
|
||||
return (
|
||||
<Message
|
||||
key={mid}
|
||||
time={created_at}
|
||||
uid={from_uid}
|
||||
content={content}
|
||||
/>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
<div className="contacts">
|
||||
{filteredUsers.map(({ name, status, uid }) => {
|
||||
return <Contact key={name} uid={uid} status={status} />;
|
||||
})}
|
||||
</div>
|
||||
</main>
|
||||
<Send id={cid} type="channel" name={name} />
|
||||
</StyledWrapper>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
import { useEffect } from "react";
|
||||
|
||||
import { useSelector, useDispatch } from "react-redux";
|
||||
import dayjs from "dayjs";
|
||||
|
||||
import Message from "../../../common/component/Message";
|
||||
import ChannelIcon from "../../../common/component/ChannelIcon";
|
||||
import Send from "../../../common/component/Send";
|
||||
import {
|
||||
clearChannelMsgUnread,
|
||||
setLastAccessTime,
|
||||
} from "../../../app/slices/message.channel";
|
||||
import { useGetContactsQuery } from "../../../app/services/contact";
|
||||
import Contact from "../../../common/component/Contact";
|
||||
import Layout from "../Layout";
|
||||
import {
|
||||
StyledNotification,
|
||||
StyledContacts,
|
||||
StyledChannelChat,
|
||||
StyledHeader,
|
||||
} from "./styled";
|
||||
|
||||
export default function ChannelChat({ cid = "", unreads = 0, data = {} }) {
|
||||
const dispatch = useDispatch();
|
||||
const msgs = useSelector((store) => {
|
||||
return store.channelMsg[cid] || {};
|
||||
});
|
||||
const { data: users } = useGetContactsQuery();
|
||||
const handleClearUnreads = () => {
|
||||
dispatch(clearChannelMsgUnread(cid));
|
||||
};
|
||||
useEffect(() => {
|
||||
console.log({ cid });
|
||||
return () => {
|
||||
dispatch(setLastAccessTime(cid));
|
||||
};
|
||||
}, [cid]);
|
||||
const { name, description, is_public, members = [] } = data;
|
||||
const filteredUsers =
|
||||
members.length == 0
|
||||
? users
|
||||
: users.filter((u) => {
|
||||
return members.includes(u.uid);
|
||||
});
|
||||
console.log("channel message list", msgs);
|
||||
return (
|
||||
<Layout
|
||||
header={
|
||||
<StyledHeader>
|
||||
<div className="txt">
|
||||
<ChannelIcon personal={!is_public} />
|
||||
<span className="title">{name}</span>
|
||||
<span className="desc">{description}</span>
|
||||
</div>
|
||||
<ul className="members">members</ul>
|
||||
</StyledHeader>
|
||||
}
|
||||
contacts={
|
||||
<StyledContacts>
|
||||
{filteredUsers.map(({ name, status, uid }) => {
|
||||
return <Contact key={name} uid={uid} status={status} />;
|
||||
})}
|
||||
</StyledContacts>
|
||||
}
|
||||
>
|
||||
<StyledChannelChat>
|
||||
<div className="wrapper">
|
||||
<div className="info">
|
||||
<h2 className="title">Welcome to #{name} !</h2>
|
||||
<p className="desc">This is the start of the #{name} channel. </p>
|
||||
{/* <button className="edit">Edit Channel</button> */}
|
||||
</div>
|
||||
<div className="chat">
|
||||
{Object.entries(msgs).map(([mid, msg]) => {
|
||||
if (!msg) return null;
|
||||
const { from_uid, content, created_at, unread } = msg;
|
||||
return (
|
||||
<Message
|
||||
unread={unread}
|
||||
gid={cid}
|
||||
mid={mid}
|
||||
key={mid}
|
||||
time={created_at}
|
||||
fromUid={from_uid}
|
||||
content={content}
|
||||
/>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<Send id={cid} type="channel" name={name} />
|
||||
<div className="placeholder"></div>
|
||||
</StyledChannelChat>
|
||||
{unreads != 0 && (
|
||||
<StyledNotification>
|
||||
<div className="content">
|
||||
{unreads} new messages
|
||||
{msgs.lastAccess
|
||||
? `since ${dayjs(msgs.lastAccess).format("YYYY-MM-DD h:mm:ss A")}`
|
||||
: ""}
|
||||
</div>
|
||||
<button onClick={handleClearUnreads} className="clear">
|
||||
Mark As Read
|
||||
</button>
|
||||
</StyledNotification>
|
||||
)}
|
||||
</Layout>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
import styled from "styled-components";
|
||||
export const StyledHeader = styled.header`
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
.txt {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 5px;
|
||||
.title {
|
||||
font-size: 16px;
|
||||
line-height: 24px;
|
||||
color: #1c1c1e;
|
||||
}
|
||||
.desc {
|
||||
margin-left: 8px;
|
||||
font-weight: normal;
|
||||
font-size: 16px;
|
||||
line-height: 24px;
|
||||
color: #616161;
|
||||
}
|
||||
}
|
||||
`;
|
||||
export const StyledNotification = styled.div`
|
||||
padding: 3px 8px;
|
||||
font-style: normal;
|
||||
font-weight: 600;
|
||||
font-size: 12px;
|
||||
line-height: 18px;
|
||||
color: #fff;
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 10px;
|
||||
width: 900px;
|
||||
height: 24px;
|
||||
background: linear-gradient(135deg, #3c8ce7 0%, #00eaff 100%);
|
||||
border-radius: 0px 0px 8px 8px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
.clear {
|
||||
cursor: pointer;
|
||||
color: inherit;
|
||||
border: none;
|
||||
background: none;
|
||||
outline: none;
|
||||
}
|
||||
`;
|
||||
export const StyledContacts = styled.div`
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 5px;
|
||||
/* todo */
|
||||
width: 226px;
|
||||
height: calc(100vh - 56px);
|
||||
overflow-y: scroll;
|
||||
background: #f5f6f7;
|
||||
padding: 16px;
|
||||
`;
|
||||
export const StyledChannelChat = styled.article`
|
||||
position: relative;
|
||||
width: 100%;
|
||||
/* margin-bottom: 120px; */
|
||||
> .wrapper {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
padding: 0 16px;
|
||||
height: calc(100vh - 56px - 80px);
|
||||
overflow-y: scroll;
|
||||
overflow-x: visible;
|
||||
.info {
|
||||
padding-top: 114px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: flex-start;
|
||||
gap: 8px;
|
||||
.title {
|
||||
font-weight: bold;
|
||||
font-size: 36px;
|
||||
line-height: 44px;
|
||||
}
|
||||
.desc {
|
||||
color: #78787c;
|
||||
font-weight: 500;
|
||||
font-size: 16px;
|
||||
line-height: 24px;
|
||||
}
|
||||
.edit {
|
||||
color: #3c8ce7;
|
||||
padding: 0;
|
||||
border: none;
|
||||
outline: none;
|
||||
background: none;
|
||||
font-style: normal;
|
||||
font-weight: 500;
|
||||
font-size: 16px;
|
||||
line-height: 24px;
|
||||
}
|
||||
}
|
||||
.chat {
|
||||
height: -webkit-fill-available;
|
||||
padding: 18px 0;
|
||||
}
|
||||
}
|
||||
.placeholder {
|
||||
width: 100%;
|
||||
height: 80px;
|
||||
}
|
||||
`;
|
||||
@@ -1,94 +0,0 @@
|
||||
import { useState, useEffect } from "react";
|
||||
import styled from "styled-components";
|
||||
import { useSelector } from "react-redux";
|
||||
import Message from "../../common/component/Message";
|
||||
import Send from "../../common/component/Send";
|
||||
// import msgs from "./channel.msg.mock.json";
|
||||
import Contact from "../../common/component/Contact";
|
||||
import { useGetContactsQuery } from "../../app/services/contact";
|
||||
|
||||
const StyledWrapper = styled.article`
|
||||
position: relative;
|
||||
width: 100%;
|
||||
background: #fff;
|
||||
height: 100vh;
|
||||
overflow-y: scroll;
|
||||
overflow-x: hidden;
|
||||
.head {
|
||||
height: 56px;
|
||||
padding: 0 20px 0 10px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
box-shadow: 0px 1px 0px rgba(0, 0, 0, 0.1);
|
||||
.txt {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 5px;
|
||||
.title {
|
||||
font-size: 16px;
|
||||
line-height: 24px;
|
||||
color: #1c1c1e;
|
||||
}
|
||||
.desc {
|
||||
margin-left: 8px;
|
||||
font-weight: normal;
|
||||
font-size: 16px;
|
||||
line-height: 24px;
|
||||
color: #616161;
|
||||
}
|
||||
}
|
||||
}
|
||||
.main {
|
||||
width: 100%;
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
justify-content: space-between;
|
||||
position: relative;
|
||||
padding: 0 0 20px 16px;
|
||||
.chat {
|
||||
width: 890px;
|
||||
padding: 18px 0;
|
||||
}
|
||||
}
|
||||
`;
|
||||
export default function DMChat({ uid = "" }) {
|
||||
const msgs = useSelector((store) => {
|
||||
return store.userMsg[uid] || {};
|
||||
});
|
||||
const { data: contacts } = useGetContactsQuery();
|
||||
const [currUser, setCurrUser] = useState(null);
|
||||
useEffect(() => {
|
||||
console.log({ uid });
|
||||
if (uid && contacts) {
|
||||
setCurrUser(contacts.find((c) => c.uid == uid));
|
||||
}
|
||||
}, [uid, contacts]);
|
||||
if (!currUser) return null;
|
||||
console.log("user msgs", msgs);
|
||||
return (
|
||||
<StyledWrapper>
|
||||
<header className="head">
|
||||
<Contact interactive={false} uid={currUser.uid} />
|
||||
{/* <ul className="members">members</ul> */}
|
||||
</header>
|
||||
<main className="main">
|
||||
<div className="chat">
|
||||
{Object.entries(msgs).map(([mid, msg]) => {
|
||||
if (!msg) return null;
|
||||
const { from_uid, content, created_at } = msg;
|
||||
return (
|
||||
<Message
|
||||
key={mid}
|
||||
time={created_at}
|
||||
uid={from_uid}
|
||||
content={content}
|
||||
/>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</main>
|
||||
<Send type="user" name={currUser?.name} id={currUser?.uid} />
|
||||
</StyledWrapper>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
import { useState, useEffect } from "react";
|
||||
import { useSelector } from "react-redux";
|
||||
import Message from "../../../common/component/Message";
|
||||
import Send from "../../../common/component/Send";
|
||||
import Contact from "../../../common/component/Contact";
|
||||
import { useGetContactsQuery } from "../../../app/services/contact";
|
||||
import Layout from "../Layout";
|
||||
|
||||
import { StyledHeader, StyledDMChat } from "./styled";
|
||||
|
||||
export default function DMChat({ uid = "" }) {
|
||||
const msgs = useSelector((store) => {
|
||||
return store.userMsg[uid] || {};
|
||||
});
|
||||
const { data: contacts } = useGetContactsQuery();
|
||||
const [currUser, setCurrUser] = useState(null);
|
||||
useEffect(() => {
|
||||
console.log({ uid });
|
||||
if (uid && contacts) {
|
||||
setCurrUser(contacts.find((c) => c.uid == uid));
|
||||
}
|
||||
}, [uid, contacts]);
|
||||
if (!currUser) return null;
|
||||
console.log("user msgs", msgs);
|
||||
return (
|
||||
<Layout
|
||||
header={
|
||||
<StyledHeader>
|
||||
<Contact interactive={false} uid={currUser.uid} />
|
||||
</StyledHeader>
|
||||
}
|
||||
>
|
||||
<StyledDMChat>
|
||||
<div className="chat">
|
||||
{Object.entries(msgs).map(([mid, msg]) => {
|
||||
if (!msg) return null;
|
||||
console.log("user msg", msg);
|
||||
const { from_uid, content, created_at, unread } = msg;
|
||||
return (
|
||||
<Message
|
||||
unread={unread}
|
||||
fromUid={from_uid}
|
||||
mid={mid}
|
||||
key={mid}
|
||||
time={created_at}
|
||||
uid={uid}
|
||||
content={content}
|
||||
/>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</StyledDMChat>
|
||||
<div className="placeholder"></div>
|
||||
<Send type="user" name={currUser?.name} id={currUser?.uid} />
|
||||
</Layout>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
import styled from "styled-components";
|
||||
export const StyledHeader = styled.header`
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
/* padding: 0 20px 0 10px; */
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
/* tricky */
|
||||
> div {
|
||||
padding-left: 4px;
|
||||
}
|
||||
.txt {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 5px;
|
||||
.title {
|
||||
font-size: 16px;
|
||||
line-height: 24px;
|
||||
color: #1c1c1e;
|
||||
}
|
||||
.desc {
|
||||
margin-left: 8px;
|
||||
font-weight: normal;
|
||||
font-size: 16px;
|
||||
line-height: 24px;
|
||||
color: #616161;
|
||||
}
|
||||
}
|
||||
`;
|
||||
export const StyledDMChat = styled.article`
|
||||
position: relative;
|
||||
width: 100%;
|
||||
padding-top: 25px;
|
||||
/* margin-bottom: 120px; */
|
||||
> .chat {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
padding: 0 16px;
|
||||
height: calc(100vh - 56px - 80px);
|
||||
overflow-y: scroll;
|
||||
overflow-x: visible;
|
||||
}
|
||||
.placeholder {
|
||||
width: 100%;
|
||||
height: 80px;
|
||||
}
|
||||
`;
|
||||
@@ -0,0 +1,36 @@
|
||||
import React from "react";
|
||||
import styled from "styled-components";
|
||||
const StyledWrapper = styled.article`
|
||||
position: relative;
|
||||
width: 100%;
|
||||
background: #fff;
|
||||
height: 100vh;
|
||||
.head {
|
||||
height: 56px;
|
||||
padding: 0 20px;
|
||||
box-shadow: 0px 1px 0px rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
.main {
|
||||
height: calc(100vh - 56px);
|
||||
width: 100%;
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
justify-content: space-between;
|
||||
position: relative;
|
||||
.members {
|
||||
border-top: 1px solid transparent;
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
export default function Layout({ children, header, contacts = null }) {
|
||||
return (
|
||||
<StyledWrapper>
|
||||
<header className="head">{header}</header>
|
||||
<main className="main">
|
||||
{children}
|
||||
{contacts && <div className="members">{contacts}</div>}
|
||||
</main>
|
||||
</StyledWrapper>
|
||||
);
|
||||
}
|
||||
+41
-26
@@ -3,10 +3,9 @@ import { useState } from "react";
|
||||
import { NavLink, useParams } from "react-router-dom";
|
||||
import { useSelector } from "react-redux";
|
||||
import dayjs from "dayjs";
|
||||
|
||||
import { MdAdd } from "react-icons/md";
|
||||
import { AiOutlineCaretDown } from "react-icons/ai";
|
||||
import { useGetChannelsQuery } from "../../app/services/channel";
|
||||
|
||||
import { useGetContactsQuery } from "../../app/services/contact";
|
||||
import StyledWrapper from "./styled";
|
||||
import Search from "../../common/component/Search";
|
||||
@@ -18,13 +17,16 @@ import ContactsModal from "../../common/component/ContactsModal";
|
||||
import ChannelModal from "../../common/component/ChannelModal";
|
||||
|
||||
export default function ChatPage() {
|
||||
const UserMsgData = useSelector((store) => {
|
||||
return store.userMsg;
|
||||
const { channels, UserMsgData, ChannelMsgData } = useSelector((store) => {
|
||||
return {
|
||||
channels: store.channels,
|
||||
UserMsgData: store.userMsg,
|
||||
ChannelMsgData: store.channelMsg,
|
||||
};
|
||||
});
|
||||
const [channelModalVisible, setChannelModalVisible] = useState(false);
|
||||
const [contactsModalVisible, setContactsModalVisible] = useState(false);
|
||||
const { channel_id, user_id } = useParams();
|
||||
const { data: channels } = useGetChannelsQuery();
|
||||
const { data: contacts } = useGetContactsQuery();
|
||||
const toggleContactsModalVisible = () => {
|
||||
setContactsModalVisible((prev) => !prev);
|
||||
@@ -32,10 +34,16 @@ export default function ChatPage() {
|
||||
const toggleChannelModalVisible = () => {
|
||||
setChannelModalVisible((prev) => !prev);
|
||||
};
|
||||
console.log("channels", channels);
|
||||
if (!channels || !contacts) return null;
|
||||
const getUnreadCount = (gid) => {
|
||||
return Object.values(ChannelMsgData[gid] || {}).filter((m) => m.unread)
|
||||
.length;
|
||||
};
|
||||
if (!contacts) return null;
|
||||
const Sessions = Object.keys(UserMsgData);
|
||||
const tmpSessionUser = contacts.find((c) => c.uid == user_id);
|
||||
const transformedChannels = Object.entries(channels).map(([key, obj]) => {
|
||||
return { id: key, ...obj };
|
||||
});
|
||||
return (
|
||||
<>
|
||||
{channelModalVisible && (
|
||||
@@ -60,22 +68,25 @@ export default function ChatPage() {
|
||||
/>
|
||||
</h3>
|
||||
<nav className="nav">
|
||||
{channels.map(({ gid, is_public, name, description }) => {
|
||||
return (
|
||||
<NavLink
|
||||
title={description}
|
||||
key={gid}
|
||||
className="link"
|
||||
to={`/chat/channel/${gid}`}
|
||||
>
|
||||
<span className="txt">
|
||||
<ChannelIcon personal={!is_public} />
|
||||
{name}
|
||||
</span>
|
||||
<i className="badge">12</i>
|
||||
</NavLink>
|
||||
);
|
||||
})}
|
||||
{transformedChannels.map(
|
||||
({ id, is_public, name, description }) => {
|
||||
let unreads = getUnreadCount(id);
|
||||
return (
|
||||
<NavLink
|
||||
title={description}
|
||||
key={id}
|
||||
className="link"
|
||||
to={`/chat/channel/${id}`}
|
||||
>
|
||||
<span className="txt">
|
||||
<ChannelIcon personal={!is_public} />
|
||||
{name}
|
||||
</span>
|
||||
{unreads > 0 && <i className="badge">{unreads}</i>}
|
||||
</NavLink>
|
||||
);
|
||||
}
|
||||
)}
|
||||
</nav>
|
||||
</div>
|
||||
<div className="list dms">
|
||||
@@ -94,6 +105,9 @@ export default function ChatPage() {
|
||||
{Sessions.map((uid) => {
|
||||
let currUser = contacts.find((c) => c.uid == uid);
|
||||
let latestMid = Object.keys(UserMsgData[uid]).sort().pop();
|
||||
let unreads = Object.values(UserMsgData[uid] || {}).filter(
|
||||
(m) => m.unread
|
||||
).length;
|
||||
let latestMsg = UserMsgData[uid][latestMid];
|
||||
return (
|
||||
<NavLink key={uid} className="session" to={`/chat/dm/${uid}`}>
|
||||
@@ -108,7 +122,7 @@ export default function ChatPage() {
|
||||
|
||||
<div className="down">
|
||||
<div className="msg">{latestMsg.content}</div>
|
||||
<i className="badge">3</i>
|
||||
{unreads > 0 && <i className="badge">{unreads}</i>}
|
||||
</div>
|
||||
</div>
|
||||
</NavLink>
|
||||
@@ -129,7 +143,7 @@ export default function ChatPage() {
|
||||
|
||||
<div className="down">
|
||||
<div className="msg"></div>
|
||||
<i className="badge">3</i>
|
||||
{/* <i className="badge">3</i> */}
|
||||
</div>
|
||||
</div>
|
||||
</NavLink>
|
||||
@@ -140,8 +154,9 @@ export default function ChatPage() {
|
||||
<div className="right">
|
||||
{channel_id && (
|
||||
<ChannelChat
|
||||
unreads={getUnreadCount(channel_id)}
|
||||
cid={channel_id}
|
||||
data={channels.find(({ gid }) => gid == channel_id)}
|
||||
data={channels[channel_id]}
|
||||
/>
|
||||
)}
|
||||
{user_id && <DMChat uid={user_id} />}
|
||||
|
||||
+143
-140
@@ -1,153 +1,156 @@
|
||||
import styled from 'styled-components';
|
||||
import styled from "styled-components";
|
||||
const StyledWrapper = styled.div`
|
||||
display: flex;
|
||||
height: 100%;
|
||||
> .left {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
width: 260px;
|
||||
box-shadow: inset -1px 0px 0px rgba(0, 0, 0, 0.1);
|
||||
.list {
|
||||
margin: 12px 8px;
|
||||
.title {
|
||||
padding: 0 8px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
margin-bottom: 4px;
|
||||
cursor: pointer;
|
||||
> .txt {
|
||||
user-select: none;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 5px;
|
||||
font-weight: bold;
|
||||
font-size: 12px;
|
||||
line-height: 20px;
|
||||
color: #78787c;
|
||||
}
|
||||
}
|
||||
> .nav {
|
||||
height: 100%;
|
||||
> .left {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 4px;
|
||||
a {
|
||||
text-decoration: none;
|
||||
}
|
||||
.link {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
padding: 8px;
|
||||
border-radius: 4px;
|
||||
&:hover,
|
||||
&.active {
|
||||
background: rgba(116, 127, 141, 0.1);
|
||||
}
|
||||
> .txt {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 5px;
|
||||
color: #1c1c1e;
|
||||
font-weight: 600;
|
||||
font-size: 14px;
|
||||
line-height: 20px;
|
||||
}
|
||||
> .badge {
|
||||
padding: 3px;
|
||||
color: #fff;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 16px;
|
||||
height: 16px;
|
||||
border-radius: 50%;
|
||||
background: #bfbfbf;
|
||||
font-weight: 900;
|
||||
font-size: 10px;
|
||||
line-height: 10px;
|
||||
&.dot {
|
||||
width: 6px;
|
||||
height: 6px;
|
||||
padding: 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
.session {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 8px;
|
||||
padding: 4px 8px;
|
||||
border-radius: 4px;
|
||||
&:hover,
|
||||
&.active {
|
||||
background: rgba(116, 127, 141, 0.1);
|
||||
}
|
||||
.avatar {
|
||||
width: 32px;
|
||||
height: 32px;
|
||||
border-radius: 50%;
|
||||
/* img{
|
||||
width: 100%;
|
||||
} */
|
||||
}
|
||||
.details {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
width: 100%;
|
||||
.up {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
.name {
|
||||
font-weight: 600;
|
||||
font-size: 14px;
|
||||
line-height: 20px;
|
||||
color: #52525b;
|
||||
}
|
||||
time {
|
||||
font-weight: 500;
|
||||
font-size: 12px;
|
||||
line-height: 18px;
|
||||
color: #78787c;
|
||||
}
|
||||
}
|
||||
.down {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
.msg {
|
||||
font-weight: normal;
|
||||
font-size: 12px;
|
||||
line-height: 18px;
|
||||
color: #78787c;
|
||||
}
|
||||
> .badge {
|
||||
letter-spacing: -1px;
|
||||
padding: 2px;
|
||||
color: #fff;
|
||||
height: 16px;
|
||||
min-width: 16px;
|
||||
width: 260px;
|
||||
box-shadow: inset -1px 0px 0px rgba(0, 0, 0, 0.1);
|
||||
.list {
|
||||
margin: 12px 8px;
|
||||
.title {
|
||||
padding: 0 8px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
border-radius: 10px;
|
||||
background: #1fe1f9;
|
||||
font-weight: 900;
|
||||
font-size: 10px;
|
||||
line-height: 10px;
|
||||
&.mute {
|
||||
background: #bfbfbf;
|
||||
justify-content: space-between;
|
||||
margin-bottom: 4px;
|
||||
cursor: pointer;
|
||||
> .txt {
|
||||
user-select: none;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 5px;
|
||||
font-weight: bold;
|
||||
font-size: 12px;
|
||||
line-height: 20px;
|
||||
color: #78787c;
|
||||
}
|
||||
}
|
||||
> .nav {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 4px;
|
||||
a {
|
||||
text-decoration: none;
|
||||
}
|
||||
.link {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
padding: 8px;
|
||||
border-radius: 4px;
|
||||
&:hover,
|
||||
&.active {
|
||||
background: rgba(116, 127, 141, 0.1);
|
||||
}
|
||||
> .txt {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 5px;
|
||||
color: #1c1c1e;
|
||||
font-weight: 600;
|
||||
font-size: 14px;
|
||||
line-height: 20px;
|
||||
}
|
||||
> .badge {
|
||||
color: #fff;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
height: 20px;
|
||||
min-width: 20px;
|
||||
border-radius: 50%;
|
||||
background: #bfbfbf;
|
||||
font-weight: 900;
|
||||
font-size: 10px;
|
||||
line-height: 10px;
|
||||
&.dot {
|
||||
width: 6px;
|
||||
height: 6px;
|
||||
padding: 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
.session {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 8px;
|
||||
padding: 4px 8px;
|
||||
border-radius: 4px;
|
||||
&:hover,
|
||||
&.active {
|
||||
background: rgba(116, 127, 141, 0.1);
|
||||
}
|
||||
.avatar {
|
||||
width: 32px;
|
||||
height: 32px;
|
||||
border-radius: 50%;
|
||||
/* img{
|
||||
width: 100%;
|
||||
} */
|
||||
}
|
||||
.details {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
width: 100%;
|
||||
.up {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
.name {
|
||||
font-weight: 600;
|
||||
font-size: 14px;
|
||||
line-height: 20px;
|
||||
color: #52525b;
|
||||
}
|
||||
time {
|
||||
font-weight: 500;
|
||||
font-size: 12px;
|
||||
line-height: 18px;
|
||||
color: #78787c;
|
||||
}
|
||||
}
|
||||
.down {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
.msg {
|
||||
font-weight: normal;
|
||||
font-size: 12px;
|
||||
line-height: 18px;
|
||||
color: #78787c;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
width: 140px;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
> .badge {
|
||||
/* letter-spacing: -1px; */
|
||||
/* padding: 2px; */
|
||||
color: #fff;
|
||||
height: 20px;
|
||||
min-width: 20px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
border-radius: 10px;
|
||||
background: #1fe1f9;
|
||||
font-weight: 900;
|
||||
font-size: 10px;
|
||||
line-height: 10px;
|
||||
&.mute {
|
||||
background: #bfbfbf;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
> .right {
|
||||
width: 100%;
|
||||
}
|
||||
> .right {
|
||||
width: 100%;
|
||||
}
|
||||
`;
|
||||
|
||||
export default StyledWrapper;
|
||||
|
||||
@@ -1,15 +1,20 @@
|
||||
// import React from 'react';
|
||||
import { useEffect } from "react";
|
||||
import styled from "styled-components";
|
||||
import { AiOutlineCaretDown, AiOutlineSound } from "react-icons/ai";
|
||||
import { MdOutlineKeyboardVoice } from "react-icons/md";
|
||||
import { useSelector } from "react-redux";
|
||||
import { useSelector, useDispatch } from "react-redux";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
|
||||
import { clearAuthData } from "../../app/slices/auth.data";
|
||||
|
||||
import { useLazyLogoutQuery } from "../../app/services/auth";
|
||||
|
||||
const StyledWrapper = styled.div`
|
||||
position: absolute;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
padding: 16px 12px;
|
||||
width: -webkit-fill-available;
|
||||
width: 100%;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
@@ -37,14 +42,28 @@ const StyledWrapper = styled.div`
|
||||
}
|
||||
}
|
||||
`;
|
||||
export default function CurrentUser({ collaspe = false }) {
|
||||
export default function CurrentUser({ expand = true }) {
|
||||
const dispatch = useDispatch();
|
||||
const navigate = useNavigate();
|
||||
const [logout, { isSuccess }] = useLazyLogoutQuery();
|
||||
const { user } = useSelector((store) => store.authData);
|
||||
const handleLogout = () => {
|
||||
logout();
|
||||
};
|
||||
useEffect(() => {
|
||||
if (isSuccess) {
|
||||
dispatch(clearAuthData());
|
||||
navigate("/login");
|
||||
}
|
||||
}, [isSuccess]);
|
||||
|
||||
if (!user) return null;
|
||||
const { name } = user;
|
||||
return (
|
||||
<StyledWrapper>
|
||||
<div className="profile" title={name}>
|
||||
<img
|
||||
onDoubleClick={handleLogout}
|
||||
title={name}
|
||||
src={`https://avatars.dicebear.com/api/adventurer-neutral/${name}.svg`}
|
||||
alt="user avatar"
|
||||
@@ -52,7 +71,7 @@ export default function CurrentUser({ collaspe = false }) {
|
||||
/>
|
||||
<AiOutlineCaretDown className="toggle" width={20} color="#C4C4C4" />
|
||||
</div>
|
||||
{!collaspe && (
|
||||
{expand && (
|
||||
<div className="settings">
|
||||
<AiOutlineSound className="icon" size={15} color="#1C1C1E" />
|
||||
<MdOutlineKeyboardVoice className="icon" size={15} color="#1C1C1E" />
|
||||
|
||||
@@ -5,12 +5,13 @@ import { HiChevronDoubleLeft } from "react-icons/hi";
|
||||
const StyledWrapper = styled.div`
|
||||
height: 56px;
|
||||
padding: 0 16px;
|
||||
padding-right: 5px;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
box-shadow: 0px 1px 0px rgba(0, 0, 0, 0.1);
|
||||
&.collaspe {
|
||||
padding-right: 5px;
|
||||
&.expand {
|
||||
padding-right: 16px;
|
||||
}
|
||||
.server {
|
||||
display: flex;
|
||||
@@ -44,26 +45,27 @@ const StyledWrapper = styled.div`
|
||||
display: flex;
|
||||
width: 15px;
|
||||
height: 15px;
|
||||
transform: rotate(180deg);
|
||||
.icon {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
&.collaspe {
|
||||
transform: rotate(180deg);
|
||||
&.expand {
|
||||
transform: rotate(0deg);
|
||||
}
|
||||
}
|
||||
`;
|
||||
export default function ServerDropList({ data, toggle, collaspe = false }) {
|
||||
export default function ServerDropList({ data, toggle, expand = true }) {
|
||||
if (!data) return null;
|
||||
return (
|
||||
<StyledWrapper className={collaspe ? "collaspe" : ""}>
|
||||
<StyledWrapper className={expand ? "expand" : ""}>
|
||||
<div className="server">
|
||||
<div className="logo">
|
||||
<img src={data.logo} alt="logo" />
|
||||
</div>
|
||||
{!collaspe && <h2 className="title">{data.name}</h2>}
|
||||
{expand && <h2 className="title">{data.name}</h2>}
|
||||
</div>
|
||||
<div onClick={toggle} className={`arrow ${collaspe ? "collaspe" : ""}`}>
|
||||
<div onClick={toggle} className={`arrow ${expand ? "expand" : ""}`}>
|
||||
<HiChevronDoubleLeft className="icon" color="#BFBFBF" />
|
||||
</div>
|
||||
</StyledWrapper>
|
||||
|
||||
@@ -60,7 +60,7 @@ const StyledWrapper = styled.div`
|
||||
}
|
||||
}
|
||||
`;
|
||||
export default function Tools({ collaspe = false }) {
|
||||
export default function Tools({ expand = true }) {
|
||||
return (
|
||||
<StyledWrapper>
|
||||
<hr />
|
||||
@@ -73,19 +73,19 @@ export default function Tools({ collaspe = false }) {
|
||||
alt="logo"
|
||||
/>
|
||||
</div>
|
||||
{!collaspe && <h2 className="title">Webrowse</h2>}
|
||||
{expand && <h2 className="title">Webrowse</h2>}
|
||||
</li>
|
||||
<li className="tool">
|
||||
<div className="logo">
|
||||
<IoLogoGithub size={40} className="icon" />
|
||||
</div>
|
||||
{!collaspe && <h2 className="title">Github</h2>}
|
||||
{expand && <h2 className="title">Github</h2>}
|
||||
</li>
|
||||
<li className="tool add">
|
||||
<div className="logo">
|
||||
<RiAddFill className="icon" size={40} color="#4B5563" />
|
||||
</div>
|
||||
{!collaspe && <h2 className="title">Add new app</h2>}
|
||||
{expand && <h2 className="title">Add new app</h2>}
|
||||
</li>
|
||||
</ul>
|
||||
</StyledWrapper>
|
||||
|
||||
+18
-13
@@ -1,7 +1,9 @@
|
||||
// import React from 'react';
|
||||
import { useState } from "react";
|
||||
import StyledWrapper from "./styled";
|
||||
// import { useState } from "react";
|
||||
import { Outlet, NavLink } from "react-router-dom";
|
||||
import { useSelector, useDispatch } from "react-redux";
|
||||
import { toggleMenuExpand } from "../../app/slices/ui";
|
||||
import StyledWrapper from "./styled";
|
||||
import ServerDropList from "./ServerDropList";
|
||||
import Tools from "./Tools";
|
||||
import usePreload from "./usePreload";
|
||||
@@ -13,33 +15,36 @@ import ContactIcon from "../../assets/icons/contact.svg";
|
||||
import NotificationHub from "../../common/component/NotificationHub";
|
||||
|
||||
export default function HomePage() {
|
||||
const dispatch = useDispatch();
|
||||
const { menuExpand, token } = useSelector((store) => {
|
||||
return { token: store.authData.token, menuExpand: store.ui.menuExpand };
|
||||
});
|
||||
const { data, error, success } = usePreload();
|
||||
const [collaspe, setCollaspe] = useState(false);
|
||||
const toggleCollaspe = () => {
|
||||
setCollaspe((prev) => !prev);
|
||||
const toggleExpand = () => {
|
||||
dispatch(toggleMenuExpand());
|
||||
};
|
||||
console.log({ data, error, success });
|
||||
return (
|
||||
<>
|
||||
<NotificationHub />
|
||||
<NotificationHub token={token} />
|
||||
<StyledWrapper>
|
||||
<div className={`col left ${collaspe ? "collaspe" : ""}`}>
|
||||
<div className={`col left ${menuExpand ? "expand" : ""}`}>
|
||||
<ServerDropList
|
||||
data={data?.server}
|
||||
collaspe={collaspe}
|
||||
toggle={toggleCollaspe}
|
||||
expand={menuExpand}
|
||||
toggle={toggleExpand}
|
||||
/>
|
||||
<nav className="nav">
|
||||
<NavLink className="link" to={"/chat"}>
|
||||
<img src={ChatIcon} alt="chat icon" /> {!collaspe && `Chat`}
|
||||
<img src={ChatIcon} alt="chat icon" /> {menuExpand && `Chat`}
|
||||
</NavLink>
|
||||
<NavLink className="link" to={"/contacts"}>
|
||||
<img src={ContactIcon} alt="contact icon" />{" "}
|
||||
{!collaspe && `Contacts`}
|
||||
{menuExpand && `Contacts`}
|
||||
</NavLink>
|
||||
</nav>
|
||||
<Tools collaspe={collaspe} />
|
||||
<CurrentUser collaspe={collaspe} />
|
||||
<Tools expand={menuExpand} />
|
||||
<CurrentUser expand={menuExpand} />
|
||||
</div>
|
||||
<div className="col right">
|
||||
<Outlet />
|
||||
|
||||
@@ -11,11 +11,11 @@ const StyledWrapper = styled.div`
|
||||
&.left {
|
||||
position: relative;
|
||||
/* background: #0891B2; */
|
||||
width: 180px;
|
||||
width: 64px;
|
||||
box-shadow: inset -1px 0px 0px rgba(0, 0, 0, 0.1);
|
||||
transition: all 0.5s ease-in;
|
||||
&.collaspe {
|
||||
width: 64px;
|
||||
&.expand {
|
||||
width: 180px;
|
||||
}
|
||||
}
|
||||
&.right {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// import React from 'react';
|
||||
import { useGetContactsQuery } from "../../app/services/contact";
|
||||
import { useGetChannelsQuery } from "../../app/services/channel";
|
||||
// import { useGetChannelsQuery } from "../../app/services/channel";
|
||||
import { useGetServerQuery } from "../../app/services/server";
|
||||
// pollingInterval: 0,
|
||||
const querySetting = {
|
||||
@@ -19,21 +19,20 @@ export default function usePreload() {
|
||||
isError: serverError,
|
||||
data: server,
|
||||
} = useGetServerQuery(undefined, querySetting);
|
||||
const {
|
||||
isLoading: groupsLoading,
|
||||
isSuccess: groupsSuccess,
|
||||
isError: groupsError,
|
||||
data: groups,
|
||||
} = useGetChannelsQuery(undefined, querySetting);
|
||||
// const {
|
||||
// isLoading: groupsLoading,
|
||||
// isSuccess: groupsSuccess,
|
||||
// isError: groupsError,
|
||||
// data: groups,
|
||||
// } = useGetChannelsQuery(undefined, querySetting);
|
||||
|
||||
return {
|
||||
loading: contactsLoading && groupsLoading && serverLoading,
|
||||
error: contactsError && groupsError && serverError,
|
||||
success: contactsSuccess && groupsSuccess && serverSuccess,
|
||||
loading: contactsLoading && serverLoading,
|
||||
error: contactsError && serverError,
|
||||
success: contactsSuccess && serverSuccess,
|
||||
data: {
|
||||
contacts,
|
||||
server,
|
||||
groups,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user