feat: refactor the cache

This commit is contained in:
zerosoul
2022-03-04 10:15:30 +08:00
parent b6b0a0c5ef
commit acd007fb71
28 changed files with 622 additions and 341 deletions
+2 -2
View File
@@ -27,9 +27,9 @@ export default function ChannelChat({
const dispatch = useDispatch();
const { msgs, users, pendingMsgs } = useSelector((store) => {
return {
msgs: store.channelMsg[cid] || {},
msgs: store.channelMessage[cid] || {},
users: store.contacts,
pendingMsgs: store.pendingMsg.channel[cid] || {},
pendingMsgs: store.pendingMessage.channel[cid] || {},
};
});
const handleClearUnreads = () => {
+4 -4
View File
@@ -13,8 +13,8 @@ export default function DMChat({ uid = "", dropFiles = [] }) {
const contacts = useSelector((store) => store.contacts);
const { msgs, pendingMsgs } = useSelector((store) => {
return {
msgs: store.userMsg[uid] || {},
pendingMsgs: store.pendingMsg.user[uid] || {},
msgs: store.userMessage[uid] || {},
pendingMsgs: store.pendingMessage.user[uid] || {},
};
});
const [currUser, setCurrUser] = useState(null);
@@ -31,7 +31,7 @@ export default function DMChat({ uid = "", dropFiles = [] }) {
}, [dropFiles]);
if (!currUser) return null;
console.log("user msgs", msgs);
// console.log("user msgs", msgs);
return (
<Layout
setDragFiles={setDragFiles}
@@ -75,7 +75,7 @@ export default function DMChat({ uid = "", dropFiles = [] }) {
})
.map(([mid, msg]) => {
if (!msg) return null;
console.log("user msg", msg);
// console.log("user msg", msg);
const {
from_uid,
content,
+10 -8
View File
@@ -20,17 +20,19 @@ import DMList from "./DMList";
export default function ChatPage() {
const [channelDropFiles, setChannelDropFiles] = useState([]);
const [userDropFiles, setUserDropFiles] = useState([]);
const { channels, UserMsgData, ChannelMsgData } = useSelector((store) => {
return {
channels: store.channels,
UserMsgData: store.userMsg,
ChannelMsgData: store.channelMsg,
};
});
const { contacts, channels, UserMsgData, ChannelMsgData } = useSelector(
(store) => {
return {
contacts: store.contacts,
channels: store.channels,
UserMsgData: store.userMessage,
ChannelMsgData: store.channelMessage,
};
}
);
const [channelModalVisible, setChannelModalVisible] = useState(false);
const [contactsModalVisible, setContactsModalVisible] = useState(false);
const { channel_id, user_id } = useParams();
const contacts = useSelector((store) => store.contacts);
const toggleContactsModalVisible = () => {
setContactsModalVisible((prev) => !prev);
};