All files / apps/chatbot/src/components/Header index.tsx

100% Statements 15/15
83.33% Branches 5/6
100% Functions 5/5
100% Lines 12/12

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 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99                              1x 6x 6x 6x 6x 6x 6x 6x   6x 6x     6x                                                             6x                                                                              
import React from "react";
import { useSafeAreaInsets } from "react-native-safe-area-context";
import { Text, TouchableOpacity, View } from "react-native";
 
import { ArrowLeftIcon } from "@repo/ui/icons/ArrowLeft";
import { RotateCcwIcon } from "@repo/ui/icons/RotateCcw";
import { useTheme } from "@repo/ui/themes";
import { makeStyles } from "@repo/ui/themes/makeStyles";
import { textStyles } from "@repo/ui/themes/typography";
 
import { useStyles as useSharedStyles } from "@/components/styles";
 
import { useChatbotRuntime } from "@/contexts/ChatbotRuntimeContext";
import { useChatActionsSelector, useChatStateSelector } from "@/contexts/ChatContext";
 
export const Header = () => {
  const styles = useStyles();
  const shared = useSharedStyles();
  const { theme } = useTheme();
  const insets = useSafeAreaInsets();
  const { actions: runtimeActions } = useChatbotRuntime();
  const onReset = useChatActionsSelector((a) => a.onReset);
  const isInitializing = useChatStateSelector((s) => s.isInitializing);
 
  const handleContainerStyle = React.useMemo(() => {
    return [styles.handleContainer, { paddingTop: insets.top > 0 ? insets.top : 8 }];
  }, [styles.handleContainer, insets.top]);
 
  return (
    <View style={handleContainerStyle}>
      <View style={styles.header}>
        <View style={styles.leftGroup}>
          <TouchableOpacity
            onPress={runtimeActions.onClose}
            accessibilityRole="button"
            accessibilityLabel="Go back"
            style={styles.backButton}
          >
            <ArrowLeftIcon width={24} height={24} color={theme.colors.text.primary} />
          </TouchableOpacity>
          <Text style={styles.title}>Agility Flash</Text>
        </View>
        <View style={styles.iconGroup}>
          <TouchableOpacity
            onPress={onReset}
            disabled={isInitializing}
            style={[isInitializing && shared.disabledSendBtn]}
            accessibilityRole="button"
            accessibilityLabel="Reset conversation"
            accessibilityState={{ disabled: isInitializing }}
          >
            <RotateCcwIcon width={22} height={22} color={theme.colors.text.primary} />
          </TouchableOpacity>
        </View>
      </View>
    </View>
  );
};
 
const useStyles = makeStyles((theme) => ({
  header: {
    flexDirection: "row",
    justifyContent: "space-between",
    alignItems: "center",
    paddingHorizontal: 16,
    paddingBottom: 16,
    paddingTop: 4,
    backgroundColor: theme.colors.white,
    borderBottomWidth: 1,
    borderBottomColor: theme.isNewTheme ? theme.colors.border.subtle : theme.colors.border.divider,
    width: "100%",
  },
  handleContainer: {
    backgroundColor: theme.colors.white,
    paddingTop: 8,
    alignItems: "center",
  },
  title: {
    ...textStyles.content.semiBold,
    fontSize: 18,
    fontWeight: "bold",
    color: theme.colors.text.primary,
  },
  leftGroup: {
    flexDirection: "row",
    alignItems: "center",
  },
  backButton: {
    marginRight: 8,
    paddingVertical: 4,
    paddingRight: 4,
  },
  iconGroup: {
    flexDirection: "row",
    alignItems: "center",
    gap: 12,
  },
}));