|
| 1 | +# Enhancement: Add Contribution Streaks to User Profiles |
| 2 | + |
| 3 | +## 🎯 Overview |
| 4 | + |
| 5 | +Add GitHub-style contribution streak tracking to individual contributor profile pages, showing both current and longest streaks to gamify and motivate consistent contributions. |
| 6 | + |
| 7 | +## 💡 Motivation |
| 8 | + |
| 9 | +Contribution streaks are a proven engagement mechanism (popularized by GitHub's contribution graph). They: |
| 10 | + |
| 11 | +- **Motivate consistency**: Encourages daily/regular contributions |
| 12 | +- **Provide recognition**: Highlights dedicated contributors |
| 13 | +- **Add gamification**: Makes contributing more engaging |
| 14 | +- **Show commitment**: Helps identify highly active community members |
| 15 | + |
| 16 | +## ✨ Proposed Feature |
| 17 | + |
| 18 | +### Current Streak 🔥 |
| 19 | + |
| 20 | +- Tracks **consecutive days** with at least one contribution |
| 21 | +- Displays with fire emoji (🔥) |
| 22 | +- Shows subtle pulse animation when active |
| 23 | +- Resets when a day is missed |
| 24 | + |
| 25 | +### Longest Streak 🏆 |
| 26 | + |
| 27 | +- Tracks **all-time best** consecutive contribution streak |
| 28 | +- Displays with trophy emoji (🏆) |
| 29 | +- Serves as a personal record/achievement |
| 30 | + |
| 31 | +### Visual Design |
| 32 | + |
| 33 | +``` |
| 34 | +┌─────────────────────────┐ |
| 35 | +│ 👤 User Card │ |
| 36 | +│ 69 Points | 34 Acts │ |
| 37 | +│ 🔥 0 Days (Current) │ ← Animated pulse |
| 38 | +│ 🏆 22 Days (Best) │ |
| 39 | +└─────────────────────────┘ |
| 40 | +``` |
| 41 | + |
| 42 | +## 🛠️ Technical Implementation |
| 43 | + |
| 44 | +### Backend Changes (`lib/db.ts`) |
| 45 | + |
| 46 | +```typescript |
| 47 | +// Add streak calculation helper |
| 48 | +function calculateStreaks(dailyActivity: DailyActivity[]) { |
| 49 | + let currentStreak = 0; |
| 50 | + let longestStreak = 0; |
| 51 | + let tempStreak = 0; |
| 52 | + |
| 53 | + const sortedDays = dailyActivity |
| 54 | + .filter((d) => d.count > 0) |
| 55 | + .sort((a, b) => new Date(b.date).getTime() - new Date(a.date).getTime()); |
| 56 | + |
| 57 | + // Calculate current streak |
| 58 | + const today = new Date(); |
| 59 | + today.setHours(0, 0, 0, 0); |
| 60 | + |
| 61 | + for (let i = 0; i < sortedDays.length; i++) { |
| 62 | + const dayDate = new Date(sortedDays[i].date); |
| 63 | + dayDate.setHours(0, 0, 0, 0); |
| 64 | + |
| 65 | + const expectedDate = new Date(today); |
| 66 | + expectedDate.setDate(today.getDate() - i); |
| 67 | + |
| 68 | + if (dayDate.getTime() === expectedDate.getTime()) { |
| 69 | + currentStreak++; |
| 70 | + } else { |
| 71 | + break; |
| 72 | + } |
| 73 | + } |
| 74 | + |
| 75 | + // Calculate longest streak |
| 76 | + // ... (similar logic for all-time longest) |
| 77 | + |
| 78 | + return { current: currentStreak, longest: longestStreak }; |
| 79 | +} |
| 80 | + |
| 81 | +// Update getContributorProfile |
| 82 | +export async function getContributorProfile(username: string) { |
| 83 | + // ... existing code ... |
| 84 | + |
| 85 | + const streaks = calculateStreaks(dailyActivity); |
| 86 | + |
| 87 | + return { |
| 88 | + // ... existing fields ... |
| 89 | + stats: { |
| 90 | + // ... existing stats ... |
| 91 | + currentStreak: streaks.current, |
| 92 | + longestStreak: streaks.longest, |
| 93 | + }, |
| 94 | + }; |
| 95 | +} |
| 96 | +``` |
| 97 | + |
| 98 | +### Frontend Changes (`app/[username]/page.tsx`) |
| 99 | + |
| 100 | +```tsx |
| 101 | +// Display streaks in user card |
| 102 | +<div className="flex items-center gap-2"> |
| 103 | + <span className={currentStreak > 0 ? "animate-pulse-slow" : ""}> |
| 104 | + 🔥 {currentStreak} Days |
| 105 | + </span> |
| 106 | + <span className="text-muted-foreground text-sm">Current</span> |
| 107 | +</div> |
| 108 | + |
| 109 | +<div className="flex items-center gap-2"> |
| 110 | + <span>🏆 {longestStreak} Days</span> |
| 111 | + <span className="text-muted-foreground text-sm">Best</span> |
| 112 | +</div> |
| 113 | +``` |
| 114 | + |
| 115 | +### Styling (`app/globals.css`) |
| 116 | + |
| 117 | +```css |
| 118 | +@keyframes pulse-slow { |
| 119 | + 0%, |
| 120 | + 100% { |
| 121 | + opacity: 1; |
| 122 | + } |
| 123 | + 50% { |
| 124 | + opacity: 0.7; |
| 125 | + } |
| 126 | +} |
| 127 | + |
| 128 | +.animate-pulse-slow { |
| 129 | + animation: pulse-slow 2s cubic-bezier(0.4, 0, 0.6, 1) infinite; |
| 130 | +} |
| 131 | +``` |
| 132 | + |
| 133 | +## 📸 Screenshots |
| 134 | + |
| 135 | +_(Will add after approval)_ |
| 136 | + |
| 137 | +## ✅ Acceptance Criteria |
| 138 | + |
| 139 | +- [ ] Current streak calculates correctly (consecutive days) |
| 140 | +- [ ] Longest streak tracks all-time best |
| 141 | +- [ ] Streak resets properly when days are missed |
| 142 | +- [ ] Animation works on active streaks |
| 143 | +- [ ] No TypeScript errors |
| 144 | +- [ ] Null-safe date handling |
| 145 | +- [ ] Works in both Light/Dark mode |
| 146 | +- [ ] Responsive on mobile |
| 147 | + |
| 148 | +## 🧪 Testing Plan |
| 149 | + |
| 150 | +### Manual Tests |
| 151 | + |
| 152 | +1. User with active streak (today + yesterday) |
| 153 | +2. User with broken streak (gap in contributions) |
| 154 | +3. User with no contributions |
| 155 | +4. User with longest streak in the past |
| 156 | + |
| 157 | +### Edge Cases |
| 158 | + |
| 159 | +- Timezone handling |
| 160 | +- Leap years |
| 161 | +- Month boundaries |
| 162 | +- New users (no history) |
| 163 | + |
| 164 | +## 📝 Implementation Notes |
| 165 | + |
| 166 | +- Uses existing `dailyActivity` data (no new API calls) |
| 167 | +- Purely additive (no breaking changes) |
| 168 | +- Backward compatible with current JSON format |
| 169 | +- Performance: O(n) where n = days in activity history |
| 170 | + |
| 171 | +## 🔗 Related |
| 172 | + |
| 173 | +- Part of Profile Enhancement series |
| 174 | +- Builds on PR #26 by @Supreeth-C |
| 175 | +- Inspired by GitHub's contribution streak |
| 176 | + |
| 177 | +--- |
| 178 | + |
| 179 | +**Ready to implement!** This will be submitted as a focused PR once approved. |
| 180 | + |
| 181 | +cc: @Naman-Chhabra @Aboobacker-MK @Supreeth-C |
0 commit comments