@adventurelabs/scout-core
Version:
Core utilities and helpers for Adventure Labs Scout applications
168 lines (167 loc) • 5.01 kB
TypeScript
import { SupabaseClient } from "@supabase/supabase-js";
import { useInfiniteSessionsByHerd, useInfiniteEventsByHerd, useInfiniteArtifactsByHerd } from "./useInfiniteQuery";
import { IHerdModule } from "../types/herd_module";
import { ISessionSummary } from "../types/db";
interface UseHerdDataOptions {
sessionsLimit?: number;
eventsLimit?: number;
artifactsLimit?: number;
enableSessions?: boolean;
enableEvents?: boolean;
enableArtifacts?: boolean;
supabase: SupabaseClient;
}
interface UseHerdDataReturn {
herdModule: IHerdModule | undefined;
herd: IHerdModule["herd"] | undefined;
devices: IHerdModule["devices"];
zones: IHerdModule["zones"];
plans: IHerdModule["plans"];
layers: IHerdModule["layers"];
providers: IHerdModule["providers"];
labels: IHerdModule["labels"];
userRoles: IHerdModule["user_roles"];
sessionSummaries: ISessionSummary | null;
timestampLastRefreshed: number | null;
sessions: {
items: ReturnType<typeof useInfiniteSessionsByHerd>["items"];
isLoading: boolean;
isLoadingMore: boolean;
hasMore: boolean;
loadMore: () => void;
refetch: () => void;
error: any;
};
events: {
items: ReturnType<typeof useInfiniteEventsByHerd>["items"];
isLoading: boolean;
isLoadingMore: boolean;
hasMore: boolean;
loadMore: () => void;
refetch: () => void;
error: any;
};
artifacts: {
items: ReturnType<typeof useInfiniteArtifactsByHerd>["items"];
isLoading: boolean;
isLoadingMore: boolean;
hasMore: boolean;
loadMore: () => void;
refetch: () => void;
error: any;
};
isInitialLoading: boolean;
hasAnyError: boolean;
}
/**
* Comprehensive hook for accessing herd data from both global store and RTK Query
*
* @param herdId - The herd ID to fetch data for
* @param options - Configuration options for data fetching
* @returns Complete herd data with both structural and paginated content
*
* @example
* ```tsx
* const {
* herd,
* devices,
* events,
* sessions,
* artifacts,
* sessionSummaries
* } = useHerdData(123, {
* supabase,
* eventsLimit: 20,
* enableSessions: true
* });
*
* // Use structural data from global store
* console.log(herd.name, devices.length);
*
* // Use paginated data from RTK Query
* console.log(events.items.length, events.hasMore);
* if (events.hasMore) {
* events.loadMore();
* }
*
* // Use session summaries
* console.log(sessionSummaries?.total_sessions, sessionSummaries?.total_distance_meters);
* ```
*/
export declare const useHerdData: (herdId: number, options: UseHerdDataOptions) => UseHerdDataReturn;
/**
* Hook for getting just the structural herd data from global store
* Useful when you only need basic herd info without paginated content
*/
export declare const useHerdStructure: (herdId: number) => {
herdModule: IHerdModule | undefined;
herd: {
created_by: string;
description: string;
earthranger_domain: string | null;
earthranger_token: string | null;
id: number;
inserted_at: string;
is_public: boolean;
slug: string;
video_publisher_token: string | null;
video_server_url: string | null;
video_subscriber_token: string | null;
} | undefined;
devices: import("../types/db").IDevice[];
zones: import("../types/db").IZoneWithActions[];
plans: {
herd_id: number;
id: number;
inserted_at: string | null;
instructions: string;
name: string;
plan_type: import("..").Database["public"]["Enums"]["plan_type"];
}[];
layers: {
created_at: string;
features: import("..").Json;
herd_id: number;
id: number;
}[];
providers: {
created_at: string;
herd_id: number;
id: number;
key: string | null;
source: string;
type: string;
}[];
labels: string[];
userRoles: import("../types/db").IUserAndRole[] | null;
sessionSummaries: ISessionSummary | null;
timestampLastRefreshed: number | null;
};
/**
* Hook for getting all herd structures (without paginated data)
* Useful for dashboard/overview components
*/
export declare const useAllHerds: () => {
herdModules: IHerdModule[];
herds: {
created_by: string;
description: string;
earthranger_domain: string | null;
earthranger_token: string | null;
id: number;
inserted_at: string;
is_public: boolean;
slug: string;
video_publisher_token: string | null;
video_server_url: string | null;
video_subscriber_token: string | null;
}[];
totalHerds: number;
totalDevices: number;
sessionSummaries: {
herdId: number;
herdSlug: string;
summaries: ISessionSummary | null;
}[];
};
export {};