mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-20 13:32:00 +00:00
refactor(FE): Refactor tab actions store to use slice pattern
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
import { TabActionsSlice } from '@/stores/tab-actions/tab-actions.store';
|
||||
import { StateCreator } from 'zustand';
|
||||
|
||||
export const createTabActionsSlice: StateCreator<
|
||||
TabActionsSlice,
|
||||
[],
|
||||
[],
|
||||
TabActionsSlice
|
||||
> = (set) => ({
|
||||
// Initial state
|
||||
tabActions: {},
|
||||
|
||||
// Actions
|
||||
setTabActions: (tabId, actions) =>
|
||||
set((state) => ({
|
||||
tabActions: {
|
||||
...state.tabActions,
|
||||
[tabId]: actions,
|
||||
},
|
||||
})),
|
||||
|
||||
clearTabActions: (tabId) =>
|
||||
set((state) => {
|
||||
const { [tabId]: _, ...rest } = state.tabActions;
|
||||
return { tabActions: rest };
|
||||
}),
|
||||
|
||||
clearAllTabActions: () => set({ tabActions: {} }),
|
||||
});
|
||||
@@ -3,6 +3,7 @@
|
||||
import { create } from 'zustand';
|
||||
import { devtools } from 'zustand/middleware';
|
||||
import { ReactNode } from 'react';
|
||||
import { createTabActionsSlice } from '@/stores/tab-actions/slices/tab-actions.slice';
|
||||
|
||||
export type TabActionsSlice = {
|
||||
// State - actions per tab ID
|
||||
@@ -16,24 +17,8 @@ export type TabActionsSlice = {
|
||||
|
||||
export const useTabActionsStore = create<TabActionsSlice>()(
|
||||
devtools(
|
||||
(set) => ({
|
||||
tabActions: {},
|
||||
|
||||
setTabActions: (tabId, actions) =>
|
||||
set((state) => ({
|
||||
tabActions: {
|
||||
...state.tabActions,
|
||||
[tabId]: actions,
|
||||
},
|
||||
})),
|
||||
|
||||
clearTabActions: (tabId) =>
|
||||
set((state) => {
|
||||
const { [tabId]: _, ...rest } = state.tabActions;
|
||||
return { tabActions: rest };
|
||||
}),
|
||||
|
||||
clearAllTabActions: () => set({ tabActions: {} }),
|
||||
(...args) => ({
|
||||
...createTabActionsSlice(...args),
|
||||
}),
|
||||
{
|
||||
name: 'TabActionsStore',
|
||||
|
||||
Reference in New Issue
Block a user