refactor: app store and cache
This commit is contained in:
@@ -2,7 +2,11 @@ import { createApi } from "@reduxjs/toolkit/query/react";
|
||||
// import toast from "react-hot-toast";
|
||||
import baseQuery from "./base.query";
|
||||
import { ContentTypes } from "../config";
|
||||
import { updateChannel } from "../slices/channels";
|
||||
import { updateChannel, removeChannel } from "../slices/channels";
|
||||
import { removeMessage } from "../slices/message";
|
||||
import { removeChannelSession } from "../slices/message.channel";
|
||||
import { removeReactionMessage } from "../slices/message.reaction";
|
||||
import { toggleChannelSetting } from "../slices/ui";
|
||||
import { onMessageSendStarted } from "./handlers";
|
||||
export const channelApi = createApi({
|
||||
reducerPath: "channelApi",
|
||||
@@ -47,6 +51,28 @@ export const channelApi = createApi({
|
||||
url: `group/${id}`,
|
||||
method: "DELETE",
|
||||
}),
|
||||
async onQueryStarted(id, { dispatch, getState, queryFulfilled }) {
|
||||
const {
|
||||
ui: { channelSetting },
|
||||
channelMessage,
|
||||
} = getState();
|
||||
try {
|
||||
await queryFulfilled;
|
||||
dispatch(removeChannel(id));
|
||||
if (id == channelSetting) {
|
||||
dispatch(toggleChannelSetting());
|
||||
}
|
||||
// 删掉该channel下的所有消息&reaction
|
||||
const mids = channelMessage[id];
|
||||
if (mids) {
|
||||
dispatch(removeChannelSession(id));
|
||||
dispatch(removeMessage(mids));
|
||||
dispatch(removeReactionMessage(mids));
|
||||
}
|
||||
} catch {
|
||||
console.log("remove channel error");
|
||||
}
|
||||
},
|
||||
}),
|
||||
sendChannelMsg: builder.mutation({
|
||||
query: ({ id, content, type = "text" }) => ({
|
||||
|
||||
Reference in New Issue
Block a user