From 07ae59378fe569452a40497fc21d83ae7914da37 Mon Sep 17 00:00:00 2001 From: Andrey Mikhadyuk Date: Wed, 29 Nov 2023 20:26:46 +0400 Subject: [PATCH 1/2] use cached commons in the breadcrumbs commons fetch --- .../saga/fetchBreadcrumbsItemsByCommonId.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/store/states/multipleSpacesLayout/saga/fetchBreadcrumbsItemsByCommonId.ts b/src/store/states/multipleSpacesLayout/saga/fetchBreadcrumbsItemsByCommonId.ts index c7e27de108..b99dbf8220 100644 --- a/src/store/states/multipleSpacesLayout/saga/fetchBreadcrumbsItemsByCommonId.ts +++ b/src/store/states/multipleSpacesLayout/saga/fetchBreadcrumbsItemsByCommonId.ts @@ -9,7 +9,7 @@ import { MultipleSpacesLayoutState, ProjectsStateItem } from "../types"; const fetchProjectsInfoByActiveCommonId = async ( commonId: string, ): Promise => { - const activeCommon = await CommonService.getCommonById(commonId); + const activeCommon = await CommonService.getCommonById(commonId, true); if (!activeCommon) { return []; @@ -17,6 +17,7 @@ const fetchProjectsInfoByActiveCommonId = async ( const commons = await CommonService.getAllParentCommonsForCommon( activeCommon, + true, ); return [...commons, activeCommon].map((common) => ({ From b8814e96d75cfadd60315d9ef277fd29ccc2cbed Mon Sep 17 00:00:00 2001 From: Andrey Mikhadyuk Date: Wed, 29 Nov 2023 20:27:37 +0400 Subject: [PATCH 2/2] add subscription to breadcrumbs related commons --- .../FeedItemBreadcrumbs.tsx | 26 ++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/src/shared/layouts/MultipleSpacesLayout/components/Header/components/Breadcrumbs/components/FeedItemBreadcrumbs/FeedItemBreadcrumbs.tsx b/src/shared/layouts/MultipleSpacesLayout/components/Header/components/Breadcrumbs/components/FeedItemBreadcrumbs/FeedItemBreadcrumbs.tsx index dd86ccc171..eac4ae6a42 100644 --- a/src/shared/layouts/MultipleSpacesLayout/components/Header/components/Breadcrumbs/components/FeedItemBreadcrumbs/FeedItemBreadcrumbs.tsx +++ b/src/shared/layouts/MultipleSpacesLayout/components/Header/components/Breadcrumbs/components/FeedItemBreadcrumbs/FeedItemBreadcrumbs.tsx @@ -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, @@ -34,6 +36,28 @@ const FeedItemBreadcrumbs: FC = (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 (
    {breadcrumbs.areItemsLoading && }