Skip to content

Commit

Permalink
Merge pull request #212 from hussaino03/dev
Browse files Browse the repository at this point in the history
preserve badge unlocks in server
  • Loading branch information
hussaino03 authored Dec 31, 2024
2 parents dea78c1 + 7e10483 commit c12a2f8
Show file tree
Hide file tree
Showing 11 changed files with 998 additions and 952 deletions.
23 changes: 15 additions & 8 deletions client/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,18 @@ const AppContent = () => {
resetXP
});

const { addNotification } = useNotification();
const badgeManager = useMemo(
() => new BadgeManager(setUnlockedBadges, addNotification),
[addNotification]
);

const taskManager = new TaskManager(
calculateXP,
setTasks,
setCompletedTasks,
setError
setError,
badgeManager
);

const themeManager = useMemo(() => new ThemeManager(setIsDark), []);
Expand All @@ -86,11 +93,6 @@ const AppContent = () => {
() => new ViewManager(setShowCompleted, setCurrentView),
[]
);
const { addNotification } = useNotification();
const badgeManager = useMemo(
() => new BadgeManager(setUnlockedBadges, addNotification),
[addNotification]
);
const collaborationManager = useMemo(
() => new CollaborationManager(setTasks, setError),
[]
Expand Down Expand Up @@ -122,13 +124,17 @@ const AppContent = () => {
}, [userId, tasks, completedTasks, experience, level, unlockedBadges]); // eslint-disable-line react-hooks/exhaustive-deps

useEffect(() => {
badgeManager.checkAndUpdateBadges(
const updatedBadges = badgeManager.checkForNewBadges(
level,
currentStreak,
completedTasks,
unlockedBadges
);
}, [level, currentStreak, completedTasks, unlockedBadges, badgeManager]);

if (updatedBadges.length !== unlockedBadges.length) {
setUnlockedBadges(updatedBadges);
}
}, [level, currentStreak]);

useEffect(() => {
const newStreakData = streakManager.calculateStreak(completedTasks);
Expand Down Expand Up @@ -188,6 +194,7 @@ const AppContent = () => {
};

const handleConfirmClear = async () => {
badgeManager.clearNotificationHistory();
await dataManager.clearAllData(userId);
setShowClearDataModal(false);
};
Expand Down
Loading

0 comments on commit c12a2f8

Please sign in to comment.