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

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

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

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

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