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

859 B

Online

// Create the online hook using the factory
const useContextOnline = createContextHook<ClientOnline>({
  endpoint: "/context/page/online",
  contextName: "online",
  enablePeriodicRefresh: true,
  refreshInterval: 5 * 60 * 1000, // 5 minutes
});

// Custom hook for online data with the expected interface
interface UseOnlineResult {
  onlineData: ClientOnline | null;
  isLoading: boolean;
  error: string | null;
  refreshOnline: () => Promise<void>;
  updateOnline: (newOnline: ClientOnline) => Promise<boolean>;
}

// Wrapper hook that adapts the generic hook to the expected interface
export function useOnline(): UseOnlineResult {
  const { data, isLoading, error, refresh, update } = useContextOnline();
  return {
    onlineData: data,
    isLoading,
    error,
    refreshOnline: refresh,
    updateOnline: update,
  };
}