-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ticket-88 #384
Ticket-88 #384
Changes from 5 commits
8b75467
ded819b
a1913a5
79a1baf
c1a2a20
eb00b6b
15d6ab9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import { Navigate, NavLink, useLoaderData } from 'react-router-dom' | ||
import { React } from '@common' | ||
import { React, useEffect } from '@common' | ||
import { colors } from '@theme' | ||
import { LearningPath, ParticipantStudy } from '@api' | ||
import { Page } from '@components' | ||
|
@@ -18,20 +18,59 @@ import { | |
Text, | ||
Title, | ||
} from '@mantine/core'; | ||
import { IconCheck } from '@tabler/icons-react' | ||
import Markdown from 'react-markdown' | ||
import { useLearningPathStudies } from './learner/studies'; | ||
import { CompactStudyCard } from '../components/study/compact-study-card'; | ||
import { notifications } from '@mantine/notifications'; | ||
|
||
let notificationShownThisSession = false; | ||
|
||
export default function StudyLanding() { | ||
const env = useEnvironment() | ||
|
||
const study = useLoaderData() as ParticipantStudy | ||
const learningPathStudies = useLearningPathStudies(study?.learningPath) | ||
|
||
const showEarnedPointsNotification = (points: number) => { | ||
if (notificationShownThisSession) 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.', | ||
icon: <IconCheck size="1.1rem" />, | ||
color: 'teal', | ||
autoClose: 5000, | ||
styles: () => ({ | ||
description: { fontSize: '12px' }, | ||
}), | ||
}); | ||
|
||
notificationShownThisSession = true; | ||
}; | ||
|
||
useEffect(() => { | ||
if (study.totalPoints > 0) { | ||
// Delay to ensure it runs after any potential double renders | ||
const timer = setTimeout(() => { | ||
showEarnedPointsNotification(study.totalPoints); | ||
}, 100); | ||
|
||
return () => clearTimeout(timer); | ||
} | ||
}, [study.totalPoints]); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what happens if you remove There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this could be just a side effect of react rendering components twice in dev mode |
||
|
||
// Reset the flag when the component unmounts | ||
useEffect(() => { | ||
return () => { | ||
notificationShownThisSession = false; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove this RE: above comment |
||
}; | ||
}, []); | ||
|
||
if (!study || !study.learningPath) { | ||
return <Navigate to='/studies' /> | ||
} | ||
|
||
|
||
return ( | ||
<Page hideFooter | ||
data-analytics-view | ||
|
@@ -44,6 +83,7 @@ export default function StudyLanding() { | |
<LearningPathProgress learningPath={study.learningPath} studies={learningPathStudies} /> | ||
} | ||
</Card> | ||
|
||
</Page> | ||
) | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I dont think we should be doing it this way - we don't want to be modifying a variable outside of the component state.