Skip to content

Commit

Permalink
Update study-landing.tsx
Browse files Browse the repository at this point in the history
  • Loading branch information
divitcr7 authored Jul 26, 2024
1 parent eb00b6b commit 15d6ab9
Showing 1 changed file with 3 additions and 10 deletions.
13 changes: 3 additions & 10 deletions frontend/src/screens/study-landing.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Navigate, NavLink, useLoaderData } from 'react-router-dom'
import { React, useEffect, useState } from '@common'
import { React, useEffect } from '@common'
import { colors } from '@theme'
import { LearningPath, ParticipantStudy } from '@api'
import { Page } from '@components'
Expand Down Expand Up @@ -28,11 +28,8 @@ export default function StudyLanding() {
const env = useEnvironment()
const study = useLoaderData() as ParticipantStudy
const learningPathStudies = useLearningPathStudies(study?.learningPath)
const [notificationShown, setNotificationShown] = useState(false);

const showEarnedPointsNotification = (points: number) => {
if (notificationShown) return;

notifications.show({
title: `You just earned ${points} points!`,
message: 'The longer the study, the more points you earn. Reach 200 points to unlock additional rewards.',
Expand All @@ -43,26 +40,22 @@ export default function StudyLanding() {
description: { fontSize: '12px' },
}),
});

setNotificationShown(true);
};

useEffect(() => {
if (!notificationShown && study.totalPoints > 0) {
if (study.totalPoints > 0) {
const timer = setTimeout(() => {
showEarnedPointsNotification(study.totalPoints);
}, 100);

return () => clearTimeout(timer);
}
}, [notificationShown, study.totalPoints]);

}, [study.totalPoints]);

if (!study || !study.learningPath) {
return <Navigate to='/studies' />
}


return (
<Page hideFooter
data-analytics-view
Expand Down

0 comments on commit 15d6ab9

Please sign in to comment.