Skip to content

Commit e67624b

Browse files
committed
chore: add jsdocs
1 parent 8935cf4 commit e67624b

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

package/src/components/AITypingIndicatorView/hooks/useAIState.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,20 @@ export const AIStates = {
1414
Thinking: 'AI_STATE_THINKING',
1515
};
1616

17+
/**
18+
* A hook that returns the current state of the AI.
19+
* @param {Channel} channel - The channel for which we want to know the AI state.
20+
* @returns {{ aiState: AIState }} The current AI state for the given channel.
21+
*/
1722
export const useAIState = <
1823
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
1924
>(
2025
channel?: Channel<StreamChatGenerics>,
21-
) => {
22-
const { client } = useChatContext();
26+
): { aiState: AIState } => {
27+
const { client } = useChatContext<StreamChatGenerics>();
28+
const { isOnline } = useIsOnline<StreamChatGenerics>(client);
29+
2330
const [aiState, setAiState] = useState<AIState>(AIStates.Idle);
24-
const { isOnline } = useIsOnline(client);
2531

2632
useEffect(() => {
2733
if (!isOnline) {

package/src/components/Message/hooks/useStreamingMessage.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,21 @@ export type UseStreamingMessageProps<
1313
const DEFAULT_LETTER_INTERVAL = 0;
1414
const DEFAULT_RENDERING_LETTER_COUNT = 2;
1515

16+
/**
17+
* A hook that returns text in a streamed, typewriter fashion. The speed of streaming is
18+
* configurable.
19+
* @param {number} [letterInterval=0] - The timeout between each typing animation in milliseconds.
20+
* @param {number} [renderingLetterCount=2] - The number of letters to be rendered each time we update.
21+
* @param {string} text - The text that we want to render in a typewriter fashion.
22+
* @returns {{ streamedMessageText: string }} - A substring of the text property, up until we've finished rendering the typewriter animation.
23+
*/
1624
export const useStreamingMessage = <
1725
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
1826
>({
1927
letterInterval = DEFAULT_LETTER_INTERVAL,
2028
renderingLetterCount = DEFAULT_RENDERING_LETTER_COUNT,
2129
text,
22-
}: UseStreamingMessageProps<StreamChatGenerics>) => {
30+
}: UseStreamingMessageProps<StreamChatGenerics>): { streamedMessageText: string } => {
2331
const [streamedMessageText, setStreamedMessageText] = useState<string>(text);
2432
const textCursor = useRef<number>(text.length);
2533

0 commit comments

Comments
 (0)