analytica-frontend-lib
Version:
Repositório público dos componentes utilizados nas plataformas da Analytica Ensino
76 lines • 2.18 kB
TypeScript
import type { ChatApiClient, ChatRoom, ChatRoomWithDetails, ChatUser } from '../types/chat';
/**
* Options for the useChatRooms hook
*/
export interface UseChatRoomsOptions {
apiClient: ChatApiClient;
}
/**
* Return type for the useChatRooms hook
*/
export interface UseChatRoomsReturn {
/** List of user's chat rooms */
rooms: ChatRoomWithDetails[];
/** Available users for creating new chat rooms */
availableUsers: ChatUser[];
/** Loading state */
loading: boolean;
/** Error state */
error: Error | null;
/** Fetch user's chat rooms */
fetchRooms: () => Promise<void>;
/** Fetch available users for chat */
fetchAvailableUsers: () => Promise<void>;
/** Create a new chat room */
createRoom: (participantIds: string[]) => Promise<ChatRoom | null>;
/** Clear error state */
clearError: () => void;
}
/**
* Hook for managing chat rooms via REST API
*
* Provides functionality to:
* - List user's chat rooms
* - Fetch available users for new chats
* - Create new chat rooms
*
* @param options - Hook configuration options
* @returns Chat rooms state and actions
*
* @example
* ```tsx
* const { rooms, fetchRooms, createRoom } = useChatRooms({ apiClient: api });
*
* useEffect(() => {
* fetchRooms();
* }, []);
*
* const handleCreateRoom = async (userIds: string[]) => {
* const room = await createRoom(userIds);
* if (room) {
* // Navigate to the new room
* }
* };
* ```
*/
export declare function useChatRooms({ apiClient, }: UseChatRoomsOptions): UseChatRoomsReturn;
/**
* Factory function to create a pre-configured useChatRooms hook
*
* @param apiClient - API client instance
* @returns Pre-configured hook function
*
* @example
* ```tsx
* // In your app setup
* import { createUseChatRooms } from 'analytica-frontend-lib';
* import api from './services/api';
*
* export const useChatRooms = createUseChatRooms(api);
*
* // Then use directly in components
* const { rooms, fetchRooms } = useChatRooms();
* ```
*/
export declare function createUseChatRooms(apiClient: ChatApiClient): () => UseChatRoomsReturn;
//# sourceMappingURL=useChatRooms.d.ts.map