112
This commit is contained in:
@@ -2,9 +2,11 @@
|
||||
* Column Visibility Store (Zustand)
|
||||
* Manages column visibility settings per page with localStorage persistence
|
||||
* Uses the same pattern as siteStore and sectorStore
|
||||
* Stores preferences per user for multi-user support
|
||||
*/
|
||||
import { create } from 'zustand';
|
||||
import { persist } from 'zustand/middleware';
|
||||
import { persist, createJSONStorage, StateStorage } from 'zustand/middleware';
|
||||
import { useAuthStore } from './authStore';
|
||||
|
||||
interface ColumnVisibilityState {
|
||||
// Map of page pathname to Set of visible column keys
|
||||
@@ -17,6 +19,29 @@ interface ColumnVisibilityState {
|
||||
resetPageColumns: (pathname: string) => void;
|
||||
}
|
||||
|
||||
// Custom storage that uses user-specific keys
|
||||
const userSpecificStorage: StateStorage = {
|
||||
getItem: (name: string) => {
|
||||
const user = useAuthStore.getState().user;
|
||||
const userId = user?.id || 'anonymous';
|
||||
const key = `igny8-column-visibility-user-${userId}`;
|
||||
const value = localStorage.getItem(key);
|
||||
return value;
|
||||
},
|
||||
setItem: (name: string, value: string) => {
|
||||
const user = useAuthStore.getState().user;
|
||||
const userId = user?.id || 'anonymous';
|
||||
const key = `igny8-column-visibility-user-${userId}`;
|
||||
localStorage.setItem(key, value);
|
||||
},
|
||||
removeItem: (name: string) => {
|
||||
const user = useAuthStore.getState().user;
|
||||
const userId = user?.id || 'anonymous';
|
||||
const key = `igny8-column-visibility-user-${userId}`;
|
||||
localStorage.removeItem(key);
|
||||
},
|
||||
};
|
||||
|
||||
export const useColumnVisibilityStore = create<ColumnVisibilityState>()(
|
||||
persist<ColumnVisibilityState>(
|
||||
(set, get) => ({
|
||||
@@ -61,6 +86,7 @@ export const useColumnVisibilityStore = create<ColumnVisibilityState>()(
|
||||
}),
|
||||
{
|
||||
name: 'igny8-column-visibility',
|
||||
storage: createJSONStorage(() => userSpecificStorage),
|
||||
partialize: (state) => ({
|
||||
pageColumns: state.pageColumns,
|
||||
}),
|
||||
|
||||
Reference in New Issue
Block a user