feat: remeber navs
This commit is contained in:
@@ -1,9 +1,10 @@
|
||||
import { useState } from "react";
|
||||
import { useState, useEffect } from "react";
|
||||
import { useDebounce } from "rooks";
|
||||
import { useSelector } from "react-redux";
|
||||
import { useDispatch, useSelector } from "react-redux";
|
||||
import PinList from "./PinList";
|
||||
import FavList from "../FavList";
|
||||
import { useReadMessageMutation } from "../../../app/services/message";
|
||||
import { updateRemeberedNavs } from "../../../app/slices/ui";
|
||||
import useChatScroll from "../../../common/hook/useChatScroll";
|
||||
import ChannelIcon from "../../../common/component/ChannelIcon";
|
||||
import Tooltip from "../../../common/component/Tooltip";
|
||||
@@ -33,11 +34,11 @@ import Tippy from "@tippyjs/react";
|
||||
export default function ChannelChat({ cid = "", dropFiles = [] }) {
|
||||
const [toolVisible, setToolVisible] = useState("");
|
||||
const { pathname } = useLocation();
|
||||
const dispatch = useDispatch();
|
||||
const [updateReadIndex] = useReadMessageMutation();
|
||||
const updateReadDebounced = useDebounce(updateReadIndex, 300);
|
||||
const [membersVisible, setMembersVisible] = useState(true);
|
||||
const [addMemberModalVisible, setAddMemberModalVisible] = useState(false);
|
||||
// const dispatch = useDispatch();
|
||||
const {
|
||||
selects,
|
||||
msgIds,
|
||||
@@ -63,6 +64,13 @@ export default function ChannelChat({ cid = "", dropFiles = [] }) {
|
||||
// const handleClearUnreads = () => {
|
||||
// dispatch(readMessage(msgIds));
|
||||
// };
|
||||
useEffect(() => {
|
||||
dispatch(updateRemeberedNavs());
|
||||
return () => {
|
||||
dispatch(updateRemeberedNavs({ path: pathname }));
|
||||
};
|
||||
}, [pathname]);
|
||||
|
||||
const toggleMembersVisible = () => {
|
||||
setMembersVisible((prev) => !prev);
|
||||
};
|
||||
|
||||
@@ -1,17 +1,26 @@
|
||||
// import { useState, useEffect } from "react";
|
||||
import { NavLink, useParams } from "react-router-dom";
|
||||
import { useSelector } from "react-redux";
|
||||
import { useEffect } from "react";
|
||||
import { NavLink, useParams, useLocation } from "react-router-dom";
|
||||
import { useDispatch, useSelector } from "react-redux";
|
||||
import { updateRemeberedNavs } from "../../app/slices/ui";
|
||||
import Search from "../../common/component/Search";
|
||||
import Contact from "../../common/component/Contact";
|
||||
// import CurrentUser from "../../common/component/CurrentUser";
|
||||
import Profile from "../../common/component/Profile";
|
||||
|
||||
import StyledWrapper from "./styled";
|
||||
import BlankPlaceholder from "../../common/component/BlankPlaceholder";
|
||||
|
||||
export default function ContactsPage() {
|
||||
const dispatch = useDispatch();
|
||||
const { pathname } = useLocation();
|
||||
|
||||
const { user_id } = useParams();
|
||||
const contactIds = useSelector((store) => store.contacts.ids);
|
||||
useEffect(() => {
|
||||
dispatch(updateRemeberedNavs({ key: "contact" }));
|
||||
return () => {
|
||||
dispatch(updateRemeberedNavs({ key: "contact", path: pathname }));
|
||||
};
|
||||
}, [pathname]);
|
||||
|
||||
console.log({ contactIds, user_id });
|
||||
if (!contactIds) return null;
|
||||
|
||||
@@ -8,8 +8,10 @@ import User from "./User";
|
||||
import Loading from "./Loading";
|
||||
import Menu from "./Menu";
|
||||
import usePreload from "./usePreload";
|
||||
import usePWABadge from "../../common/hook/usePWABadge";
|
||||
import Tooltip from "../../common/component/Tooltip";
|
||||
import Notification from "../../common/component/Notification";
|
||||
import Manifest from "../../common/component/Manifest";
|
||||
|
||||
import ChatIcon from "../../assets/icons/chat.svg";
|
||||
import ContactIcon from "../../assets/icons/contact.svg";
|
||||
@@ -17,10 +19,14 @@ import FavIcon from "../../assets/icons/bookmark.svg";
|
||||
import FolderIcon from "../../assets/icons/folder.svg";
|
||||
// const routes = ["/setting", "/setting/channel/:cid"];
|
||||
export default function HomePage() {
|
||||
usePWABadge();
|
||||
const { pathname } = useLocation();
|
||||
const {
|
||||
loginUid,
|
||||
ui: { ready },
|
||||
ui: {
|
||||
ready,
|
||||
remeberedNavs: { chat: chatPath, contact: contactPath },
|
||||
},
|
||||
} = useSelector((store) => {
|
||||
return {
|
||||
ui: store.ui,
|
||||
@@ -41,19 +47,23 @@ export default function HomePage() {
|
||||
</>
|
||||
);
|
||||
}
|
||||
const chatNav = chatPath || "/chat";
|
||||
const contactNav = contactPath || "/contacts";
|
||||
|
||||
return (
|
||||
<>
|
||||
<Manifest />
|
||||
<Notification />
|
||||
<StyledWrapper>
|
||||
<div className={`col left`}>
|
||||
<User uid={loginUid} />
|
||||
<nav className="link_navs">
|
||||
<NavLink className="link" to={"/chat"}>
|
||||
<NavLink className="link" to={chatNav}>
|
||||
<Tooltip tip="Chat">
|
||||
<ChatIcon />
|
||||
</Tooltip>
|
||||
</NavLink>
|
||||
<NavLink className="link" to={"/contacts"}>
|
||||
<NavLink className="link" to={contactNav}>
|
||||
<Tooltip tip="Members">
|
||||
<ContactIcon />
|
||||
</Tooltip>
|
||||
|
||||
Reference in New Issue
Block a user