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