Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions hooks/useMessageLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ import { UIMessage } from "ai";
import getChatMessages from "@/lib/messages/getChatMessages";

/**
* Hook for loading existing messages from a room
* Hook for loading existing messages from a room via the chats API (Bearer auth).
* @param roomId - The room ID to load messages from (undefined to skip loading)
* @param userId - The current user ID (messages won't load if user is not authenticated)
* @param accessToken - Privy access token for the API request
* @param apiOverride - Optional API base URL override (e.g. preview)
* @param setMessages - Callback function to set the loaded messages
* @returns Loading state and error information
*/
Comment on lines 5 to 12
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion | 🟠 Major

Add @returns documentation to complete the JSDoc.

The JSDoc is missing documentation for the return value. The hook returns an object with isLoading, error, and hasError properties that consumers need to understand.

📝 Proposed documentation addition
 /**
  * Hook for loading existing messages from a room via the chats API (Bearer auth).
  * `@param` roomId - The room ID to load messages from (undefined to skip loading)
  * `@param` userId - The current user ID (messages won't load if user is not authenticated)
  * `@param` accessToken - Privy access token for the API request
  * `@param` apiOverride - Optional API base URL override (e.g. preview)
  * `@param` setMessages - Callback function to set the loaded messages
+ * `@returns` Object containing loading state, error state, and error flag
  */

As per coding guidelines: "For custom hooks, ensure: Return consistent interface" - documenting the return value helps maintain clarity about the hook's consistent interface.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
/**
* Hook for loading existing messages from a room
* Hook for loading existing messages from a room via the chats API (Bearer auth).
* @param roomId - The room ID to load messages from (undefined to skip loading)
* @param userId - The current user ID (messages won't load if user is not authenticated)
* @param accessToken - Privy access token for the API request
* @param apiOverride - Optional API base URL override (e.g. preview)
* @param setMessages - Callback function to set the loaded messages
* @returns Loading state and error information
*/
/**
* Hook for loading existing messages from a room via the chats API (Bearer auth).
* `@param` roomId - The room ID to load messages from (undefined to skip loading)
* `@param` userId - The current user ID (messages won't load if user is not authenticated)
* `@param` accessToken - Privy access token for the API request
* `@param` apiOverride - Optional API base URL override (e.g. preview)
* `@param` setMessages - Callback function to set the loaded messages
* `@returns` Object containing loading state, error state, and error flag
*/
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@hooks/useMessageLoader.ts` around lines 5 - 12, Add a `@returns` block to the
JSDoc for the useMessageLoader hook that documents the returned object shape:
include descriptions for isLoading (boolean indicating loading state), error
(Error | null for any fetch error), and hasError (boolean derived from error) so
consumers understand the hook's consistent interface; update the JSDoc above the
useMessageLoader function to explicitly list each property and its type/meaning.

export function useMessageLoader(
roomId: string | undefined,
Expand Down
Loading