Skip to content

Commit

Permalink
added more events
Browse files Browse the repository at this point in the history
  • Loading branch information
Bahugunajii committed Jan 5, 2024
1 parent b2507cb commit ce934f7
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions app/library/show/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,27 +95,27 @@ const ContentLibrary = () => {
}, [selectedGrade, page, selectedChapter]);


const handleChapterClick = async (chapterId: number) => {
const handleChapterClick = async (chapterId: number, chapterName: string) => {
try {
const topicData = await getTopics([chapterId]);
setTopics(topicData);
const topicIds = topicData.map((topic) => topic.id);
const resourceData = await getResourcesWithSource(topicIds);
setResources(resourceData);
MixpanelTracking.getInstance().trackEvent('Selected chapter: ' + chapterId);
MixpanelTracking.getInstance().trackEvent('Selected chapter: ' + chapterName);
} catch (error) {
console.error('Error fetching chapter data:', error);
}
};

const toggleChapterExpansion = async (chapterId: number) => {
const toggleChapterExpansion = async (chapterId: number, chapterName: string) => {
setExpandedChapters((prevExpanded) => ({
...prevExpanded,
[chapterId]: !prevExpanded[chapterId],
}));

if (!expandedChapters[chapterId]) {
await handleChapterClick(chapterId);
await handleChapterClick(chapterId, chapterName);
}
};

Expand All @@ -134,6 +134,10 @@ const ContentLibrary = () => {
setChapterList(chapterData);
};

const handleResourceTracking = (resourceName: any) => {
MixpanelTracking.getInstance().trackEvent('Selected resource: '+ resourceName)
}

const generateSubjectButton = (subject: string, label: string) => (
<PrimaryButton
key={subject}
Expand Down Expand Up @@ -192,7 +196,7 @@ const ContentLibrary = () => {
<div key={chapter.id} className="mx-5">
<div
className="text-md font-semibold mt-2 bg-primary text-white cursor-pointer px-4 py-4 mb-4 flex flex-row justify-between items-center"
onClick={() => toggleChapterExpansion(chapter.id)}
onClick={() => toggleChapterExpansion(chapter.id, chapter.name)}
>
<div className="w-52">{chapter.name}</div>
<div className="w-8 flex justify-center">
Expand All @@ -214,7 +218,7 @@ const ContentLibrary = () => {
{resources
.filter((resource) => resource.topic_id === topic.id)
.map((resource) => (
<li key={resource.id} className="py-2">
<li key={resource.id} onClick={() => handleResourceTracking(resource.name)} className="py-2">
<Link href={resource.link} target="_blank" rel="noopener noreferrer" className="flex flex-row">
<Image src={PlayIcon} alt="Play" className="w-10 h-10 mr-2" /> {resource.name}
</Link>
Expand Down

0 comments on commit ce934f7

Please sign in to comment.