refactor: archive message

This commit is contained in:
Tristan Yang
2023-03-16 09:28:17 +08:00
parent 02f02709c1
commit 75df1f93c9
11 changed files with 119 additions and 35 deletions
+35
View File
@@ -0,0 +1,35 @@
import { createSlice, PayloadAction } from "@reduxjs/toolkit";
// import { ContentTypes } from "../config";
// import { normalizeFileMessage } from "../../common/utils";
// import { ContentType } from "../../types/message";
import { Archive } from "../../types/resource";
export interface State {
[key: string]: Archive;
}
const initialState: State = {
};
const messageArchiveSlice = createSlice({
name: "archiveMessage",
initialState,
reducers: {
resetArchiveMessage() {
return initialState;
},
fillArchiveMessage(state, action) {
return Object.assign({ ...initialState }, action.payload);
},
upsertArchiveMessage(state, action: PayloadAction<{ filePath: string, data: Archive }>) {
const { filePath, data } = action.payload;
state[filePath] = data;
},
}
});
export const {
resetArchiveMessage,
fillArchiveMessage,
upsertArchiveMessage
} = messageArchiveSlice.actions;
export default messageArchiveSlice.reducer;