production-evyos-systems-an.../docs/frontDocs/contexts/component_menu.md

1.0 KiB

Menu

Syncs each step of left menu actions with redis backend.

// Create the menu hook using the factory
const useContextMenu = createContextHook<ClientMenu>({
  endpoint: "/context/page/menu",
  contextName: "menu",
  extractAvailableItems: (data) => data.selectionList || [],
  enablePeriodicRefresh: false,
});

// Custom hook for menu data with the expected interface
interface UseMenuResult {
  menuData: ClientMenu | null;
  availableApplications: string[];
  isLoading: boolean;
  error: string | null;
  refreshMenu: () => Promise<void>;
  updateMenu: (newMenu: ClientMenu) => Promise<boolean>;
}

// Wrapper hook that adapts the generic hook to the expected interface
export function useMenu(): UseMenuResult {
  const { data, availableItems, isLoading, error, refresh, update } =
    useContextMenu();

  return {
    menuData: data,
    availableApplications: availableItems,
    isLoading,
    error,
    refreshMenu: refresh,
    updateMenu: update,
  };
}

export { checkContextPageMenu, setContextPageMenu };