Skip to content

Commit

Permalink
add subscription to breadcrumbs related commons
Browse files Browse the repository at this point in the history
  • Loading branch information
andreymikhadyuk committed Nov 29, 2023
1 parent 07ae593 commit b8814e9
Showing 1 changed file with 25 additions and 1 deletion.
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

0 comments on commit b8814e9

Please sign in to comment.