refactor: add more TS constraints

This commit is contained in:
Tristan Yang
2022-07-04 18:15:24 +08:00
parent 8330e45674
commit ff7fe05b58
18 changed files with 48 additions and 202 deletions
+1 -1
View File
@@ -4,7 +4,7 @@ import BASE_URL from "../config";
import { Channel, UpdateChannelDTO, UpdatePinnedMessageDTO } from "../../types/channel";
interface StoredChannel extends Channel {
icon: string;
icon?: string;
}
interface State {
+2 -4
View File
@@ -1,6 +1,4 @@
import { createSlice, PayloadAction } from "@reduxjs/toolkit";
import { EntityId } from "../../types/common";
import { ChatEvent } from "../../types/sse";
export interface State {
[gid: number]: number[] | undefined;
@@ -18,7 +16,7 @@ const channelMsgSlice = createSlice({
fullfillChannelMsg(state, action: PayloadAction<State>) {
return action.payload;
},
addChannelMsg(state, action: PayloadAction<ChatEvent>) {
addChannelMsg(state, action: PayloadAction<{ id: number; mid: number; local_id?: any }>) {
const { id, mid, local_id = null } = action.payload;
if (state[id]) {
const midExsited = state[id]!.findIndex((id) => id == mid) > -1;
@@ -29,7 +27,7 @@ const channelMsgSlice = createSlice({
state[id] = [+mid];
}
},
removeChannelMsg(state, action: PayloadAction<ChannelMessage & EntityId>) {
removeChannelMsg(state, action: PayloadAction<{ id: number; mid: number }>) {
const { id, mid } = action.payload;
if (state[id]) {
const idx = state[id]!.findIndex((i) => i == mid);
-15
View File
@@ -4,10 +4,6 @@ import { Views } from "../config";
export interface State {
online: boolean;
ready: boolean;
userGuide: {
visible: boolean;
step: number;
};
inputMode: "text";
menuExpand: boolean;
// todo
@@ -25,10 +21,6 @@ export interface State {
const initialState: State = {
online: true,
ready: false,
userGuide: {
visible: false,
step: 1
},
inputMode: "text",
menuExpand: false,
fileListView: Views.grid,
@@ -77,12 +69,6 @@ const uiSlice = createSlice({
const { key, value } = action.payload;
state.draftMixedText[key] = value;
},
updateUserGuide(state, action) {
const obj = action.payload || {};
Object.keys(obj).forEach((key) => {
state.userGuide[key] = obj[key];
});
},
updateUploadFiles(state, action) {
const { context = "channel", id = null, operation = "add", ...rest } = action.payload;
if (!id || !context) return;
@@ -177,7 +163,6 @@ export const {
updateFileListView,
updateUploadFiles,
updateSelectMessages,
updateUserGuide,
updateDraftMarkdown,
updateDraftMixedText,
updateRemeberedNavs