mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-23 23:05:46 +00:00
38 lines
834 B
TypeScript
38 lines
834 B
TypeScript
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: {} }),
|
|
});
|