UNPKG

@cossistant/next

Version:

Next.js-ready SDK for building AI-powered support/chat widgets. Hooks + primitives, WS-driven, TypeScript-first. Next.js-ready, Tailwind optional.

80 lines 2.35 kB
//#region ../react/src/hooks/use-home-page.d.ts type UseHomePageOptions = { /** * Whether to enable conversations fetching. * Default: true */ enabled?: boolean; /** * Callback when user wants to start a new conversation. */ onStartConversation?: (initialMessage?: string) => void; /** * Callback when user wants to open an existing conversation. */ onOpenConversation?: (conversationId: string) => void; /** * Callback when user wants to view conversation history. */ onOpenConversationHistory?: () => void; }; type UseHomePageReturn = { conversations: Conversation[]; isLoading: boolean; error: Error | null; lastOpenConversation: Conversation | undefined; availableConversationsCount: number; hasConversations: boolean; startConversation: (initialMessage?: string) => void; openConversation: (conversationId: string) => void; openConversationHistory: () => void; }; /** * Main hook for the home page of the support widget. * * This hook: * - Fetches and manages conversations list * - Derives useful state (last open conversation, conversation counts) * - Provides navigation actions for the home page * * It encapsulates all home page logic, making the component * purely presentational. * * @example * ```tsx * export function HomePage() { * const home = useHomePage({ * onStartConversation: (msg) => { * navigate('conversation', { conversationId: PENDING_CONVERSATION_ID, initialMessage: msg }); * }, * onOpenConversation: (id) => { * navigate('conversation', { conversationId: id }); * }, * onOpenConversationHistory: () => { * navigate('conversation-history'); * }, * }); * * return ( * <> * <h1>How can we help?</h1> * * {home.lastOpenConversation && ( * <ConversationCard * conversation={home.lastOpenConversation} * onClick={() => home.openConversation(home.lastOpenConversation.id)} * /> * )} * * <Button onClick={() => home.startConversation()}> * Ask a question * </Button> * </> * ); * } * ``` */ declare function useHomePage(options?: UseHomePageOptions): UseHomePageReturn; //#endregion export { UseHomePageOptions, UseHomePageReturn, useHomePage }; //# sourceMappingURL=use-home-page.d.ts.map