refactor: setting page

This commit is contained in:
zerosoul
2022-04-15 13:18:03 +08:00
parent eb8717da8e
commit 19a4861819
9 changed files with 56 additions and 63 deletions
+17
View File
@@ -72,6 +72,21 @@ export const channelApi = createApi({
// }
// },
}),
createInviteLink: builder.query({
query: (gid) => ({
headers: {
"content-type": "text/plain",
accept: "text/plain",
},
url: `/group/${gid}/create_invite_link`,
responseHandler: (response) => response.text(),
}),
transformResponse: (link) => {
// 替换掉域名
const invite = new URL(link);
return `${location.origin}${invite.pathname}${invite.search}${invite.hash}`;
},
}),
removeChannel: builder.query({
query: (id) => ({
url: `group/${id}`,
@@ -126,6 +141,8 @@ export const channelApi = createApi({
});
export const {
useLazyCreateInviteLinkQuery,
useCreateInviteLinkQuery,
useLazyGetHistoryMessagesQuery,
useGetChannelQuery,
useUpdateChannelMutation,
+1 -13
View File
@@ -1,6 +1,6 @@
import { createApi } from "@reduxjs/toolkit/query/react";
import BASE_URL from "../config";
import { updateInviteLink, updateInfo } from "../slices/server";
import { updateInfo } from "../slices/server";
import baseQuery from "./base.query";
const defaultExpireDuration = 7 * 24 * 60 * 60;
export const serverApi = createApi({
@@ -108,18 +108,6 @@ export const serverApi = createApi({
const invite = new URL(link);
return `${location.origin}${invite.pathname}${invite.search}${invite.hash}`;
},
async onQueryStarted(
expire = defaultExpireDuration,
{ dispatch, queryFulfilled }
) {
try {
const { data: link } = await queryFulfilled;
console.log("link", link);
dispatch(updateInviteLink({ expire, link }));
} catch {
console.log("invite link error");
}
},
}),
updateServer: builder.mutation({
query: (data) => ({