Skip to content

Commit

Permalink
Merge pull request #214 from hussaino03/dev
Browse files Browse the repository at this point in the history
preserve badge unlocks in server
  • Loading branch information
hussaino03 authored Jan 1, 2025
2 parents c8c7fd3 + b85a1d6 commit 7a34a07
Show file tree
Hide file tree
Showing 4 changed files with 262 additions and 109 deletions.
6 changes: 2 additions & 4 deletions client/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,7 @@ const AppContent = () => {
calculateXP,
setTasks,
setCompletedTasks,
setError,
badgeManager
setError
);

const themeManager = useMemo(() => new ThemeManager(setIsDark), []);
Expand Down Expand Up @@ -134,8 +133,7 @@ const AppContent = () => {
if (updatedBadges.length !== unlockedBadges.length) {
setUnlockedBadges(updatedBadges);
}
// eslint-disable-next-line
}, [level, currentStreak]);
}, [level, currentStreak, completedTasks, badgeManager, unlockedBadges]);

useEffect(() => {
const newStreakData = streakManager.calculateStreak(completedTasks);
Expand Down
12 changes: 9 additions & 3 deletions client/src/services/badge/BadgeManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,15 @@ class BadgeManager {
constructor(setUnlockedBadges, addNotification) {
this.setUnlockedBadges = setUnlockedBadges;
this.addNotification = addNotification;
this.notifiedBadges = new Set(
JSON.parse(localStorage.getItem('notifiedBadges') || '[]')
);

try {
this.notifiedBadges = new Set(
JSON.parse(localStorage.getItem('notifiedBadges') || '[]')
);
} catch (error) {
console.error('Failed to parse notified badges:', error);
this.notifiedBadges = new Set();
}

this.notifyNewBadge = this.notifyNewBadge.bind(this);
}
Expand Down
Loading

0 comments on commit 7a34a07

Please sign in to comment.