All files / apps/chatbot/src/components/MessageList/blocks TextBlock.tsx

100% Statements 10/10
85.71% Branches 12/14
100% Functions 2/2
100% Lines 7/7

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40                              2x 5x 5x   5x 4x   2x                       5x          
import React from "react";
import { Text, View } from "react-native";
 
import { makeStyles } from "@repo/ui/themes/makeStyles";
 
import { BouncingDots } from "@/components/Indicators/BouncingDots";
import { ShimmerText } from "@/components/Indicators/ShimmerText";
import { useStyles as useSharedStyles } from "@/components/styles";
 
import { Block } from "@/types/chat";
 
/**
 * A text block that has no text yet but is still streaming is the agent
 * "thinking" — it gets the shimmer instead of an empty bubble.
 */
export const TextBlock = ({ block }: { block: Block }) => {
  const shared = useSharedStyles();
  const styles = useStyles();
 
  if (!block.text && !block.isStreaming) return null;
  if (block.isStreaming && !block.text?.trim()) return <ShimmerText />;
 
  return (
    <View>
      {block.text ? <Text style={shared.blockText}>{block.text}</Text> : null}
      {block.isStreaming && (
        <View style={block.text ? styles.streamingDotsContainer : null}>
          <BouncingDots />
        </View>
      )}
    </View>
  );
};
 
const useStyles = makeStyles(() => ({
  streamingDotsContainer: {
    marginTop: 8,
  },
}));