feat: refactor the cache

This commit is contained in:
zerosoul
2022-03-04 10:15:30 +08:00
parent b6b0a0c5ef
commit acd007fb71
28 changed files with 622 additions and 341 deletions
+5 -10
View File
@@ -1,5 +1,4 @@
import { createApi } from "@reduxjs/toolkit/query/react";
import { REHYDRATE } from "redux-persist";
import toast from "react-hot-toast";
import baseQuery from "./base.query";
import { ContentTypes } from "../config";
@@ -12,11 +11,6 @@ import {
export const channelApi = createApi({
reducerPath: "channel",
baseQuery,
extractRehydrationInfo(action, { reducerPath }) {
if (action.type === REHYDRATE) {
return action.payload ? action.payload[reducerPath] : undefined;
}
},
refetchOnFocus: true,
endpoints: (builder) => ({
getChannels: builder.query({
@@ -84,11 +78,12 @@ export const channelApi = createApi({
};
dispatch(addPendingMessage({ type: "channel", msg: tmpMsg }));
try {
const {
data: { gid, ...rest },
} = await queryFulfilled;
const { data: server_mid } = await queryFulfilled;
console.log("channel server mid", server_mid);
// 此处的id,是指给谁发的
dispatch(addChannelMsg({ id: gid, ...rest, unread: false }));
dispatch(
addChannelMsg({ ...tmpMsg, mid: server_mid, unread: false })
);
dispatch(removePendingMessage({ id, mid, type: "channel" }));
} catch {
console.log("channel message send failed");