refactor: more TS code

This commit is contained in:
Tristan Yang
2022-07-04 23:13:09 +08:00
parent 627082eacb
commit e0872b1dd3
28 changed files with 56 additions and 126 deletions
+5 -5
View File
@@ -3,7 +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 { updateRememberedNavs } from "../slices/ui";
import { removeMessage } from "../slices/message";
import { removeChannelSession } from "../slices/message.channel";
import { removeReactionMessage } from "../slices/message.reaction";
@@ -72,8 +72,8 @@ export const channelApi = createApi({
}
}
}),
createInviteLink: builder.query({
query: (gid = "") => ({
createInviteLink: builder.query<string, number | void>({
query: (gid) => ({
headers: {
"content-type": "text/plain",
accept: "text/plain"
@@ -98,7 +98,7 @@ export const channelApi = createApi({
const {
channelMessage,
ui: {
remeberedNavs: { chat: remeberedPath }
rememberedNavs: { chat: remeberedPath }
}
} = getState() as RootState;
try {
@@ -106,7 +106,7 @@ export const channelApi = createApi({
// 删掉该channel下的所有消息&reaction
const mids = channelMessage[id];
if (remeberedPath == `/chat/channel/${id}`) {
dispatch(updateRemeberedNavs({ path: null }));
dispatch(updateRememberedNavs({ path: null }));
}
if (mids) {
dispatch(removeChannelSession(id));
+5 -5
View File
@@ -12,7 +12,7 @@ export interface State {
selectMessages: { [key: string]: any };
draftMarkdown: { [key: string]: any };
draftMixedText: { [key: string]: any };
remeberedNavs: {
rememberedNavs: {
chat: null | string;
user: null | string;
};
@@ -29,7 +29,7 @@ const initialState: State = {
draftMarkdown: {},
draftMixedText: {},
// todo: typo
remeberedNavs: {
rememberedNavs: {
chat: null,
user: null
}
@@ -57,9 +57,9 @@ const uiSlice = createSlice({
updateFileListView(state, action) {
state.fileListView = action.payload;
},
updateRemeberedNavs(state, action: PayloadAction<{ key?: string; path: string | null }>) {
updateRememberedNavs(state, action: PayloadAction<{ key?: string; path: string | null }>) {
const { key = "chat", path = null } = action.payload || {};
state.remeberedNavs[key] = path;
state.rememberedNavs[key] = path;
},
updateDraftMarkdown(state, action) {
const { key, value } = action.payload;
@@ -165,7 +165,7 @@ export const {
updateSelectMessages,
updateDraftMarkdown,
updateDraftMixedText,
updateRemeberedNavs
updateRememberedNavs
} = uiSlice.actions;
export default uiSlice.reducer;