mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-23 06:45:46 +00:00
refactor(FE): Refactor tab actions store to use a unified implementation
This commit is contained in:
@@ -1,21 +0,0 @@
|
||||
'use client';
|
||||
|
||||
import { create } from 'zustand';
|
||||
import { devtools } from 'zustand/middleware';
|
||||
import {
|
||||
createClosingTabSlice,
|
||||
ClosingTabSlice,
|
||||
} from '@/stores/closing/slices/closing-tab.slice';
|
||||
|
||||
export type ClosingTabStore = ClosingTabSlice;
|
||||
|
||||
export const useClosingTabStore = create<ClosingTabStore>()(
|
||||
devtools(
|
||||
(...args) => ({
|
||||
...createClosingTabSlice(...args),
|
||||
}),
|
||||
{
|
||||
name: 'ClosingTabStore',
|
||||
}
|
||||
)
|
||||
);
|
||||
@@ -1,37 +0,0 @@
|
||||
import { ReactNode } from 'react';
|
||||
import { StateCreator } from 'zustand';
|
||||
|
||||
export type ClosingTabSlice = {
|
||||
// State - actions per tab ID
|
||||
tabActions: Record<string, ReactNode>;
|
||||
|
||||
// Actions
|
||||
setTabActions: (tabId: string, actions: ReactNode) => void;
|
||||
clearTabActions: (tabId: string) => void;
|
||||
clearAllTabActions: () => void;
|
||||
};
|
||||
|
||||
export const createClosingTabSlice: StateCreator<
|
||||
ClosingTabSlice,
|
||||
[],
|
||||
[],
|
||||
ClosingTabSlice
|
||||
> = (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: {} }),
|
||||
});
|
||||
@@ -1,21 +0,0 @@
|
||||
'use client';
|
||||
|
||||
import { create } from 'zustand';
|
||||
import { devtools } from 'zustand/middleware';
|
||||
import {
|
||||
createReportTabSlice,
|
||||
ReportTabSlice,
|
||||
} from '@/stores/report/slices/report-tab.slice';
|
||||
|
||||
export type ReportTabStore = ReportTabSlice;
|
||||
|
||||
export const useReportTabStore = create<ReportTabStore>()(
|
||||
devtools(
|
||||
(...args) => ({
|
||||
...createReportTabSlice(...args),
|
||||
}),
|
||||
{
|
||||
name: 'ReportTabStore',
|
||||
}
|
||||
)
|
||||
);
|
||||
@@ -1,37 +0,0 @@
|
||||
import { ReactNode } from 'react';
|
||||
import { StateCreator } from 'zustand';
|
||||
|
||||
export type ReportTabSlice = {
|
||||
// State - actions per tab ID
|
||||
tabActions: Record<string, ReactNode>;
|
||||
|
||||
// Actions
|
||||
setTabActions: (tabId: string, actions: ReactNode) => void;
|
||||
clearTabActions: (tabId: string) => void;
|
||||
clearAllTabActions: () => void;
|
||||
};
|
||||
|
||||
export const createReportTabSlice: StateCreator<
|
||||
ReportTabSlice,
|
||||
[],
|
||||
[],
|
||||
ReportTabSlice
|
||||
> = (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: {} }),
|
||||
});
|
||||
@@ -0,0 +1,42 @@
|
||||
'use client';
|
||||
|
||||
import { create } from 'zustand';
|
||||
import { devtools } from 'zustand/middleware';
|
||||
import { ReactNode } from 'react';
|
||||
|
||||
export type TabActionsSlice = {
|
||||
// State - actions per tab ID
|
||||
tabActions: Record<string, ReactNode>;
|
||||
|
||||
// Actions
|
||||
setTabActions: (tabId: string, actions: ReactNode) => void;
|
||||
clearTabActions: (tabId: string) => void;
|
||||
clearAllTabActions: () => void;
|
||||
};
|
||||
|
||||
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: {} }),
|
||||
}),
|
||||
{
|
||||
name: 'TabActionsStore',
|
||||
}
|
||||
)
|
||||
);
|
||||
Reference in New Issue
Block a user