Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 23 additions & 4 deletions src/components/gamification/BadgeDisplay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { useState } from "react";
import { Badge } from "@/types";
import {
BADGE_TEMPLATES,
BadgeRequirement,
RARITY_COLORS,
RARITY_LABELS,
getBadgeTemplate,
Expand All @@ -24,6 +25,27 @@ interface BadgeCardProps {
onClick?: () => void;
}

function getBadgeRequirementDescription(requirement: BadgeRequirement): string {
switch (requirement.type) {
case "total_reduction":
return `Reduce your ${requirement.period} COβ‚‚ footprint by ${requirement.threshold}%`;
case "streak_days":
return `Log activities for ${requirement.threshold} consecutive days`;
case "milestone":
return `Complete ${requirement.threshold} day${
requirement.threshold > 1 ? "s" : ""
} of tracking`;
case "activity_limit":
return `Keep ${requirement.activity} under ${requirement.threshold} ${requirement.period}`;
case "tips_applied":
return `Apply ${requirement.threshold} eco-friendly tips`;
case "consistency":
return `Maintain consistent eco-friendly activity tracking`;
default:
return "Complete the requirement to unlock this badge";
}
}

function BadgeCard({ badge, isEarned, onClick }: BadgeCardProps) {
const template = getBadgeTemplate(badge.id);
const rarity = template?.rarity || "common";
Expand Down Expand Up @@ -56,10 +78,7 @@ function BadgeCard({ badge, isEarned, onClick }: BadgeCardProps) {
</svg>

<span className="text-white ">
This badge is earned by achieving a total COβ‚‚ reduction of at least{" "}
{" "}
{badge.requirement.threshold}% over a {badge.requirement.period}{" "}
period.
{getBadgeRequirementDescription(badge.requirement)}
</span>
</div>
}
Expand Down