feat: remove session realtime

This commit is contained in:
Tristan Yang
2023-03-17 21:00:17 +08:00
parent f11c758938
commit 5bf4baabd3
4 changed files with 31 additions and 6 deletions
+11 -3
View File
@@ -1,7 +1,9 @@
import { useState, useEffect, memo } from "react";
import { useLocation } from "react-router-dom";
import { useLocation, useNavigate } from "react-router-dom";
import Tippy from "@tippyjs/react";
import { useTranslation } from "react-i18next";
import { useDispatch } from "react-redux";
import PinList from "./PinList";
import FavList from "../FavList";
import { updateRememberedNavs } from "../../../app/slices/ui";
@@ -11,9 +13,7 @@ import Layout from "../Layout";
import IconFav from "../../../assets/icons/bookmark.svg";
import IconPeople from "../../../assets/icons/people.svg";
import IconPin from "../../../assets/icons/pin.svg";
import { useAppSelector } from "../../../app/store";
import { useTranslation } from "react-i18next";
import GoBackNav from "../../../common/component/GoBackNav";
import Members from "./Members";
type Props = {
@@ -23,6 +23,7 @@ type Props = {
function ChannelChat({ cid = 0, dropFiles = [] }: Props) {
const { t } = useTranslation("chat");
const { pathname } = useLocation();
const navigate = useNavigate();
const dispatch = useDispatch();
const [membersVisible, setMembersVisible] = useState(true);
@@ -37,6 +38,12 @@ function ChannelChat({ cid = 0, dropFiles = [] }: Props) {
data: store.channels.byId[cid],
};
});
useEffect(() => {
if (!data) {
// channel不存在了 回首页
navigate("/chat");
}
}, [data]);
useEffect(() => {
dispatch(updateRememberedNavs());
return () => {
@@ -48,6 +55,7 @@ function ChannelChat({ cid = 0, dropFiles = [] }: Props) {
setMembersVisible((prev) => !prev);
};
if (!data) return null;
const { name, description, is_public, members = [], owner } = data;
const memberIds = is_public ? userIds : members.slice(0).sort((n) => (n == owner ? -1 : 0));
+9 -1
View File
@@ -1,4 +1,5 @@
import { FC } from "react";
import { FC, useEffect } from "react";
import { useNavigate } from "react-router-dom";
import Tippy from "@tippyjs/react";
import FavList from "../FavList";
import Tooltip from "../../../common/component/Tooltip";
@@ -12,11 +13,18 @@ type Props = {
dropFiles?: File[];
};
const DMChat: FC<Props> = ({ uid = 0, dropFiles }) => {
const navigate = useNavigate();
const { currUser } = useAppSelector((store) => {
return {
currUser: store.users.byId[uid],
};
});
useEffect(() => {
if (!currUser) {
// user不存在了 回首页
navigate("/chat");
}
}, [currUser]);
if (!currUser) return null;
return (
<Layout