This commit is contained in:
Desktop
2025-11-13 00:52:28 +05:00
parent 52dc95d66c
commit 235f01c1fe
2 changed files with 114 additions and 52 deletions

View File

@@ -0,0 +1,70 @@
/**
* Column Visibility Store (Zustand)
* Manages column visibility settings per page with localStorage persistence
* Uses the same pattern as siteStore and sectorStore
*/
import { create } from 'zustand';
import { persist } from 'zustand/middleware';
interface ColumnVisibilityState {
// Map of page pathname to Set of visible column keys
pageColumns: Record<string, string[]>;
// Actions
setPageColumns: (pathname: string, columnKeys: string[]) => void;
getPageColumns: (pathname: string) => string[];
toggleColumn: (pathname: string, columnKey: string) => void;
resetPageColumns: (pathname: string) => void;
}
export const useColumnVisibilityStore = create<ColumnVisibilityState>()(
persist<ColumnVisibilityState>(
(set, get) => ({
pageColumns: {},
setPageColumns: (pathname: string, columnKeys: string[]) => {
set((state) => ({
pageColumns: {
...state.pageColumns,
[pathname]: columnKeys,
},
}));
},
getPageColumns: (pathname: string) => {
return get().pageColumns[pathname] || [];
},
toggleColumn: (pathname: string, columnKey: string) => {
set((state) => {
const currentColumns = state.pageColumns[pathname] || [];
const newColumns = currentColumns.includes(columnKey)
? currentColumns.filter((key) => key !== columnKey)
: [...currentColumns, columnKey];
return {
pageColumns: {
...state.pageColumns,
[pathname]: newColumns,
},
};
});
},
resetPageColumns: (pathname: string) => {
set((state) => {
const newPageColumns = { ...state.pageColumns };
delete newPageColumns[pathname];
return { pageColumns: newPageColumns };
});
},
}),
{
name: 'igny8-column-visibility',
partialize: (state) => ({
pageColumns: state.pageColumns,
}),
}
)
);