Skip to content

Commit

Permalink
Merge pull request #1467 from culturecreates/bugfix/tech-support-issu…
Browse files Browse the repository at this point in the history
…e-104

fix: optimised code and added support for image type object closes
  • Loading branch information
SyamBabu-M authored Nov 28, 2024
2 parents 7d6ac0c + 765d02f commit df4fd78
Showing 1 changed file with 22 additions and 35 deletions.
57 changes: 22 additions & 35 deletions src/components/Accordion/CalendarAccordion/CalendarAccordion.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,22 @@ function CalendarAccordion(props) {

const calendarContentLanguage = currentCalendarData?.contentLanguage;

const processEntities = (entities) => {
if (!entities) return [];
return entities.map((v) => ({
...v,
image: Array.isArray(v?.image)
? v?.image.find((image) => image?.isMain) || null
: typeof v?.image === 'object' && v?.image !== null
? v?.image
: null,
}));
};

const updateList = (entities, setter) => {
setter(treeEntitiesOption(processEntities(entities), user, calendarContentLanguage, sourceOptions.CMS));
};

const organizationPersonSearch = (value, type) => {
const queryMap = {
organizers: query,
Expand All @@ -95,25 +111,10 @@ function CalendarAccordion(props) {
getEntities({ searchKey: value, classes: decodeURIComponent(currentQuery.toString()), calendarId })
.unwrap()
.then((response) => {
if (type == 'organizers') {
setOrganizersList(
treeEntitiesOption(
response?.map((v) => ({ ...v, image: v?.image?.find((image) => image?.isMain) })),
user,
calendarContentLanguage,
sourceOptions.CMS,
),
);
}
if (type == 'people') {
setPeopleList(
treeEntitiesOption(
response?.map((v) => ({ ...v, image: v?.image?.find((image) => image?.isMain) })),
user,
calendarContentLanguage,
sourceOptions.CMS,
),
);
if (type === 'organizers') {
updateList(response, setOrganizersList);
} else if (type === 'people') {
updateList(response, setPeopleList);
}
})
.catch((error) => console.log(error));
Expand All @@ -131,27 +132,13 @@ function CalendarAccordion(props) {

useEffect(() => {
if (initialEntities && currentCalendarData) {
setOrganizersList(
treeEntitiesOption(
initialEntities?.map((v) => ({ ...v, image: v?.image?.find((image) => image?.isMain) })),
user,
calendarContentLanguage,
sourceOptions.CMS,
),
);
updateList(initialEntities, setOrganizersList);
}
}, [initialEntityLoading, currentCalendarData]);

useEffect(() => {
if (initialPersonEntities && currentCalendarData) {
setPeopleList(
treeEntitiesOption(
initialPersonEntities?.map((v) => ({ ...v, image: v?.image?.find((image) => image?.isMain) })),
user,
calendarContentLanguage,
sourceOptions.CMS,
),
);
updateList(initialPersonEntities, setPeopleList);
}
}, [initialPersonEntityLoading, currentCalendarData]);

Expand Down

0 comments on commit df4fd78

Please sign in to comment.