mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-20 13:32:00 +00:00
43 lines
974 B
TypeScript
43 lines
974 B
TypeScript
'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',
|
|
}
|
|
)
|
|
);
|