fix: clear local data after reset msgs
This commit is contained in:
@@ -13,11 +13,14 @@ import { resetUsers } from "@/app/slices/users";
|
|||||||
export default function useLogout() {
|
export default function useLogout() {
|
||||||
const dispatch = useDispatch();
|
const dispatch = useDispatch();
|
||||||
const [logout, { isLoading, isSuccess }] = useLazyLogoutQuery();
|
const [logout, { isLoading, isSuccess }] = useLazyLogoutQuery();
|
||||||
const clearLocalData = () => {
|
const clearLocalData = (footprint?: boolean) => {
|
||||||
|
let fp = typeof footprint === "undefined" ? true : footprint;
|
||||||
dispatch(resetChannels());
|
dispatch(resetChannels());
|
||||||
dispatch(resetUsers());
|
dispatch(resetUsers());
|
||||||
// 和消息相关的数据
|
// 和消息相关的数据
|
||||||
dispatch(resetFootprint());
|
if (fp) {
|
||||||
|
dispatch(resetFootprint());
|
||||||
|
}
|
||||||
dispatch(resetChannelMsg());
|
dispatch(resetChannelMsg());
|
||||||
dispatch(resetUserMsg());
|
dispatch(resetUserMsg());
|
||||||
dispatch(resetMessage());
|
dispatch(resetMessage());
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import Modal from "@/components/Modal";
|
|||||||
import Button from "@/components/styled/Button";
|
import Button from "@/components/styled/Button";
|
||||||
import StyledModal from "@/components/styled/Modal";
|
import StyledModal from "@/components/styled/Modal";
|
||||||
import { VisibleModalType } from "./index";
|
import { VisibleModalType } from "./index";
|
||||||
|
import useLogout from "@/hooks/useLogout";
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
context: VisibleModalType;
|
context: VisibleModalType;
|
||||||
@@ -17,6 +18,7 @@ interface Props {
|
|||||||
|
|
||||||
const ClearConfirmModal: FC<Props> = ({ context, title, desc, closeModal }) => {
|
const ClearConfirmModal: FC<Props> = ({ context, title, desc, closeModal }) => {
|
||||||
// const { t } = useTranslation("auth");
|
// const { t } = useTranslation("auth");
|
||||||
|
const { clearLocalData } = useLogout();
|
||||||
const { t: ct } = useTranslation();
|
const { t: ct } = useTranslation();
|
||||||
const [clearFiles, { isLoading: filesClearing, isSuccess: clearFilesSuccess }] =
|
const [clearFiles, { isLoading: filesClearing, isSuccess: clearFilesSuccess }] =
|
||||||
useLazyClearAllFilesQuery();
|
useLazyClearAllFilesQuery();
|
||||||
@@ -42,6 +44,13 @@ const ClearConfirmModal: FC<Props> = ({ context, title, desc, closeModal }) => {
|
|||||||
closeModal();
|
closeModal();
|
||||||
}
|
}
|
||||||
}, [clearSuccess]);
|
}, [clearSuccess]);
|
||||||
|
// 即时清除本地数据
|
||||||
|
useEffect(() => {
|
||||||
|
if (clearMsgSuccess) {
|
||||||
|
clearLocalData(false);
|
||||||
|
}
|
||||||
|
}, [clearMsgSuccess]);
|
||||||
|
|
||||||
const clearing = msgClearing || filesClearing;
|
const clearing = msgClearing || filesClearing;
|
||||||
return (
|
return (
|
||||||
<Modal id="modal-modal">
|
<Modal id="modal-modal">
|
||||||
|
|||||||
Reference in New Issue
Block a user