Skip to content

Commit

Permalink
Fix: Update featured quest logic to prioritize recent quests
Browse files Browse the repository at this point in the history
  • Loading branch information
Stepcu committed Jan 24, 2025
1 parent cf1a679 commit 82db127
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions context/QuestsProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -130,19 +130,27 @@ export const QuestsContextProvider = ({

useMemo(() => {
if (!quests.length) return;

const notExpired = quests.filter((quest) => !quest.expired);
const lastBoostedQuest = boostedQuests.length
? quests.find(
(quest) =>
quest.id === boostedQuests[boostedQuests.length - 1] &&
!quest.expired
)
: undefined;
? quests.find(
(quest) =>
quest.id === boostedQuests[boostedQuests.length - 1] &&
!quest.expired
)
: undefined;

const recentQuest = notExpired.find(
(quest) =>
new Date(quest.start_timestamp) >= new Date(Date.now() - 7 * 24 * 60 * 60 * 1000) // Check if less than a week ago
);

setFeaturedQuest(
lastBoostedQuest ||
lastBoostedQuest ||
recentQuest ||
notExpired[Math.floor(Math.random() * notExpired.length)]
);
}, [quests, boostedQuests]);
}, [quests, boostedQuests]);

const contextValues = useMemo(() => {
return {
Expand Down

0 comments on commit 82db127

Please sign in to comment.