Skip to content

Commit

Permalink
Merge pull request #2364 from daostack/feature/CW-2356-optimize-bread…
Browse files Browse the repository at this point in the history
…crumbs-loading

Optimize breadcrumb loading #2356
  • Loading branch information
andreymikhadyuk authored Nov 30, 2023
2 parents 30edd7d + b8814e9 commit 561d89e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import React, { FC } from "react";
import React, { FC, useEffect } from "react";
import { useDispatch, useSelector } from "react-redux";
import { CommonEvent, CommonEventEmitter } from "@/events";
import { CommonService } from "@/services";
import {
commonLayoutActions,
MultipleSpacesLayoutFeedItemBreadcrumbs,
Expand Down Expand Up @@ -34,6 +36,28 @@ const FeedItemBreadcrumbs: FC<FeedItemBreadcrumbsProps> = (props) => {
}
};

useEffect(() => {
const commonIds = breadcrumbs.items.map((item) => item.commonId);

if (commonIds.length === 0) {
return;
}

const unsubscribe = CommonService.subscribeToCommons(commonIds, (data) => {
data.forEach(({ common }) => {
CommonEventEmitter.emit(CommonEvent.ProjectUpdated, {
commonId: common.id,
image: common.image,
name: common.name,
directParent: common.directParent,
rootCommonId: common.rootCommonId,
});
});
});

return unsubscribe;
}, [breadcrumbs.activeItem?.id]);

return (
<ul className={styles.container}>
{breadcrumbs.areItemsLoading && <LoadingBreadcrumbsItem />}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@ import { MultipleSpacesLayoutState, ProjectsStateItem } from "../types";
const fetchProjectsInfoByActiveCommonId = async (
commonId: string,
): Promise<ProjectsStateItem[]> => {
const activeCommon = await CommonService.getCommonById(commonId);
const activeCommon = await CommonService.getCommonById(commonId, true);

if (!activeCommon) {
return [];
}

const commons = await CommonService.getAllParentCommonsForCommon(
activeCommon,
true,
);

return [...commons, activeCommon].map((common) => ({
Expand Down

0 comments on commit 561d89e

Please sign in to comment.