eletrotupi / tcc/ frontend/components/history/TriggerCard.tsxa1a9079e3159130a372ea537b25611ee5d274ef9
2.2 KB | 72 lines Raw
1
import { View, StyleSheet } from "react-native";
2
import { Text } from '@/components/ui/Text';
3
import { MaterialIcons } from "@expo/vector-icons";
4
import { Card } from "@/components/ui/Cards";
5
import { Badge } from "@/components/ui/Badge";
6
import { HistoryCard } from "@/lib/history/types";
7
import { Trigger } from "@/lib/api";
8
import { Spacing } from "@/constants/theme";
9
import { router } from 'expo-router';
10
import { getTriggerCategory } from "@/constants/trigger-categories";
11

12
type Props = { card: HistoryCard & { raw: Trigger } };
13

14
export function TriggerHistoryCard({ card }: Props) {
15
  const meta = getTriggerCategory(card.raw.category);
16
  const time = new Date(card.timestamp).toLocaleTimeString("pt-BR", {
17
    hour: "2-digit",
18
    minute: "2-digit",
19
  });
20

21
  return (
22
    <Card style={styles.card} onPress={() => router.push(`/triggers/${card.raw.id}`) }>
23
      <View style={styles.row}>
24
        <View style={[styles.iconWrap, { backgroundColor: meta.iconBackground }]}>
25
          <MaterialIcons name={meta.icon} size={22} color={meta.color} />
26
        </View>
27
        <View style={styles.body}>
28
          <View style={styles.titleRow}>
29
            <Text style={styles.title}>Gatilho Identificado</Text>
30
            <Text style={styles.time}>{time}</Text>
31
          </View>
32
          {card.raw.comment ? (
33
            <Text style={styles.summary} numberOfLines={2}>
34
              {card.raw.comment}
35
            </Text>
36
          ) : null}
37
          <Badge
38
            label={meta.label}
39
            variant={meta.variant}
40
            style={styles.badge}
41
          />
42
        </View>
43
      </View>
44
    </Card>
45
  );
46
}
47

48
const styles = StyleSheet.create({
49
  card: {
50
    padding: Spacing.cardGap,
51
  },
52
  row: { flexDirection: "row", alignItems: "flex-start", gap: 12 },
53
  iconWrap: {
54
    width: 40,
55
    height: 40,
56
    borderRadius: 20,
57
    alignItems: "center",
58
    justifyContent: "center",
59
    marginTop: 1,
60
  },
61
  body: { flex: 1 },
62
  titleRow: {
63
    flexDirection: "row",
64
    justifyContent: "space-between",
65
    alignItems: "center",
66
    marginBottom: 2,
67
  },
68
  title: { fontSize: 15, fontWeight: "600" },
69
  time: { fontSize: 13, opacity: 0.45 },
70
  summary: { fontSize: 13, opacity: 0.6, lineHeight: 18, marginBottom: 6 },
71
  badge: { alignSelf: "flex-start", marginTop: 4 },
72
});