feat: lots updates

This commit is contained in:
zerosoul
2022-02-24 14:50:26 +08:00
parent b1ba2aa523
commit 0394c99292
46 changed files with 1101 additions and 397 deletions
+1 -8
View File
@@ -44,16 +44,10 @@ const channelMsgSlice = createSlice({
clearChannelMsgUnread(state, action) {
const gid = action.payload;
console.log("set channel all unread", gid);
Object.entries(state[gid]).forEach(([key, obj]) => {
Object.entries(state[gid]).forEach(([, obj]) => {
obj.unread = false;
});
},
setLastAccessTime(state, action) {
// let gid = action.payload;
// delete state[gid].lastAccess;
// const gid = action.payload;
// state.accessLogs[gid] = new Date().getTime();
},
addPendingMsg(state, action) {
state.pendingMsgs.push(action.payload);
},
@@ -66,7 +60,6 @@ const channelMsgSlice = createSlice({
},
});
export const {
setLastAccessTime,
clearChannelMsgUnread,
setChannelMsgRead,
addChannelMsg,
+29
View File
@@ -0,0 +1,29 @@
import { createSlice } from "@reduxjs/toolkit";
const initialState = {
user: {},
channel: {},
};
const pendingMessageSlice = createSlice({
name: "pendingMessage",
initialState,
reducers: {
addPendingMessage(state, action) {
const { type = "user", msg } = action.payload;
const { id, mid } = msg;
const curr = state[type][id] || {};
curr[mid] = { ...msg, pending: true };
state[type][id] = curr;
},
removePendingMessage(state, action) {
const { id, mid, type = "user" } = action.payload;
console.log("remove msg", type, id, mid);
delete state[type][id][mid];
},
},
});
export const {
addPendingMessage,
removePendingMessage,
} = pendingMessageSlice.actions;
export default pendingMessageSlice.reducer;
+6 -11
View File
@@ -28,16 +28,6 @@ const userMsgSlice = createSlice({
} else {
state[id][mid] = newMsg;
}
// let replaceIdx = state[id].findIndex((m) => m.mid == mid);
// if (replaceIdx > -1) {
// const copyMsg = { ...state[id][replaceIdx] };
// console.log("current user msg", copyMsg, newMsg);
// if (!isObjectEqual(copyMsg, newMsg)) {
// state[id][replaceIdx] = newMsg;
// }
// } else {
// state[id] = [...state[id], newMsg];
// }
} else {
state[id] = { [mid]: newMsg };
}
@@ -47,7 +37,12 @@ const userMsgSlice = createSlice({
console.log("set unread", id, mid);
state[id][mid].unread = false;
},
removeMsg(state, action) {
const { id, mid } = action.payload;
console.log("remove user msg", id, mid);
delete state[id][mid];
},
},
});
export const { addUserMsg, setUserMsgRead } = userMsgSlice.actions;
export const { addUserMsg, setUserMsgRead, removeMsg } = userMsgSlice.actions;
export default userMsgSlice.reducer;
+20 -1
View File
@@ -2,6 +2,9 @@ import { createSlice } from "@reduxjs/toolkit";
const initialState = {
menuExpand: true,
setting: false,
profileSetting: false,
channelSetting: null,
};
const uiSlice = createSlice({
name: "ui",
@@ -10,7 +13,23 @@ const uiSlice = createSlice({
toggleMenuExpand(state) {
state.menuExpand = !state.menuExpand;
},
toggleSetting(state) {
state.setting = !state.setting;
},
toggleProfileSetting(state) {
state.profileSetting = !state.profileSetting;
},
toggleChannelSetting(state, action) {
console.log("toggle channel setting payload", action);
const id = action.payload;
state.channelSetting = state.channelSetting ? null : id;
},
},
});
export const { toggleMenuExpand } = uiSlice.actions;
export const {
toggleSetting,
toggleMenuExpand,
toggleProfileSetting,
toggleChannelSetting,
} = uiSlice.actions;
export default uiSlice.reducer;