refactor: more TS code
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user