refactor(FE): Refactor tab actions store to use slice pattern

This commit is contained in:
rstubryan
2026-03-02 14:44:20 +07:00
parent f1ba577a97
commit 968243c370
2 changed files with 32 additions and 18 deletions
@@ -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 -18
View File
@@ -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',