assistant-note/src/redux/tableBarItem_reducer.js

41 lines
1.4 KiB
JavaScript
Raw Normal View History

2024-02-02 01:40:28 -05:00
import { createSlice } from '@reduxjs/toolkit'
import {isEmpty} from "../utils/ObjectUtils";
2024-02-02 01:40:28 -05:00
export const tableBarItemSlice = createSlice({
name: 'tableBarItem',
initialState: {
type:"tableBarItem",
2024-02-03 20:29:00 -05:00
data: [],
activeKey:""
2024-02-02 01:40:28 -05:00
},
reducers: {
2024-02-03 20:29:00 -05:00
addTableBarItem: (state, action) => {
2024-02-03 22:08:49 -05:00
console.log("tableBarItemSlice:tableBarItem", state, action,)
2024-02-03 20:29:00 -05:00
if (state.data.filter(file=>file.key===action.payload.key).length===0){
state.data.push(action.payload)
}
if (action.payload.activeKey){
state.activeKey=action.payload.activeKey
}
2024-02-03 20:29:00 -05:00
},
2024-02-03 22:08:49 -05:00
removeTableBarItem: (state, action) => {
console.log("tableBarItemSlice:removeTableBarItem",action.payload)
state.data=state.data.filter(file=>file.key!==action.payload)
if (action.payload.activeKey){
state.activeKey=action.payload.activeKey
}
}
,
setActiveKey: (state, action) => {
2024-02-03 22:08:49 -05:00
console.log("tableBarItemSlice:setActiveKey",action.payload)
if (action.payload.activeKey){
state.activeKey=action.payload.activeKey
2024-02-03 20:29:00 -05:00
}
2024-02-02 01:40:28 -05:00
}
}
})
2024-02-03 22:08:49 -05:00
export const { addTableBarItem,
removeTableBarItem,
setActiveKey } = tableBarItemSlice.actions
2024-02-02 01:40:28 -05:00
export default tableBarItemSlice.reducer