Skip to content

Commit

Permalink
Merge pull request #2392 from daostack/feature/CW-2089-link-stream
Browse files Browse the repository at this point in the history
FE add "Link stream" action #2089
  • Loading branch information
pvm-code authored Dec 21, 2023
2 parents 296f948 + 444d8fb commit 72fb592
Show file tree
Hide file tree
Showing 68 changed files with 1,362 additions and 110 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import {
GetLastMessageOptions,
GetNonAllowedItemsOptions,
} from "../FeedItem";
import { LinkSpaceModal } from "./components";
import { useMenuItems } from "./hooks";

interface DiscussionFeedCardProps {
Expand All @@ -65,6 +66,7 @@ interface DiscussionFeedCardProps {
getNonAllowedItems?: GetNonAllowedItemsOptions;
onActiveItemDataChange?: (data: FeedLayoutItemChangeData) => void;
directParent?: DirectParent | null;
rootCommonId?: string;
feedItemFollow: FeedItemFollowState;
onUserSelect?: (userId: string, commonId?: string) => void;
}
Expand Down Expand Up @@ -93,6 +95,7 @@ const DiscussionFeedCard = forwardRef<FeedItemRef, DiscussionFeedCardProps>(
getNonAllowedItems,
onActiveItemDataChange,
directParent,
rootCommonId,
feedItemFollow,
onUserSelect,
} = props;
Expand All @@ -111,6 +114,11 @@ const DiscussionFeedCard = forwardRef<FeedItemRef, DiscussionFeedCardProps>(
onOpen: onDeleteModalOpen,
onClose: onDeleteModalClose,
} = useModal(false);
const {
isShowing: isLinkSpaceModalOpen,
onOpen: onLinkSpaceModalOpen,
onClose: onLinkSpaceModalClose,
} = useModal(false);
const [isDeletingInProgress, setDeletingInProgress] = useState(false);
const {
fetchUser: fetchDiscussionCreator,
Expand Down Expand Up @@ -147,6 +155,7 @@ const DiscussionFeedCard = forwardRef<FeedItemRef, DiscussionFeedCardProps>(
report: onReportModalOpen,
share: () => onShareModalOpen(),
remove: onDeleteModalOpen,
linkSpace: onLinkSpaceModalOpen,
},
);
const user = useSelector(selectUser());
Expand Down Expand Up @@ -346,6 +355,8 @@ const DiscussionFeedCard = forwardRef<FeedItemRef, DiscussionFeedCardProps>(
isFeedItemUserMetadataFetched &&
feedItemUserMetadata?.hasUnseenMention
}
originalCommonIdForLinking={discussion?.commonId}
linkedCommonIds={discussion?.linkedCommonIds}
>
{renderContent()}
</FeedCard>
Expand Down Expand Up @@ -378,6 +389,18 @@ const DiscussionFeedCard = forwardRef<FeedItemRef, DiscussionFeedCardProps>(
/>
</GlobalOverlay>
)}
{commonId && (
<LinkSpaceModal
isOpen={isLinkSpaceModalOpen}
onClose={onLinkSpaceModalClose}
feedItemId={item.id}
title={cardTitle || ""}
rootCommonId={rootCommonId || commonId}
commonId={commonId}
originalCommonId={discussion?.commonId || ""}
linkedCommonIds={discussion?.linkedCommonIds}
/>
)}
</>
);
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
@import "../../../../../../constants";
@import "../../../../../../styles/sizes";

.modal {
max-width: 31.875rem;
width: 100%;
max-height: 33.75rem;
min-height: 24rem;
border-radius: 0;
box-shadow: 0 0.25rem 0.9375rem var(--drop-shadow);

:global(.modal__header-wrapper--with-modal-padding) {
.modalHeader {
justify-content: flex-start;
}

.modalTitle {
margin: 0;
font-family: PoppinsSans, sans-serif;
font-weight: 600;
font-size: 1.25rem;
color: var(--primary-text);
text-align: left;
word-break: break-word;
}
}

.modalContent {
width: 100%;
display: flex;
flex-direction: column;
overflow: hidden;
box-sizing: border-box;
}

.modalCloseWrapper {
top: 1.7rem;
margin: 0;

@include tablet {
top: 1.1rem;
}
}

@include tablet {
max-width: unset;
max-height: unset;
}
}

.submitButtonWrapper {
margin-top: auto;
padding-top: 1.5rem;
display: flex;
justify-content: flex-end;
}

.submitButton {
--btn-w: 100%;

max-width: 9.75rem;

@include tablet {
max-width: 100%;
}
}

.loader {
margin: 0 auto;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
import React, { FC, ReactElement, useEffect, useState } from "react";
import { useSelector } from "react-redux";
import { selectUser } from "@/pages/Auth/store/selectors";
import { Modal } from "@/shared/components";
import { useNotification } from "@/shared/hooks";
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";

interface DirectMessageModalProps {
isOpen: boolean;
onClose: () => void;
feedItemId: string;
title: string;
rootCommonId: string;
commonId: string;
originalCommonId: string;
linkedCommonIds?: string[];
}

const LinkSpaceModal: FC<DirectMessageModalProps> = (props) => {
const {
isOpen,
onClose,
feedItemId,
title,
rootCommonId,
commonId,
originalCommonId,
linkedCommonIds = [],
} = props;
const { notify } = useNotification();
const { isStreamLinking, isStreamLinked, linkStream } = useStreamLinking();
const [activeItemId, setActiveItemId] = useState("");
const user = useSelector(selectUser());
const userId = user?.uid;

const handleSubmit = () => {
if (!userId) {
return;
}

linkStream({
userId,
feedObjectId: feedItemId,
sourceCommonId: commonId,
targetCommonId: activeItemId,
});
};

const renderContent = (): ReactElement => {
if (isStreamLinking) {
return <Loader className={styles.loader} />;
}

return (
<>
<Projects
rootCommonId={rootCommonId}
commonId={commonId}
activeItemId={activeItemId}
onActiveItemId={setActiveItemId}
originalCommonId={originalCommonId}
linkedCommonIds={linkedCommonIds}
/>
<div className={styles.submitButtonWrapper}>
<Button
className={styles.submitButton}
variant={ButtonVariant.PrimaryPink}
disabled={!activeItemId}
onClick={handleSubmit}
>
Apply
</Button>
</div>
</>
);
};

useEffect(() => {
if (isStreamLinked) {
notify("Stream is successfully linked");
onClose();
}
}, [isStreamLinking, isStreamLinked]);

return (
<Modal
className={styles.modal}
isShowing={isOpen}
onClose={isStreamLinking ? emptyFunction : onClose}
title={`Link “${title}“`}
isHeaderSticky
hideCloseButton={isStreamLinking}
mobileFullScreen
styles={{
header: styles.modalHeader,
title: styles.modalTitle,
content: styles.modalContent,
closeWrapper: styles.modalCloseWrapper,
}}
>
{renderContent()}
</Modal>
);
};

export default LinkSpaceModal;
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
@import "../../../../../../../../constants";
@import "../../../../../../../../styles/sizes";

.projectsTree {
overflow-y: auto;
box-sizing: border-box;
}

.projectsTreeItemTriggerClassName {
--item-pl-per-level: 1.25rem;
--item-arrow-pl: 0.5rem;

height: 3rem;
border-radius: 0;

&:hover {
--bg-color: var(--secondary-text);
--item-text-color: #{$c-shades-white};
}

@media (hover: none) {
&:hover {
--bg-color: var(--primary-background);
--item-text-color: var(--primary-text);
}
}
}
.projectsTreeItemTriggerActiveClassName {
--bg-color: var(--primary-fill);
--item-text-color: #{$c-shades-white};

&:hover {
--bg-color: var(--primary-fill);
}

@media (hover: none) {
&:hover {
--bg-color: var(--primary-fill);
--item-text-color: #{$c-shades-white};
}
}
}

.projectsTreeItemTriggerNameClassName {
font-family: PoppinsSans, sans-serif;
font-weight: 500;
}

.projectsTreeItemTriggerImageClassName {
width: 1.5rem;
height: 1.5rem;
margin-right: 0.875rem;
}
.projectsTreeItemTriggerImageNonRoundedClassName {
border-radius: 0.375rem;
}

.loader {
margin: 1rem auto 0;
display: block;
}

.createCommonButton {
width: 100%;
padding-left: 2.125rem;
padding-right: 0.875rem;
}

.commonsMenuClassName {
max-height: 15rem;
}
Loading

0 comments on commit 72fb592

Please sign in to comment.