Skip to content

Commit 6527d72

Browse files
committed
chore: add JSDocs as well
1 parent a023f17 commit 6527d72

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

src/components/AIStateIndicator/hooks/useAIState.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,16 @@ export const AIStates = {
1212
Thinking: 'AI_STATE_THINKING',
1313
};
1414

15+
/**
16+
* A hook that returns the current state of the AI.
17+
* @param {Channel} channel - The channel for which we want to know the AI state.
18+
* @returns {{ aiState: AIState }} The current AI state for the given channel.
19+
*/
1520
export const useAIState = <
1621
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics
1722
>(
1823
channel?: Channel<StreamChatGenerics>,
19-
) => {
24+
): { aiState: AIState } => {
2025
const [aiState, setAiState] = useState<AIState>(AIStates.Idle);
2126

2227
useEffect(() => {

src/components/Message/hooks/useMessageTextStreaming.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,21 @@ export type UseMessageTextStreamingProps<
1313
const DEFAULT_LETTER_INTERVAL = 30;
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} [streamingLetterIntervalMs=30] - 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 useMessageTextStreaming = <
1725
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics
1826
>({
1927
streamingLetterIntervalMs = DEFAULT_LETTER_INTERVAL,
2028
renderingLetterCount = DEFAULT_RENDERING_LETTER_COUNT,
2129
text,
22-
}: UseMessageTextStreamingProps<StreamChatGenerics>) => {
30+
}: UseMessageTextStreamingProps<StreamChatGenerics>): { streamedMessageText: string } => {
2331
const [streamedMessageText, setStreamedMessageText] = useState<string>(text);
2432
const textCursor = useRef<number>(text.length);
2533

0 commit comments

Comments
 (0)