Skip to content

Commit

Permalink
Merge pull request #2422 from daostack/bugfix/CW-2089-stream-linking
Browse files Browse the repository at this point in the history
FE add "Link stream" action #2089
  • Loading branch information
pvm-code authored Dec 26, 2023
2 parents 854bf86 + cd4518b commit 77d1b18
Show file tree
Hide file tree
Showing 19 changed files with 63 additions and 90 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ import {
GetLastMessageOptions,
GetNonAllowedItemsOptions,
} from "../FeedItem";
import { LinkSpaceModal } from "./components";
import { LinkStreamModal } from "./components";
import { useMenuItems } from "./hooks";

interface DiscussionFeedCardProps {
Expand Down Expand Up @@ -115,9 +115,9 @@ const DiscussionFeedCard = forwardRef<FeedItemRef, DiscussionFeedCardProps>(
onClose: onDeleteModalClose,
} = useModal(false);
const {
isShowing: isLinkSpaceModalOpen,
onOpen: onLinkSpaceModalOpen,
onClose: onLinkSpaceModalClose,
isShowing: isLinkStreamModalOpen,
onOpen: onLinkStreamModalOpen,
onClose: onLinkStreamModalClose,
} = useModal(false);
const [isDeletingInProgress, setDeletingInProgress] = useState(false);
const {
Expand Down Expand Up @@ -155,7 +155,7 @@ const DiscussionFeedCard = forwardRef<FeedItemRef, DiscussionFeedCardProps>(
report: onReportModalOpen,
share: () => onShareModalOpen(),
remove: onDeleteModalOpen,
linkSpace: onLinkSpaceModalOpen,
linkStream: onLinkStreamModalOpen,
},
);
const user = useSelector(selectUser());
Expand Down Expand Up @@ -390,15 +390,16 @@ const DiscussionFeedCard = forwardRef<FeedItemRef, DiscussionFeedCardProps>(
</GlobalOverlay>
)}
{commonId && (
<LinkSpaceModal
isOpen={isLinkSpaceModalOpen}
onClose={onLinkSpaceModalClose}
<LinkStreamModal
isOpen={isLinkStreamModalOpen}
onClose={onLinkStreamModalClose}
feedItemId={item.id}
title={cardTitle || ""}
rootCommonId={rootCommonId || commonId}
commonId={commonId}
originalCommonId={discussion?.commonId || ""}
linkedCommonIds={discussion?.linkedCommonIds}
circleVisibility={item.circleVisibility}
/>
)}
</>
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import { useStreamLinking } from "@/shared/hooks/useCases";
import { Button, ButtonVariant, Loader } from "@/shared/ui-kit";
import { emptyFunction } from "@/shared/utils";
import { Projects } from "./components";
import styles from "./LinkSpaceModal.module.scss";
import styles from "./LinkStreamModal.module.scss";

interface DirectMessageModalProps {
interface LinkStreamModalProps {
isOpen: boolean;
onClose: () => void;
feedItemId: string;
Expand All @@ -18,9 +18,10 @@ interface DirectMessageModalProps {
commonId: string;
originalCommonId: string;
linkedCommonIds?: string[];
circleVisibility: string[];
}

const LinkSpaceModal: FC<DirectMessageModalProps> = (props) => {
const LinkStreamModal: FC<LinkStreamModalProps> = (props) => {
const {
isOpen,
onClose,
Expand All @@ -30,6 +31,7 @@ const LinkSpaceModal: FC<DirectMessageModalProps> = (props) => {
commonId,
originalCommonId,
linkedCommonIds = [],
circleVisibility,
} = props;
const { notify } = useNotification();
const { isStreamLinking, isStreamLinked, linkStream } = useStreamLinking();
Expand Down Expand Up @@ -64,6 +66,7 @@ const LinkSpaceModal: FC<DirectMessageModalProps> = (props) => {
onActiveItemId={setActiveItemId}
originalCommonId={originalCommonId}
linkedCommonIds={linkedCommonIds}
circleVisibility={circleVisibility}
/>
<div className={styles.submitButtonWrapper}>
<Button
Expand Down Expand Up @@ -107,4 +110,4 @@ const LinkSpaceModal: FC<DirectMessageModalProps> = (props) => {
);
};

export default LinkSpaceModal;
export default LinkStreamModal;
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ interface ProjectsProps {
onActiveItemId: (activeItemId: string) => void;
originalCommonId: string;
linkedCommonIds: string[];
circleVisibility: string[];
renderNoItemsInfo?: () => ReactNode;
}

Expand All @@ -23,6 +24,7 @@ const Projects: FC<ProjectsProps> = (props) => {
renderNoItemsInfo,
originalCommonId,
linkedCommonIds,
circleVisibility,
} = props;
const [currentCommonId, setCurrentCommonId] = useState(props.rootCommonId);
const {
Expand All @@ -35,9 +37,11 @@ const Projects: FC<ProjectsProps> = (props) => {
parentItemIds,
} = useProjectsData({
currentCommonId,
currentCommonRootCommonId: props.rootCommonId,
activeItemId,
originalCommonId,
linkedCommonIds,
circleVisibility,
});
const treeItemTriggerStyles = useMemo<TreeItemTriggerStyles>(
() => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@ import { NameRightContent } from "./components";

interface ProjectsInfo {
currentCommonId: string;
currentCommonRootCommonId: string;
activeItemId: string;
originalCommonId: string;
linkedCommonIds: string[];
circleVisibility: string[];
}

interface Return {
Expand All @@ -36,8 +38,14 @@ interface Return {
const generateItemCommonPagePath = () => "";

export const useProjectsData = (projectsInfo: ProjectsInfo): Return => {
const { currentCommonId, activeItemId, originalCommonId, linkedCommonIds } =
projectsInfo;
const {
currentCommonId,
currentCommonRootCommonId,
activeItemId,
originalCommonId,
linkedCommonIds,
circleVisibility,
} = projectsInfo;
const currentCommonIdRef = useRef(currentCommonId);
currentCommonIdRef.current = currentCommonId;
const { commons, areCommonsLoading } = useSelector(
Expand All @@ -52,20 +60,33 @@ export const useProjectsData = (projectsInfo: ProjectsInfo): Return => {
);

const getAdditionalItemData = useCallback(
(projectsStateItem: ProjectsStateItem): Partial<Item> => ({
disabled:
!projectsStateItem.hasPermissionToLinkToHere ||
projectsStateItem.commonId === originalCommonId ||
linkedCommonIds.includes(projectsStateItem.commonId),
nameRightContent: (
<NameRightContent
projectsStateItem={projectsStateItem}
originalCommonId={originalCommonId}
linkedCommonIds={linkedCommonIds}
/>
),
}),
[originalCommonId, linkedCommonIds],
(projectsStateItem: ProjectsStateItem): Partial<Item> => {
const isAllowedToLink =
circleVisibility.length === 0 ||
projectsStateItem.commonId === currentCommonRootCommonId ||
projectsStateItem.rootCommonId === currentCommonRootCommonId;

return {
disabled:
!isAllowedToLink ||
!projectsStateItem.hasPermissionToLinkToHere ||
projectsStateItem.commonId === originalCommonId ||
linkedCommonIds.includes(projectsStateItem.commonId),
nameRightContent: (
<NameRightContent
projectsStateItem={projectsStateItem}
originalCommonId={originalCommonId}
linkedCommonIds={linkedCommonIds}
/>
),
};
},
[
originalCommonId,
linkedCommonIds,
currentCommonRootCommonId,
circleVisibility,
],
);

const parentItem = useMemo(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default as LinkStreamModal } from "./LinkStreamModal";
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from "./LinkSpaceModal";
export * from "./LinkStreamModal";
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ interface Actions {
report: () => void;
share: () => void;
remove?: () => void;
linkSpace?: () => void;
linkStream?: () => void;
}

export const useMenuItems = (
Expand All @@ -42,7 +42,7 @@ export const useMenuItems = (
feedItemFollow,
feedItemUserMetadata,
} = options;
const { report, share, remove, linkSpace } = actions;
const { report, share, remove, linkStream } = actions;
const allowedMenuItems = getAllowedItems({ ...options, feedItemFollow });
const items: Item[] = [
{
Expand Down Expand Up @@ -148,11 +148,11 @@ export const useMenuItems = (
feedItemFollow.onFollowToggle(FollowFeedItemAction.Unfollow),
icon: <UnfollowIcon />,
},
linkSpace
linkStream
? {
id: FeedItemMenuItem.LinkTo,
text: "Link to...",
onClick: linkSpace,
onClick: linkStream,
icon: <LinkIcon />,
}
: undefined,
Expand Down

0 comments on commit 77d1b18

Please sign in to comment.