fix: delete channel and remove remembered navs

This commit is contained in:
zerosoul
2022-05-24 23:12:55 +08:00
parent 1f6bfa1629
commit d649c46c21
2 changed files with 13 additions and 4 deletions
+10 -1
View File
@@ -3,6 +3,7 @@ import { createApi } from "@reduxjs/toolkit/query/react";
import baseQuery from "./base.query";
import BASE_URL, { ContentTypes } from "../config";
import { updateChannel, removeChannel } from "../slices/channels";
import { updateRemeberedNavs } from "../slices/ui";
import { removeMessage } from "../slices/message";
import { removeChannelSession } from "../slices/message.channel";
import { removeReactionMessage } from "../slices/message.reaction";
@@ -104,11 +105,19 @@ export const channelApi = createApi({
method: "DELETE",
}),
async onQueryStarted(id, { dispatch, getState, queryFulfilled }) {
const { channelMessage } = getState();
const {
channelMessage,
ui: {
remeberedNavs: { chat: remeberedPath },
},
} = getState();
try {
await queryFulfilled;
// 删掉该channel下的所有消息&reaction
const mids = channelMessage[id];
if (remeberedPath == `/chat/channel/${id}`) {
dispatch(updateRemeberedNavs({ path: null }));
}
if (mids) {
dispatch(removeChannelSession(id));
dispatch(removeMessage(mids));
@@ -1,7 +1,7 @@
// import React from "react";
import { useEffect } from "react";
import toast from "react-hot-toast";
import { useNavigate, useMatch } from "react-router-dom";
import { useNavigate } from "react-router-dom";
import Modal from "../../common/component/Modal";
import { useLazyRemoveChannelQuery } from "../../app/services/channel";
import StyledModal from "../../common/component/styled/Modal";
@@ -9,7 +9,7 @@ import Button from "../../common/component/styled/Button";
export default function DeleteConfirmModal({ id, closeModal }) {
const navigateTo = useNavigate();
const pathMatched = useMatch(`/chat/channel/${id}`);
// const pathMatched = useMatch(`/chat/channel/${id}`);
const [deleteChannel, { isLoading, isSuccess }] = useLazyRemoveChannelQuery();
const handleDelete = () => {
deleteChannel(id);
@@ -20,7 +20,7 @@ export default function DeleteConfirmModal({ id, closeModal }) {
closeModal();
navigateTo("/chat");
}
}, [isSuccess, id, pathMatched]);
}, [isSuccess]);
if (!id) return null;
return (
<Modal id="modal-modal">