From 501e15964fedec40c04ff28bf99f3cae3e04b942 Mon Sep 17 00:00:00 2001 From: Andrey Mikhadyuk Date: Wed, 29 Nov 2023 20:20:50 +0400 Subject: [PATCH] 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 (