refactor: app store and cache

This commit is contained in:
zerosoul
2022-03-18 16:30:38 +08:00
parent ad994f1eaf
commit 7bb8e9a914
26 changed files with 280 additions and 908 deletions
+27 -1
View File
@@ -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" }) => ({