File size: 2,975 Bytes
9580dce
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
100
101
"use client";

import { CATEGORY_LABELS, CATEGORY_COLORS, type Category } from "@/config/xp";
import { Zap } from "lucide-react";
import { formatDistanceToNow } from "date-fns";

interface Activity {
  id: number;
  category: string;
  exerciseType: string;
  description: string | null;
  totalXp: number;
  isCriticalHit: boolean;
  createdAt: string;
}

interface ActivityFeedProps {
  activities: Activity[];
}

export function ActivityFeed({ activities }: ActivityFeedProps) {
  if (activities.length === 0) {
    return (
      <div
        className="text-center py-8 text-sm"
        style={{ color: "var(--text-muted)" }}
      >
        No activity yet — start training!
      </div>
    );
  }

  return (
    <div className="space-y-2">
      {activities.map((activity) => {
        const cat = activity.category as Category;
        const color = CATEGORY_COLORS[cat] ?? "#6b7280";
        const label = CATEGORY_LABELS[cat] ?? activity.category;
        const timeAgo = formatDistanceToNow(new Date(activity.createdAt), {
          addSuffix: true,
        });

        return (
          <div
            key={activity.id}
            className="flex items-center gap-3 rounded-lg px-3 py-2"
            style={{ background: "rgba(255,255,255,0.03)" }}
          >
            {/* Category dot */}
            <div
              className="w-2 h-2 rounded-full flex-shrink-0"
              style={{ background: color }}
            />

            {/* Content */}
            <div className="flex-1 min-w-0">
              <div className="flex items-center gap-2">
                <span
                  className="text-xs font-semibold"
                  style={{ color, whiteSpace: "nowrap" }}
                >
                  {label}
                </span>
                <span
                  className="text-xs truncate"
                  style={{ color: "var(--text-secondary)" }}
                >
                  {activity.exerciseType}
                  {activity.description ? ` — ${activity.description}` : ""}
                </span>
              </div>
              <span className="text-xs" style={{ color: "var(--text-muted)" }}>
                {timeAgo}
              </span>
            </div>

            {/* XP */}
            <div className="flex items-center gap-1 flex-shrink-0">
              {activity.isCriticalHit && (
                <Zap size={12} color="#f59e0b" fill="#f59e0b" />
              )}
              <span
                className="text-sm font-bold"
                style={{
                  fontFamily: "var(--font-mono)",
                  color: activity.isCriticalHit ? "#f59e0b" : "var(--text-primary)",
                }}
              >
                +{activity.totalXp}
              </span>
              <span className="text-xs" style={{ color: "var(--text-muted)" }}>
                XP
              </span>
            </div>
          </div>
        );
      })}
    </div>
  );
}