Skip to content

Commit

Permalink
Merge pull request #446 from suvarnakale/release-1.0.0
Browse files Browse the repository at this point in the history
Issue #PS-2546 bug: Not able to see preview / template image at requisites of topic and subtopic- fix
  • Loading branch information
itsvick authored Nov 27, 2024
2 parents 6ef1da0 + 81b7933 commit 1cb3bf9
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 810 deletions.
6 changes: 5 additions & 1 deletion src/components/RequisitesAccordion.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,11 @@ const RequisitesAccordion: React.FC<RequisitesAccordionProps> = ({
<Grid item xs={6} sx={{ mt: 2 }} key={item.name}>
<Box
className="facilitator-bg"
onClick={() => handlePlayers(item?.identifier)}
sx={{
backgroundImage: `url(${item?.appIcon ? item.appIcon : '/decorationBg.png'})`,
position: 'relative',
}}
onClick={() => handlePlayers(item?.id)}
>
<Box
sx={{
Expand Down
42 changes: 40 additions & 2 deletions src/components/SessionCardFooter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import { convertUTCToIST, getDayMonthYearFormat } from '@/utils/Helper';
import { EventStatus } from '@/utils/app.constant';
import { useDirection } from '../hooks/useDirection';
import { useRouter } from 'next/router';
import { fetchBulkContents } from '@/services/PlayerService';
import { IResource } from '@/pages/course-planner/center/[cohortId]';

const SessionCardFooter: React.FC<SessionCardFooterProps> = ({
item,
Expand Down Expand Up @@ -108,7 +110,7 @@ const SessionCardFooter: React.FC<SessionCardFooterProps> = ({
name: resource?.name,
link: resource?.link,
type: resource?.type || '',
identifier: resource?.identifier || '',
id: resource?.id || '',
})
);
return subAcc;
Expand All @@ -118,7 +120,9 @@ const SessionCardFooter: React.FC<SessionCardFooterProps> = ({
return acc;
}, {});
console.log(learningResources);
setLearningResources(learningResources);
const resources: IResource[] = extractResources(learningResources);
const enrichedContent = await fetchLearningResources(resources);
setLearningResources(enrichedContent);
}
}
} catch (error) {
Expand All @@ -129,6 +133,40 @@ const SessionCardFooter: React.FC<SessionCardFooterProps> = ({
fetchTopicSubtopic();
}, [item]);

const extractResources = (learningResources: any): IResource[] => {
const resources: IResource[] = [];

Object.values(learningResources).forEach((childTasks: any) => {
Object.values(childTasks).forEach((resourceArray: any) => {
if (Array.isArray(resourceArray)) {
resources.push(...resourceArray);
}
});
});

return resources;
};

const fetchLearningResources = async (resources: IResource[]) => {
try {
const identifiers = resources?.map((resource: IResource) => resource?.id);
const response = await fetchBulkContents(identifiers);

resources = resources.map((resource: IResource) => {
const content = response?.find(
(content: any) => content?.identifier === resource?.id
);
return { ...resource, ...content, name: resource.name };
});

// setResources(resources);
console.log('response===>', resources);
return resources;
} catch (error) {
console.error('error', error);
}
};

const handleComponentOpen = () => {
setSelectedTopic('');
setSelectedSubtopics([]);
Expand Down
32 changes: 15 additions & 17 deletions src/components/TopicDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,18 @@ const TopicDetails: React.FC<TopicDetailsProps> = ({
const { t } = useTranslation();
const theme = useTheme<any>();

const content: any = [];
if (learningResources?.[topic]) {
const subTopics = learningResources[topic];
subTopic?.forEach((currentSubTopic: string) => {
if (subTopics[currentSubTopic]) {
const resources = subTopics[currentSubTopic];
resources?.forEach((resource: any) => {
content.push(resource);
});
}
});
}
// const content: any = [];
// if (learningResources?.[topic]) {
// const subTopics = learningResources[topic];
// subTopic?.forEach((currentSubTopic: string) => {
// if (subTopics[currentSubTopic]) {
// const resources = subTopics[currentSubTopic];
// resources?.forEach((resource: any) => {
// content.push(resource);
// });
// }
// });
// }

const openTopicModal = () => {
handleOpen();
Expand Down Expand Up @@ -154,29 +154,27 @@ const TopicDetails: React.FC<TopicDetailsProps> = ({
/>
</Box>
</Box>

<Box sx={{ mb: 1.5 }}>

<RequisitesAccordion
title={t('CENTER_SESSION.FACILITATOR_REQUISITES')}
type={RequisiteType.FACILITATOR_REQUISITE}
content={content}
content={learningResources}
handlePlayers={handlePlayers}
theme={theme}
subTopic={subTopic}
/>
<RequisitesAccordion
title={t('CENTER_SESSION.PREREQUISITES')}
type={RequisiteType.PRE_REQUISITES}
content={content}
content={learningResources}
handlePlayers={handlePlayers}
theme={theme}
subTopic={subTopic}
/>
<RequisitesAccordion
title={t('CENTER_SESSION.POST_REQUISITES')}
type={RequisiteType.POST_REQUISITES}
content={content}
content={learningResources}
handlePlayers={handlePlayers}
theme={theme}
subTopic={subTopic}
Expand Down
Loading

0 comments on commit 1cb3bf9

Please sign in to comment.