refactor: more TS code

This commit is contained in:
Tristan Yang
2022-07-08 22:30:06 +08:00
parent 9f1b115c73
commit c7eae47fb2
11 changed files with 33 additions and 80 deletions
+5 -5
View File
@@ -19,14 +19,14 @@ const userMsgSlice = createSlice({
return initialState;
},
fillUserMsg(state, action: PayloadAction<{ [id: number]: any }>) {
state.ids = Object.keys(action.payload);
state.ids = Object.keys(action.payload).map((k) => +k);
state.byId = action.payload;
},
addUserMsg(state, action: PayloadAction<{ id: number; mid: number; local_id: number }>) {
const { id, mid, local_id } = action.payload;
if (state.byId[id]) {
const midExisted = state.byId[id].findIndex((id) => id == mid) > -1;
const localMsgExisted = state.byId[id].findIndex((id) => id == local_id) > -1;
const midExisted = state.byId[id].findIndex((id: number) => id == mid) > -1;
const localMsgExisted = state.byId[id].findIndex((id: number) => id == local_id) > -1;
if (midExisted || localMsgExisted) return;
state.byId[id].push(+mid);
// 只要有新消息,就检查下
@@ -41,7 +41,7 @@ const userMsgSlice = createSlice({
removeUserMsg(state, action) {
const { id, mid } = action.payload;
if (state.byId[id]) {
const idx = state.byId[id].findIndex((i) => i == mid);
const idx = state.byId[id].findIndex((i: number) => i == mid);
if (idx > -1) {
// 存在 则再删除
state.byId[id].splice(idx, 1);
@@ -51,7 +51,7 @@ const userMsgSlice = createSlice({
replaceUserMsg(state, action) {
const { id, localMid, serverMid } = action.payload;
if (state.byId[id]) {
const localIdx = state.byId[id].findIndex((i) => i == localMid);
const localIdx = state.byId[id].findIndex((i: number) => i == localMid);
if (localIdx > -1 && serverMid) {
// 存在 则再删除
state.byId[id].splice(localIdx, 1, serverMid);
+1 -1
View File
@@ -45,7 +45,7 @@ const uiSlice = createSlice({
setReady(state) {
state.ready = true;
},
updateOnline(state, action) {
updateOnline(state, action: PayloadAction<boolean>) {
state.online = action.payload;
},
toggleMenuExpand(state) {