Files
lti-web-client/src/stores/closing/slices/closing-tab.slice.ts
T

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: {} }),
});