From a4476a6a999c754e2ac9109396d7d8b8d51993b2 Mon Sep 17 00:00:00 2001 From: Pavel Meyer Date: Mon, 2 Sep 2024 15:11:36 +0300 Subject: [PATCH] CW-Optimistic-streams Full support of proposal optimistic streams Clean up code --- .../ChatComponent/ChatComponent.tsx | 2 +- .../NewDiscussionCreation.tsx | 56 ++------ .../NewProposalCreation.tsx | 83 +++--------- .../common/components/FeedItem/FeedItem.tsx | 12 +- .../LinkStreamModal.module.scss | 70 ---------- .../LinkStreamModal/LinkStreamModal.tsx | 113 ---------------- .../LinkStreamProjects/LinkStreamProjects.tsx | 46 ------- .../NameRightContent.module.scss | 11 -- .../NameRightContent/NameRightContent.tsx | 25 ---- .../components/NameRightContent/index.ts | 1 - .../LinkStreamProjects/components/index.ts | 1 - .../components/LinkStreamProjects/index.ts | 1 - .../LinkStreamModal/components/index.ts | 1 - .../components/LinkStreamModal/index.ts | 1 - .../MoveStreamModal.module.scss | 70 ---------- .../MoveStreamModal/MoveStreamModal.tsx | 110 --------------- .../MoveStreamProjects/MoveStreamProjects.tsx | 42 ------ .../components/MoveStreamProjects/index.ts | 1 - .../MoveStreamModal/components/index.ts | 1 - .../components/MoveStreamModal/index.ts | 1 - .../index.ts | 1 - .../components/Projects/Projects.module.scss | 71 ---------- .../components/Projects/Projects.tsx | 86 ------------ .../components/Projects/hooks/index.ts | 1 - .../Projects/hooks/useProjectsData.ts | 127 ------------------ .../components/Projects/index.ts | 2 - .../UnlinkStreamModal.module.scss | 39 ------ .../UnlinkStreamModal/UnlinkStreamModal.tsx | 116 ---------------- .../components/UnlinkStreamModal/index.ts | 1 - .../components/index.ts | 4 - .../OptimisticDiscussionFeedCard/index.ts | 1 - .../utils/checkIsEditItemAllowed.ts | 13 -- .../utils/checkIsLinkToAllowed.ts | 32 ----- .../utils/checkIsMoveToAllowed.ts | 28 ---- .../utils/checkIsPinUnpinAllowed.ts | 44 ------ .../utils/checkIsRemoveDiscussionAllowed.ts | 38 ------ .../OptimisticFeedCard.tsx} | 16 ++- .../OptimisticFeedCardContent.tsx} | 13 +- .../OptimisticFeedCardContent/index.ts | 1 + .../OptimisticFeedCard/components/index.ts | 1 + .../hooks/index.ts | 0 .../hooks/useMenuItems.tsx | 0 .../components/OptimisticFeedCard/index.ts | 1 + .../utils/getAllowedItems.ts | 0 .../utils/index.ts | 0 src/pages/common/components/index.ts | 2 +- .../hooks/useCases/useCommonFeedItems.ts | 3 +- src/shared/models/CommonFeed.tsx | 1 + .../utils/generateOptimisticFeedItem.ts | 63 +++++++++ src/shared/utils/index.tsx | 1 + src/store/states/common/reducer.ts | 5 +- 51 files changed, 130 insertions(+), 1229 deletions(-) delete mode 100644 src/pages/common/components/OptimisticDiscussionFeedCard/components/LinkStreamModal/LinkStreamModal.module.scss delete mode 100644 src/pages/common/components/OptimisticDiscussionFeedCard/components/LinkStreamModal/LinkStreamModal.tsx delete mode 100644 src/pages/common/components/OptimisticDiscussionFeedCard/components/LinkStreamModal/components/LinkStreamProjects/LinkStreamProjects.tsx delete mode 100644 src/pages/common/components/OptimisticDiscussionFeedCard/components/LinkStreamModal/components/LinkStreamProjects/components/NameRightContent/NameRightContent.module.scss delete mode 100644 src/pages/common/components/OptimisticDiscussionFeedCard/components/LinkStreamModal/components/LinkStreamProjects/components/NameRightContent/NameRightContent.tsx delete mode 100644 src/pages/common/components/OptimisticDiscussionFeedCard/components/LinkStreamModal/components/LinkStreamProjects/components/NameRightContent/index.ts delete mode 100644 src/pages/common/components/OptimisticDiscussionFeedCard/components/LinkStreamModal/components/LinkStreamProjects/components/index.ts delete mode 100644 src/pages/common/components/OptimisticDiscussionFeedCard/components/LinkStreamModal/components/LinkStreamProjects/index.ts delete mode 100644 src/pages/common/components/OptimisticDiscussionFeedCard/components/LinkStreamModal/components/index.ts delete mode 100644 src/pages/common/components/OptimisticDiscussionFeedCard/components/LinkStreamModal/index.ts delete mode 100644 src/pages/common/components/OptimisticDiscussionFeedCard/components/MoveStreamModal/MoveStreamModal.module.scss delete mode 100644 src/pages/common/components/OptimisticDiscussionFeedCard/components/MoveStreamModal/MoveStreamModal.tsx delete mode 100644 src/pages/common/components/OptimisticDiscussionFeedCard/components/MoveStreamModal/components/MoveStreamProjects/MoveStreamProjects.tsx delete mode 100644 src/pages/common/components/OptimisticDiscussionFeedCard/components/MoveStreamModal/components/MoveStreamProjects/index.ts delete mode 100644 src/pages/common/components/OptimisticDiscussionFeedCard/components/MoveStreamModal/components/index.ts delete mode 100644 src/pages/common/components/OptimisticDiscussionFeedCard/components/MoveStreamModal/index.ts delete mode 100644 src/pages/common/components/OptimisticDiscussionFeedCard/components/OptimisticDiscussionFeedCardContent/index.ts delete mode 100644 src/pages/common/components/OptimisticDiscussionFeedCard/components/Projects/Projects.module.scss delete mode 100644 src/pages/common/components/OptimisticDiscussionFeedCard/components/Projects/Projects.tsx delete mode 100644 src/pages/common/components/OptimisticDiscussionFeedCard/components/Projects/hooks/index.ts delete mode 100644 src/pages/common/components/OptimisticDiscussionFeedCard/components/Projects/hooks/useProjectsData.ts delete mode 100644 src/pages/common/components/OptimisticDiscussionFeedCard/components/Projects/index.ts delete mode 100644 src/pages/common/components/OptimisticDiscussionFeedCard/components/UnlinkStreamModal/UnlinkStreamModal.module.scss delete mode 100644 src/pages/common/components/OptimisticDiscussionFeedCard/components/UnlinkStreamModal/UnlinkStreamModal.tsx delete mode 100644 src/pages/common/components/OptimisticDiscussionFeedCard/components/UnlinkStreamModal/index.ts delete mode 100644 src/pages/common/components/OptimisticDiscussionFeedCard/components/index.ts delete mode 100644 src/pages/common/components/OptimisticDiscussionFeedCard/index.ts delete mode 100644 src/pages/common/components/OptimisticDiscussionFeedCard/utils/checkIsEditItemAllowed.ts delete mode 100644 src/pages/common/components/OptimisticDiscussionFeedCard/utils/checkIsLinkToAllowed.ts delete mode 100644 src/pages/common/components/OptimisticDiscussionFeedCard/utils/checkIsMoveToAllowed.ts delete mode 100644 src/pages/common/components/OptimisticDiscussionFeedCard/utils/checkIsPinUnpinAllowed.ts delete mode 100644 src/pages/common/components/OptimisticDiscussionFeedCard/utils/checkIsRemoveDiscussionAllowed.ts rename src/pages/common/components/{OptimisticDiscussionFeedCard/OptimisticDiscussionFeedCard.tsx => OptimisticFeedCard/OptimisticFeedCard.tsx} (96%) rename src/pages/common/components/{OptimisticDiscussionFeedCard/components/OptimisticDiscussionFeedCardContent/OptimisticDiscussionFeedCardContent.tsx => OptimisticFeedCard/components/OptimisticFeedCardContent/OptimisticFeedCardContent.tsx} (89%) create mode 100644 src/pages/common/components/OptimisticFeedCard/components/OptimisticFeedCardContent/index.ts create mode 100644 src/pages/common/components/OptimisticFeedCard/components/index.ts rename src/pages/common/components/{OptimisticDiscussionFeedCard => OptimisticFeedCard}/hooks/index.ts (100%) rename src/pages/common/components/{OptimisticDiscussionFeedCard => OptimisticFeedCard}/hooks/useMenuItems.tsx (100%) create mode 100644 src/pages/common/components/OptimisticFeedCard/index.ts rename src/pages/common/components/{OptimisticDiscussionFeedCard => OptimisticFeedCard}/utils/getAllowedItems.ts (100%) rename src/pages/common/components/{OptimisticDiscussionFeedCard => OptimisticFeedCard}/utils/index.ts (100%) create mode 100644 src/shared/utils/generateOptimisticFeedItem.ts diff --git a/src/pages/common/components/ChatComponent/ChatComponent.tsx b/src/pages/common/components/ChatComponent/ChatComponent.tsx index 4a71557936..197571f67e 100644 --- a/src/pages/common/components/ChatComponent/ChatComponent.tsx +++ b/src/pages/common/components/ChatComponent/ChatComponent.tsx @@ -268,7 +268,7 @@ export default function ChatComponent({ const optimisticFeedItems = useSelector(selectOptimisticFeedItems); - console.log("--optimisticFeedItems", optimisticFeedItems); + // console.log("--optimisticFeedItems", optimisticFeedItems); const optimisticDiscussionMessages = useSelector( selectOptimisticDiscussionMessages, ); diff --git a/src/pages/common/components/CommonTabPanels/components/FeedTab/components/NewDiscussionCreation/NewDiscussionCreation.tsx b/src/pages/common/components/CommonTabPanels/components/FeedTab/components/NewDiscussionCreation/NewDiscussionCreation.tsx index 63098068cc..06d8ca5998 100644 --- a/src/pages/common/components/CommonTabPanels/components/FeedTab/components/NewDiscussionCreation/NewDiscussionCreation.tsx +++ b/src/pages/common/components/CommonTabPanels/components/FeedTab/components/NewDiscussionCreation/NewDiscussionCreation.tsx @@ -1,9 +1,7 @@ import React, { FC, useCallback, useEffect, useMemo } from "react"; import { useDispatch, useSelector } from "react-redux"; -import { Timestamp as FirestoreTimestamp } from "firebase/firestore"; import { v4 as uuidv4 } from "uuid"; import { selectUser } from "@/pages/Auth/store/selectors"; -import { DiscussionMessageOwnerType } from "@/shared/constants"; import { NewDiscussionCreationFormValues, UploadFile, @@ -15,13 +13,12 @@ import { CommonFeedType, CommonMember, Governance, - OptimisticFeedItemState, } from "@/shared/models"; import { TextEditorValue, parseStringToTextEditorValue, } from "@/shared/ui-kit/TextEditor"; -import { getUserName } from "@/shared/utils"; +import { generateOptimisticFeedItem } from "@/shared/utils"; import { selectDiscussionCreationData, selectIsDiscussionCreationLoading, @@ -123,52 +120,19 @@ const NewDiscussionCreation: FC = (props) => { ); } else { const discussionId = uuidv4(); - const currentDate = FirestoreTimestamp.now(); - const optimisticFeedItemId = uuidv4(); dispatch( - commonActions.setOptimisticFeedItem({ - id: optimisticFeedItemId, - createdAt: currentDate, - updatedAt: currentDate, - isDeleted: false, - userId, - commonId: common.id, - data: { - type: CommonFeedType.OptimisticDiscussion, - id: discussionId, - discussionId: null, - lastMessage: { - userName: getUserName(user), - ownerId: userId, - content: JSON.stringify(values.content), - ownerType: DiscussionMessageOwnerType.User, - }, - hasFiles: false, - hasImages: false, - }, - optimisticData: { - id: discussionId, - title: values.title, - message: JSON.stringify(values.content), - ownerId: userId, + commonActions.setOptimisticFeedItem( + generateOptimisticFeedItem({ + userId, commonId: common.id, - lastMessage: currentDate, - updatedAt: currentDate, - createdAt: currentDate, - messageCount: 0, - followers: [], - files: [], - images: [], - discussionMessages: [], - isDeleted: false, + type: CommonFeedType.OptimisticDiscussion, circleVisibility, - circleVisibilityByCommon: null, - linkedCommonIds: [], - state: OptimisticFeedItemState.loading, - }, - circleVisibility, - }), + discussionId, + title: values.title, + content: JSON.stringify(values.content), + }), + ), ); dispatch( diff --git a/src/pages/common/components/CommonTabPanels/components/FeedTab/components/NewProposalCreation/NewProposalCreation.tsx b/src/pages/common/components/CommonTabPanels/components/FeedTab/components/NewProposalCreation/NewProposalCreation.tsx index 14a887527f..40ca182df1 100644 --- a/src/pages/common/components/CommonTabPanels/components/FeedTab/components/NewProposalCreation/NewProposalCreation.tsx +++ b/src/pages/common/components/CommonTabPanels/components/FeedTab/components/NewProposalCreation/NewProposalCreation.tsx @@ -1,10 +1,8 @@ import React, { FC, ReactNode, useCallback, useMemo } from "react"; import { useDispatch, useSelector } from "react-redux"; -import { Timestamp as FirestoreTimestamp } from "firebase/firestore"; import { v4 as uuidv4 } from "uuid"; import { selectUser } from "@/pages/Auth/store/selectors"; import { - DiscussionMessageOwnerType, PROPOSAL_TYPE_SELECT_OPTIONS, ProposalsTypes, } from "@/shared/constants"; @@ -15,10 +13,9 @@ import { CommonFeedType, CommonMember, Governance, - OptimisticFeedItemState, } from "@/shared/models"; import { parseStringToTextEditorValue } from "@/shared/ui-kit/TextEditor"; -import { getUserName } from "@/shared/utils"; +import { generateOptimisticFeedItem } from "@/shared/utils"; import { selectIsProposalCreationLoading, selectProposalCreationData, @@ -90,52 +87,19 @@ const NewProposalCreation: FC = (props) => { const proposalId = uuidv4(); const discussionId = uuidv4(); - const currentDate = FirestoreTimestamp.now(); - const optimisticFeedItemId = uuidv4(); dispatch( - commonActions.setOptimisticFeedItem({ - id: optimisticFeedItemId, - createdAt: currentDate, - updatedAt: currentDate, - isDeleted: false, - userId, - commonId: common.id, - data: { - type: CommonFeedType.OptimisticDiscussion, - id: discussionId, - discussionId: null, - lastMessage: { - userName: getUserName(user), - ownerId: userId, - content: JSON.stringify(values.content), - ownerType: DiscussionMessageOwnerType.User, - }, - hasFiles: false, - hasImages: false, - }, - optimisticData: { - id: discussionId, - title: values.title, - message: JSON.stringify(values.content), - ownerId: userId, + commonActions.setOptimisticFeedItem( + generateOptimisticFeedItem({ + userId, commonId: common.id, - lastMessage: currentDate, - updatedAt: currentDate, - createdAt: currentDate, - messageCount: 0, - followers: [], - files: [], - images: [], - discussionMessages: [], - isDeleted: false, + type: CommonFeedType.OptimisticProposal, circleVisibility: userCircleIds, - circleVisibilityByCommon: null, - linkedCommonIds: [], - state: OptimisticFeedItemState.loading, - }, - circleVisibility: userCircleIds, - }), + discussionId, + title: values.title, + content: JSON.stringify(values.content), + }), + ), ); switch (values.proposalType.value) { case ProposalsTypes.FUNDS_ALLOCATION: { @@ -158,25 +122,16 @@ const NewProposalCreation: FC = (props) => { break; } case ProposalsTypes.SURVEY: { - console.log( - "----getSurveyProposalPayload", - getSurveyProposalPayload( - values, - commonId, - proposalId, - discussionId, - ), + dispatch( + commonActions.createSurveyProposal.request({ + payload: getSurveyProposalPayload( + values, + commonId, + proposalId, + discussionId, + ), + }), ); - // dispatch( - // commonActions.createSurveyProposal.request({ - // payload: getSurveyProposalPayload( - // values, - // commonId, - // proposalId, - // discussionId, - // ), - // }), - // ); break; } } diff --git a/src/pages/common/components/FeedItem/FeedItem.tsx b/src/pages/common/components/FeedItem/FeedItem.tsx index b141051a28..287e405292 100644 --- a/src/pages/common/components/FeedItem/FeedItem.tsx +++ b/src/pages/common/components/FeedItem/FeedItem.tsx @@ -20,7 +20,7 @@ import { import { checkIsItemVisibleForUser } from "@/shared/utils"; import { useFeedItemSubscription } from "../../hooks"; import { DiscussionFeedCard } from "../DiscussionFeedCard"; -import { OptimisticDiscussionFeedCard } from "../OptimisticDiscussionFeedCard"; +import { OptimisticFeedCard } from "../OptimisticFeedCard"; import { ProposalFeedCard } from "../ProposalFeedCard"; import { ProjectFeedItem } from "./components"; import { useFeedItemContext } from "./context"; @@ -145,7 +145,6 @@ const FeedItem = forwardRef((props, ref) => { onFeedItemUnfollowed, ]); - const generalProps = useMemo( () => ({ ref, @@ -207,7 +206,6 @@ const FeedItem = forwardRef((props, ref) => { ], ); - if ( shouldCheckItemVisibility && !checkIsItemVisibleForUser({ @@ -221,11 +219,15 @@ const FeedItem = forwardRef((props, ref) => { return null; } - if (item.data.type === CommonFeedType.OptimisticDiscussion) { + if ( + item.data.type === CommonFeedType.OptimisticDiscussion || + item.data.type === CommonFeedType.OptimisticProposal + ) { return ( - ); } diff --git a/src/pages/common/components/OptimisticDiscussionFeedCard/components/LinkStreamModal/LinkStreamModal.module.scss b/src/pages/common/components/OptimisticDiscussionFeedCard/components/LinkStreamModal/LinkStreamModal.module.scss deleted file mode 100644 index b99c0e1f41..0000000000 --- a/src/pages/common/components/OptimisticDiscussionFeedCard/components/LinkStreamModal/LinkStreamModal.module.scss +++ /dev/null @@ -1,70 +0,0 @@ -@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; -} diff --git a/src/pages/common/components/OptimisticDiscussionFeedCard/components/LinkStreamModal/LinkStreamModal.tsx b/src/pages/common/components/OptimisticDiscussionFeedCard/components/LinkStreamModal/LinkStreamModal.tsx deleted file mode 100644 index b3d56b1a68..0000000000 --- a/src/pages/common/components/OptimisticDiscussionFeedCard/components/LinkStreamModal/LinkStreamModal.tsx +++ /dev/null @@ -1,113 +0,0 @@ -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 { LinkStreamProjects } from "./components"; -import styles from "./LinkStreamModal.module.scss"; - -interface LinkStreamModalProps { - isOpen: boolean; - onClose: () => void; - feedItemId: string; - title: string; - rootCommonId: string; - commonId: string; - originalCommonId: string; - linkedCommonIds?: string[]; - circleVisibility: string[]; -} - -const LinkStreamModal: FC = (props) => { - const { - isOpen, - onClose, - feedItemId, - title, - rootCommonId, - commonId, - originalCommonId, - linkedCommonIds = [], - circleVisibility, - } = 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 ; - } - - return ( - <> - -
- -
- - ); - }; - - useEffect(() => { - if (isStreamLinked) { - notify("Stream is successfully linked"); - onClose(); - } - }, [isStreamLinking, isStreamLinked]); - - return ( - - {renderContent()} - - ); -}; - -export default LinkStreamModal; diff --git a/src/pages/common/components/OptimisticDiscussionFeedCard/components/LinkStreamModal/components/LinkStreamProjects/LinkStreamProjects.tsx b/src/pages/common/components/OptimisticDiscussionFeedCard/components/LinkStreamModal/components/LinkStreamProjects/LinkStreamProjects.tsx deleted file mode 100644 index bdc8828423..0000000000 --- a/src/pages/common/components/OptimisticDiscussionFeedCard/components/LinkStreamModal/components/LinkStreamProjects/LinkStreamProjects.tsx +++ /dev/null @@ -1,46 +0,0 @@ -import React, { FC, useCallback } from "react"; -import { Item } from "@/shared/layouts/SidenavLayout/components/SidenavContent/components"; -import { ProjectsStateItem } from "@/store/states"; -import { Projects, ProjectsProps } from "../../../Projects"; -import { NameRightContent } from "./components"; - -interface LinkStreamProjects - extends Omit { - originalCommonId: string; - linkedCommonIds: string[]; - circleVisibility: string[]; -} - -const LinkStreamProjects: FC = (props) => { - const { rootCommonId, originalCommonId, linkedCommonIds, circleVisibility } = - props; - - const getAdditionalItemData = useCallback( - (projectsStateItem: ProjectsStateItem): Partial => { - const isAllowedToLink = - circleVisibility.length === 0 || - projectsStateItem.commonId === rootCommonId || - projectsStateItem.rootCommonId === rootCommonId; - - return { - disabled: - !isAllowedToLink || - !projectsStateItem.hasPermissionToLinkToHere || - projectsStateItem.commonId === originalCommonId || - linkedCommonIds.includes(projectsStateItem.commonId), - nameRightContent: ( - - ), - }; - }, - [originalCommonId, linkedCommonIds, rootCommonId, circleVisibility], - ); - - return ; -}; - -export default LinkStreamProjects; diff --git a/src/pages/common/components/OptimisticDiscussionFeedCard/components/LinkStreamModal/components/LinkStreamProjects/components/NameRightContent/NameRightContent.module.scss b/src/pages/common/components/OptimisticDiscussionFeedCard/components/LinkStreamModal/components/LinkStreamProjects/components/NameRightContent/NameRightContent.module.scss deleted file mode 100644 index e54f537a46..0000000000 --- a/src/pages/common/components/OptimisticDiscussionFeedCard/components/LinkStreamModal/components/LinkStreamProjects/components/NameRightContent/NameRightContent.module.scss +++ /dev/null @@ -1,11 +0,0 @@ -.originalText { - margin-left: 0.5rem; - font-weight: normal; - font-size: 0.875rem; - font-style: italic; -} - -.linkIcon { - flex-shrink: 0; - margin-left: 0.5rem; -} diff --git a/src/pages/common/components/OptimisticDiscussionFeedCard/components/LinkStreamModal/components/LinkStreamProjects/components/NameRightContent/NameRightContent.tsx b/src/pages/common/components/OptimisticDiscussionFeedCard/components/LinkStreamModal/components/LinkStreamProjects/components/NameRightContent/NameRightContent.tsx deleted file mode 100644 index 9d834a9512..0000000000 --- a/src/pages/common/components/OptimisticDiscussionFeedCard/components/LinkStreamModal/components/LinkStreamProjects/components/NameRightContent/NameRightContent.tsx +++ /dev/null @@ -1,25 +0,0 @@ -import React, { FC } from "react"; -import { Link4Icon } from "@/shared/icons"; -import { ProjectsStateItem } from "@/store/states"; -import styles from "./NameRightContent.module.scss"; - -interface NameRightContentProps { - projectsStateItem: ProjectsStateItem; - originalCommonId: string; - linkedCommonIds?: string[]; -} - -const NameRightContent: FC = (props) => { - const { projectsStateItem, originalCommonId, linkedCommonIds = [] } = props; - - if (projectsStateItem.commonId === originalCommonId) { - return original; - } - if (linkedCommonIds.includes(projectsStateItem.commonId)) { - return ; - } - - return null; -}; - -export default NameRightContent; diff --git a/src/pages/common/components/OptimisticDiscussionFeedCard/components/LinkStreamModal/components/LinkStreamProjects/components/NameRightContent/index.ts b/src/pages/common/components/OptimisticDiscussionFeedCard/components/LinkStreamModal/components/LinkStreamProjects/components/NameRightContent/index.ts deleted file mode 100644 index 3c341bfce7..0000000000 --- a/src/pages/common/components/OptimisticDiscussionFeedCard/components/LinkStreamModal/components/LinkStreamProjects/components/NameRightContent/index.ts +++ /dev/null @@ -1 +0,0 @@ -export { default as NameRightContent } from "./NameRightContent"; diff --git a/src/pages/common/components/OptimisticDiscussionFeedCard/components/LinkStreamModal/components/LinkStreamProjects/components/index.ts b/src/pages/common/components/OptimisticDiscussionFeedCard/components/LinkStreamModal/components/LinkStreamProjects/components/index.ts deleted file mode 100644 index f5705eab2d..0000000000 --- a/src/pages/common/components/OptimisticDiscussionFeedCard/components/LinkStreamModal/components/LinkStreamProjects/components/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from "./NameRightContent"; diff --git a/src/pages/common/components/OptimisticDiscussionFeedCard/components/LinkStreamModal/components/LinkStreamProjects/index.ts b/src/pages/common/components/OptimisticDiscussionFeedCard/components/LinkStreamModal/components/LinkStreamProjects/index.ts deleted file mode 100644 index f6931ce7fb..0000000000 --- a/src/pages/common/components/OptimisticDiscussionFeedCard/components/LinkStreamModal/components/LinkStreamProjects/index.ts +++ /dev/null @@ -1 +0,0 @@ -export { default as LinkStreamProjects } from "./LinkStreamProjects"; diff --git a/src/pages/common/components/OptimisticDiscussionFeedCard/components/LinkStreamModal/components/index.ts b/src/pages/common/components/OptimisticDiscussionFeedCard/components/LinkStreamModal/components/index.ts deleted file mode 100644 index 159661f715..0000000000 --- a/src/pages/common/components/OptimisticDiscussionFeedCard/components/LinkStreamModal/components/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from "./LinkStreamProjects"; diff --git a/src/pages/common/components/OptimisticDiscussionFeedCard/components/LinkStreamModal/index.ts b/src/pages/common/components/OptimisticDiscussionFeedCard/components/LinkStreamModal/index.ts deleted file mode 100644 index 79c9f12e5d..0000000000 --- a/src/pages/common/components/OptimisticDiscussionFeedCard/components/LinkStreamModal/index.ts +++ /dev/null @@ -1 +0,0 @@ -export { default as LinkStreamModal } from "./LinkStreamModal"; diff --git a/src/pages/common/components/OptimisticDiscussionFeedCard/components/MoveStreamModal/MoveStreamModal.module.scss b/src/pages/common/components/OptimisticDiscussionFeedCard/components/MoveStreamModal/MoveStreamModal.module.scss deleted file mode 100644 index b99c0e1f41..0000000000 --- a/src/pages/common/components/OptimisticDiscussionFeedCard/components/MoveStreamModal/MoveStreamModal.module.scss +++ /dev/null @@ -1,70 +0,0 @@ -@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; -} diff --git a/src/pages/common/components/OptimisticDiscussionFeedCard/components/MoveStreamModal/MoveStreamModal.tsx b/src/pages/common/components/OptimisticDiscussionFeedCard/components/MoveStreamModal/MoveStreamModal.tsx deleted file mode 100644 index 46dc541967..0000000000 --- a/src/pages/common/components/OptimisticDiscussionFeedCard/components/MoveStreamModal/MoveStreamModal.tsx +++ /dev/null @@ -1,110 +0,0 @@ -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 { useStreamMoving } from "@/shared/hooks/useCases"; -import { Button, ButtonVariant, Loader } from "@/shared/ui-kit"; -import { emptyFunction } from "@/shared/utils"; -import { MoveStreamProjects } from "./components"; -import styles from "./MoveStreamModal.module.scss"; - -interface MoveStreamModalProps { - isOpen: boolean; - onClose: () => void; - feedItemId: string; - title: string; - rootCommonId: string; - commonId: string; - originalCommonId: string; - circleVisibility: string[]; -} - -const MoveStreamModal: FC = (props) => { - const { - isOpen, - onClose, - feedItemId, - title, - rootCommonId, - commonId, - originalCommonId, - circleVisibility, - } = props; - const { notify } = useNotification(); - const { isStreamMoving, isStreamMoved, moveStream } = useStreamMoving(); - const [activeItemId, setActiveItemId] = useState(""); - const user = useSelector(selectUser()); - const userId = user?.uid; - - const handleSubmit = () => { - if (!userId) { - return; - } - - moveStream({ - userId, - feedObjectId: feedItemId, - sourceCommonId: commonId, - targetCommonId: activeItemId, - }); - }; - - const renderContent = (): ReactElement => { - if (isStreamMoving) { - return ; - } - - return ( - <> - -
- -
- - ); - }; - - useEffect(() => { - if (isStreamMoved) { - notify("Stream is successfully moved"); - onClose(); - } - }, [isStreamMoving, isStreamMoved]); - - return ( - - {renderContent()} - - ); -}; - -export default MoveStreamModal; diff --git a/src/pages/common/components/OptimisticDiscussionFeedCard/components/MoveStreamModal/components/MoveStreamProjects/MoveStreamProjects.tsx b/src/pages/common/components/OptimisticDiscussionFeedCard/components/MoveStreamModal/components/MoveStreamProjects/MoveStreamProjects.tsx deleted file mode 100644 index 78e25f4148..0000000000 --- a/src/pages/common/components/OptimisticDiscussionFeedCard/components/MoveStreamModal/components/MoveStreamProjects/MoveStreamProjects.tsx +++ /dev/null @@ -1,42 +0,0 @@ -import React, { FC, useCallback } from "react"; -import { Item } from "@/shared/layouts/SidenavLayout/components/SidenavContent/components"; -import { ProjectsStateItem } from "@/store/states"; -import { NameRightContent } from "../../../LinkStreamModal/components/LinkStreamProjects/components"; -import { Projects, ProjectsProps } from "../../../Projects"; - -interface MoveStreamProjectsProps - extends Omit { - originalCommonId: string; - circleVisibility: string[]; -} - -const MoveStreamProjects: FC = (props) => { - const { rootCommonId, originalCommonId, circleVisibility } = props; - - const getAdditionalItemData = useCallback( - (projectsStateItem: ProjectsStateItem): Partial => { - const isAllowedToMove = - circleVisibility.length === 0 || - projectsStateItem.commonId === rootCommonId || - projectsStateItem.rootCommonId === rootCommonId; - - return { - disabled: - !isAllowedToMove || - !projectsStateItem.hasPermissionToMoveToHere || - projectsStateItem.commonId === originalCommonId, - nameRightContent: ( - - ), - }; - }, - [originalCommonId, rootCommonId, circleVisibility], - ); - - return ; -}; - -export default MoveStreamProjects; diff --git a/src/pages/common/components/OptimisticDiscussionFeedCard/components/MoveStreamModal/components/MoveStreamProjects/index.ts b/src/pages/common/components/OptimisticDiscussionFeedCard/components/MoveStreamModal/components/MoveStreamProjects/index.ts deleted file mode 100644 index cd9ba5fc65..0000000000 --- a/src/pages/common/components/OptimisticDiscussionFeedCard/components/MoveStreamModal/components/MoveStreamProjects/index.ts +++ /dev/null @@ -1 +0,0 @@ -export { default as MoveStreamProjects } from "./MoveStreamProjects"; diff --git a/src/pages/common/components/OptimisticDiscussionFeedCard/components/MoveStreamModal/components/index.ts b/src/pages/common/components/OptimisticDiscussionFeedCard/components/MoveStreamModal/components/index.ts deleted file mode 100644 index 35fef4926d..0000000000 --- a/src/pages/common/components/OptimisticDiscussionFeedCard/components/MoveStreamModal/components/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from "./MoveStreamProjects"; diff --git a/src/pages/common/components/OptimisticDiscussionFeedCard/components/MoveStreamModal/index.ts b/src/pages/common/components/OptimisticDiscussionFeedCard/components/MoveStreamModal/index.ts deleted file mode 100644 index 219e936dd5..0000000000 --- a/src/pages/common/components/OptimisticDiscussionFeedCard/components/MoveStreamModal/index.ts +++ /dev/null @@ -1 +0,0 @@ -export { default as MoveStreamModal } from "./MoveStreamModal"; diff --git a/src/pages/common/components/OptimisticDiscussionFeedCard/components/OptimisticDiscussionFeedCardContent/index.ts b/src/pages/common/components/OptimisticDiscussionFeedCard/components/OptimisticDiscussionFeedCardContent/index.ts deleted file mode 100644 index c38bf83825..0000000000 --- a/src/pages/common/components/OptimisticDiscussionFeedCard/components/OptimisticDiscussionFeedCardContent/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from "./OptimisticDiscussionFeedCardContent"; \ No newline at end of file diff --git a/src/pages/common/components/OptimisticDiscussionFeedCard/components/Projects/Projects.module.scss b/src/pages/common/components/OptimisticDiscussionFeedCard/components/Projects/Projects.module.scss deleted file mode 100644 index 9776f0251b..0000000000 --- a/src/pages/common/components/OptimisticDiscussionFeedCard/components/Projects/Projects.module.scss +++ /dev/null @@ -1,71 +0,0 @@ -@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(--hover-fill); - --item-text-color: var(--primary-text); - } - - @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; -} diff --git a/src/pages/common/components/OptimisticDiscussionFeedCard/components/Projects/Projects.tsx b/src/pages/common/components/OptimisticDiscussionFeedCard/components/Projects/Projects.tsx deleted file mode 100644 index ef60d43e99..0000000000 --- a/src/pages/common/components/OptimisticDiscussionFeedCard/components/Projects/Projects.tsx +++ /dev/null @@ -1,86 +0,0 @@ -import React, { FC, ReactNode, useEffect, useMemo, useState } from "react"; -import { LOADER_APPEARANCE_DELAY } from "@/shared/constants"; -import { TreeItemTriggerStyles } from "@/shared/layouts"; -import { ProjectsTree } from "@/shared/layouts/CommonSidenavLayout/components/SidenavContent/components/ProjectsTree"; -import { Item } from "@/shared/layouts/SidenavLayout/components/SidenavContent/components"; -import { Loader } from "@/shared/ui-kit"; -import { ProjectsStateItem } from "@/store/states"; -import { useProjectsData } from "./hooks"; -import styles from "./Projects.module.scss"; - -export interface ProjectsProps { - rootCommonId: string; - commonId: string; - activeItemId: string; - onActiveItemId: (activeItemId: string) => void; - renderNoItemsInfo?: () => ReactNode; - getAdditionalItemData?: ( - projectsStateItem: ProjectsStateItem, - ) => Partial; -} - -const Projects: FC = (props) => { - const { - activeItemId, - onActiveItemId, - renderNoItemsInfo, - getAdditionalItemData, - } = props; - const [currentCommonId, setCurrentCommonId] = useState(props.rootCommonId); - const { - parentItem, - areCommonsLoading, - areProjectsLoading, - commons, - items, - activeItem, - parentItemIds, - } = useProjectsData({ - currentCommonId, - activeItemId, - getAdditionalItemData, - }); - const treeItemTriggerStyles = useMemo( - () => ({ - container: styles.projectsTreeItemTriggerClassName, - containerActive: styles.projectsTreeItemTriggerActiveClassName, - name: styles.projectsTreeItemTriggerNameClassName, - image: styles.projectsTreeItemTriggerImageClassName, - imageNonRounded: styles.projectsTreeItemTriggerImageNonRoundedClassName, - }), - [], - ); - - useEffect(() => { - onActiveItemId(""); - }, [currentCommonId]); - - if (!parentItem) { - return areCommonsLoading ? ( - - ) : ( - <>{renderNoItemsInfo?.() || null} - ); - } - - return ( - - ); -}; - -export default Projects; diff --git a/src/pages/common/components/OptimisticDiscussionFeedCard/components/Projects/hooks/index.ts b/src/pages/common/components/OptimisticDiscussionFeedCard/components/Projects/hooks/index.ts deleted file mode 100644 index ced5d7bb9c..0000000000 --- a/src/pages/common/components/OptimisticDiscussionFeedCard/components/Projects/hooks/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from "./useProjectsData"; diff --git a/src/pages/common/components/OptimisticDiscussionFeedCard/components/Projects/hooks/useProjectsData.ts b/src/pages/common/components/OptimisticDiscussionFeedCard/components/Projects/hooks/useProjectsData.ts deleted file mode 100644 index 1bb8ed7c8e..0000000000 --- a/src/pages/common/components/OptimisticDiscussionFeedCard/components/Projects/hooks/useProjectsData.ts +++ /dev/null @@ -1,127 +0,0 @@ -import { useEffect, useMemo, useRef } from "react"; -import { useSelector } from "react-redux"; -import { selectUser } from "@/pages/Auth/store/selectors"; -import { useLoadingState } from "@/shared/hooks"; -import { - generateProjectsTreeItems, - getItemById, - getItemFromProjectsStateItem, - getParentItemIds, - Item, -} from "@/shared/layouts/SidenavLayout/components/SidenavContent/components"; -import { - ProjectsStateItem, - selectCommonLayoutCommonsState, -} from "@/store/states"; -import { getProjects as getProjectsUtil } from "@/store/states/commonLayout/saga/utils"; - -interface ProjectsInfo { - currentCommonId: string; - activeItemId: string; - getAdditionalItemData?: ( - projectsStateItem: ProjectsStateItem, - ) => Partial; -} - -interface Return { - parentItem: Item | null; - areCommonsLoading: boolean; - areProjectsLoading: boolean; - commons: ProjectsStateItem[]; - items: Item[]; - activeItem: Item | null; - parentItemIds: string[]; -} - -const generateItemCommonPagePath = () => ""; - -export const useProjectsData = (projectsInfo: ProjectsInfo): Return => { - const { currentCommonId, activeItemId, getAdditionalItemData } = projectsInfo; - const currentCommonIdRef = useRef(currentCommonId); - currentCommonIdRef.current = currentCommonId; - const { commons, areCommonsLoading } = useSelector( - selectCommonLayoutCommonsState, - ); - const user = useSelector(selectUser()); - const userId = user?.uid; - const [{ data: projects, loading: areProjectsLoading }, setProjectsState] = - useLoadingState([]); - const currentCommon = commons.find( - ({ commonId }) => commonId === currentCommonId, - ); - - const parentItem = useMemo( - () => - currentCommon - ? getItemFromProjectsStateItem( - currentCommon, - generateItemCommonPagePath, - undefined, - getAdditionalItemData, - ) - : null, - [currentCommon, getAdditionalItemData], - ); - const items = useMemo(() => { - const [item] = generateProjectsTreeItems( - currentCommon ? projects.concat(currentCommon) : projects, - generateItemCommonPagePath, - getAdditionalItemData, - ); - - return item?.items || []; - }, [currentCommon, projects, getAdditionalItemData]); - const activeItem = getItemById( - activeItemId, - parentItem ? [parentItem, ...items] : items, - ); - const parentItemIds = getParentItemIds( - activeItemId, - currentCommon ? projects.concat(currentCommon) : projects, - ); - - useEffect(() => { - let isRelevantLoading = true; - - (async () => { - try { - setProjectsState({ - data: [], - loading: true, - fetched: false, - }); - const projectsData = await getProjectsUtil(currentCommonId, userId); - - if (isRelevantLoading) { - setProjectsState({ - data: projectsData, - loading: false, - fetched: true, - }); - } - } catch (err) { - if (isRelevantLoading) { - setProjectsState({ - data: [], - loading: false, - fetched: true, - }); - } - } - })(); - - return () => { - isRelevantLoading = false; - }; - }, [currentCommonId]); - - return { - parentItem, - areCommonsLoading, - areProjectsLoading, - commons, - items, - activeItem, - parentItemIds, - }; -}; diff --git a/src/pages/common/components/OptimisticDiscussionFeedCard/components/Projects/index.ts b/src/pages/common/components/OptimisticDiscussionFeedCard/components/Projects/index.ts deleted file mode 100644 index 6ca2075a54..0000000000 --- a/src/pages/common/components/OptimisticDiscussionFeedCard/components/Projects/index.ts +++ /dev/null @@ -1,2 +0,0 @@ -export { default as Projects } from "./Projects"; -export type { ProjectsProps } from "./Projects"; diff --git a/src/pages/common/components/OptimisticDiscussionFeedCard/components/UnlinkStreamModal/UnlinkStreamModal.module.scss b/src/pages/common/components/OptimisticDiscussionFeedCard/components/UnlinkStreamModal/UnlinkStreamModal.module.scss deleted file mode 100644 index 3cf05ba9e8..0000000000 --- a/src/pages/common/components/OptimisticDiscussionFeedCard/components/UnlinkStreamModal/UnlinkStreamModal.module.scss +++ /dev/null @@ -1,39 +0,0 @@ -@import "../../../../../../constants"; -@import "../../../../../../styles/sizes"; - -.modal { - max-width: 31.875rem; -} - -.buttonsWrapper { - display: flex; - margin-top: 1rem; - justify-content: flex-end; - - @include tablet { - flex-direction: column; - margin-top: 100%; - } -} - -.button { - width: 10rem; - - @include tablet { - width: 100%; - } -} - -.unlinkButton { - margin-left: 1.5rem; - - @include tablet { - margin-left: unset; - margin-top: 1rem; - } -} - -.errorText { - font-size: $xsmall; - color: $red; -} diff --git a/src/pages/common/components/OptimisticDiscussionFeedCard/components/UnlinkStreamModal/UnlinkStreamModal.tsx b/src/pages/common/components/OptimisticDiscussionFeedCard/components/UnlinkStreamModal/UnlinkStreamModal.tsx deleted file mode 100644 index 76f0886970..0000000000 --- a/src/pages/common/components/OptimisticDiscussionFeedCard/components/UnlinkStreamModal/UnlinkStreamModal.tsx +++ /dev/null @@ -1,116 +0,0 @@ -import React, { FC, useRef, useState } from "react"; -import { useSelector } from "react-redux"; -import { CancelTokenSource } from "axios"; -import classNames from "classnames"; -import { isError } from "lodash"; -import { selectUser } from "@/pages/Auth/store/selectors"; -import { - CommonFeedService, - Logger, - getCancelTokenSource, - isRequestCancelled, -} from "@/services"; -import { Modal } from "@/shared/components"; -import { useNotification } from "@/shared/hooks"; -import { Button, ButtonVariant } from "@/shared/ui-kit"; -import { emptyFunction } from "@/shared/utils"; -import styles from "./UnlinkStreamModal.module.scss"; - -interface UnlinkStreamModalProps { - isOpen: boolean; - onClose: () => void; - feedItemId: string; - title: string; - commonId: string; - commonName: string; -} - -const UnlinkStreamModal: FC = (props) => { - const { isOpen, onClose, feedItemId, title, commonId, commonName } = props; - const { notify } = useNotification(); - const [isUnlinking, setIsUnlinking] = useState(false); - const [errorText, setErrorText] = useState(""); - const cancelTokenRef = useRef(null); - const user = useSelector(selectUser()); - const userId = user?.uid; - - const handleSubmit = async () => { - if (!userId) { - return; - } - - setErrorText(""); - setIsUnlinking(true); - - try { - if (cancelTokenRef.current) { - cancelTokenRef.current.cancel(); - } - - cancelTokenRef.current = getCancelTokenSource(); - - await CommonFeedService.unlinkStream( - { - feedObjectId: feedItemId, - commonId: commonId, - userId: userId, - }, - { - cancelToken: cancelTokenRef.current.token, - }, - ); - - cancelTokenRef.current = null; - - notify("Stream is successfully unlinked"); - setIsUnlinking(false); - onClose(); - } catch (error) { - if (!isRequestCancelled(error)) { - Logger.error(error); - cancelTokenRef.current = null; - } - setIsUnlinking(false); - setErrorText(isError(error) ? error.message : "Something went wrong..."); - } - }; - - return ( - -
- This stream is linked in multiple spaces.
- If you proceed, it will be removed from "{commonName}" only and will - remain in other locations. Do you want to continue? -
- - -
- {errorText && {errorText}} -
-
- ); -}; - -export default UnlinkStreamModal; diff --git a/src/pages/common/components/OptimisticDiscussionFeedCard/components/UnlinkStreamModal/index.ts b/src/pages/common/components/OptimisticDiscussionFeedCard/components/UnlinkStreamModal/index.ts deleted file mode 100644 index a8902e6f40..0000000000 --- a/src/pages/common/components/OptimisticDiscussionFeedCard/components/UnlinkStreamModal/index.ts +++ /dev/null @@ -1 +0,0 @@ -export { default as UnlinkStreamModal } from "./UnlinkStreamModal"; diff --git a/src/pages/common/components/OptimisticDiscussionFeedCard/components/index.ts b/src/pages/common/components/OptimisticDiscussionFeedCard/components/index.ts deleted file mode 100644 index 605eb3dc70..0000000000 --- a/src/pages/common/components/OptimisticDiscussionFeedCard/components/index.ts +++ /dev/null @@ -1,4 +0,0 @@ -export * from "./LinkStreamModal"; -export * from "./MoveStreamModal"; -export * from "./UnlinkStreamModal"; -export * from "./OptimisticDiscussionFeedCardContent"; diff --git a/src/pages/common/components/OptimisticDiscussionFeedCard/index.ts b/src/pages/common/components/OptimisticDiscussionFeedCard/index.ts deleted file mode 100644 index e3e2245f56..0000000000 --- a/src/pages/common/components/OptimisticDiscussionFeedCard/index.ts +++ /dev/null @@ -1 +0,0 @@ -export { default as OptimisticDiscussionFeedCard } from "./OptimisticDiscussionFeedCard"; diff --git a/src/pages/common/components/OptimisticDiscussionFeedCard/utils/checkIsEditItemAllowed.ts b/src/pages/common/components/OptimisticDiscussionFeedCard/utils/checkIsEditItemAllowed.ts deleted file mode 100644 index 085874a155..0000000000 --- a/src/pages/common/components/OptimisticDiscussionFeedCard/utils/checkIsEditItemAllowed.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { CommonFeedType, PredefinedTypes } from "@/shared/models"; -import { GetAllowedItemsOptions } from "../../FeedItem"; - -export function checkIsEditItemAllowed(options: GetAllowedItemsOptions) { - if (!options.commonMember) return false; - if (options.discussion?.predefinedType === PredefinedTypes.General) - return false; - - return ( - options.commonMember.userId === options.discussion?.ownerId && - options.feedItem?.data.type === CommonFeedType.Discussion - ); -} diff --git a/src/pages/common/components/OptimisticDiscussionFeedCard/utils/checkIsLinkToAllowed.ts b/src/pages/common/components/OptimisticDiscussionFeedCard/utils/checkIsLinkToAllowed.ts deleted file mode 100644 index 7bc6b04502..0000000000 --- a/src/pages/common/components/OptimisticDiscussionFeedCard/utils/checkIsLinkToAllowed.ts +++ /dev/null @@ -1,32 +0,0 @@ -import { GovernanceActions } from "@/shared/constants"; -import { getCirclesWithLowestTier, hasPermission } from "@/shared/utils"; -import { GetAllowedItemsOptions } from "../../FeedItem"; - -export const checkIsLinkToAllowed = ( - options: GetAllowedItemsOptions, -): boolean => { - if (!options.commonMember) { - return false; - } - - const circlesWithLowestTier = getCirclesWithLowestTier( - Object.values(options.governanceCircles || {}), - ); - const discussionCircleVisibility = - options.discussion?.circleVisibilityByCommon?.[options.commonId || ""] || - []; - - return ( - (discussionCircleVisibility.length === 0 || - discussionCircleVisibility.some((circleId) => - circlesWithLowestTier.some((circle) => circle.id === circleId), - )) && - hasPermission({ - commonMember: options.commonMember, - governance: { - circles: options.governanceCircles || {}, - }, - action: GovernanceActions.LINK_FROM_HERE, - }) - ); -}; diff --git a/src/pages/common/components/OptimisticDiscussionFeedCard/utils/checkIsMoveToAllowed.ts b/src/pages/common/components/OptimisticDiscussionFeedCard/utils/checkIsMoveToAllowed.ts deleted file mode 100644 index 1175daaeeb..0000000000 --- a/src/pages/common/components/OptimisticDiscussionFeedCard/utils/checkIsMoveToAllowed.ts +++ /dev/null @@ -1,28 +0,0 @@ -import { GovernanceActions } from "@/shared/constants"; -import { PredefinedTypes } from "@/shared/models"; -import { hasPermission } from "@/shared/utils"; -import { GetAllowedItemsOptions } from "../../FeedItem"; - -export const checkIsMoveToAllowed = ( - options: GetAllowedItemsOptions, -): boolean => { - if ( - !options.commonMember || - options.discussion?.predefinedType === PredefinedTypes.General - ) { - return false; - } - - const linkedCommonIds = options.discussion?.linkedCommonIds || []; - - return ( - linkedCommonIds.length === 0 && - hasPermission({ - commonMember: options.commonMember, - governance: { - circles: options.governanceCircles || {}, - }, - action: GovernanceActions.MOVE_FROM_HERE, - }) - ); -}; diff --git a/src/pages/common/components/OptimisticDiscussionFeedCard/utils/checkIsPinUnpinAllowed.ts b/src/pages/common/components/OptimisticDiscussionFeedCard/utils/checkIsPinUnpinAllowed.ts deleted file mode 100644 index ee5d572477..0000000000 --- a/src/pages/common/components/OptimisticDiscussionFeedCard/utils/checkIsPinUnpinAllowed.ts +++ /dev/null @@ -1,44 +0,0 @@ -import { GovernanceActions } from "@/shared/constants"; -import { PredefinedTypes } from "@/shared/models"; -import { hasPermission } from "@/shared/utils"; -import { FeedItemPinAction, GetAllowedItemsOptions } from "../../FeedItem"; - -const PINNED_ITEMS_LIMIT = 7; - -export function checkIsPinUnpinAllowed( - action: FeedItemPinAction, - options: GetAllowedItemsOptions, -) { - const { feedItem, commonMember, discussion, pinnedFeedItems = [] } = options; - const isDiscussionPinned = pinnedFeedItems.some( - (pinnedFeedItem) => pinnedFeedItem.feedObjectId === feedItem?.id, - ); - - if (!commonMember) { - return false; - } - - if (action === FeedItemPinAction.Pin) { - const hasReachedPinLimit = pinnedFeedItems.length >= PINNED_ITEMS_LIMIT; - - if (isDiscussionPinned || hasReachedPinLimit) { - return false; - } - } else if ( - action === FeedItemPinAction.Unpin && - (!isDiscussionPinned || - discussion?.predefinedType === PredefinedTypes.General) - ) { - return false; - } - - const isAllowed = hasPermission({ - commonMember, - governance: { - circles: options.governanceCircles || {}, - }, - action: GovernanceActions.PIN_OR_UNPIN_FEED_ITEMS, - }); - - return isAllowed; -} diff --git a/src/pages/common/components/OptimisticDiscussionFeedCard/utils/checkIsRemoveDiscussionAllowed.ts b/src/pages/common/components/OptimisticDiscussionFeedCard/utils/checkIsRemoveDiscussionAllowed.ts deleted file mode 100644 index 4977af6973..0000000000 --- a/src/pages/common/components/OptimisticDiscussionFeedCard/utils/checkIsRemoveDiscussionAllowed.ts +++ /dev/null @@ -1,38 +0,0 @@ -import { GovernanceActions } from "@/shared/constants"; -import { PredefinedTypes } from "@/shared/models"; -import { getCirclesWithHighestTier, hasPermission } from "@/shared/utils"; -import { GetAllowedItemsOptions } from "../../FeedItem"; - -export function checkIsRemoveDiscussionAllowed( - options: GetAllowedItemsOptions, -): boolean { - const { commonMember } = options; - - if ( - !commonMember || - options.discussion?.predefinedType === PredefinedTypes.General - ) { - return false; - } - - const circles = options.governanceCircles || {}; - const isDiscussionOwner = commonMember.userId === options.discussion?.ownerId; - const hasPermissionToRemoveDiscussion = - hasPermission({ - commonMember, - governance: { circles }, - action: GovernanceActions.HIDE_OR_UNHIDE_DISCUSSION, - }) || isDiscussionOwner; - - if (!options.discussion?.proposalId) { - return hasPermissionToRemoveDiscussion; - } - - const circlesWithHighestTier = getCirclesWithHighestTier( - Object.values(circles), - ); - - return circlesWithHighestTier.some((circle) => - commonMember.circleIds.includes(circle.id), - ); -} diff --git a/src/pages/common/components/OptimisticDiscussionFeedCard/OptimisticDiscussionFeedCard.tsx b/src/pages/common/components/OptimisticFeedCard/OptimisticFeedCard.tsx similarity index 96% rename from src/pages/common/components/OptimisticDiscussionFeedCard/OptimisticDiscussionFeedCard.tsx rename to src/pages/common/components/OptimisticFeedCard/OptimisticFeedCard.tsx index 9b774f85c3..f0128b4fb3 100644 --- a/src/pages/common/components/OptimisticDiscussionFeedCard/OptimisticDiscussionFeedCard.tsx +++ b/src/pages/common/components/OptimisticFeedCard/OptimisticFeedCard.tsx @@ -21,6 +21,7 @@ import { FeedLayoutItemChangeData } from "@/shared/interfaces"; import { Common, CommonFeed, + CommonFeedType, CommonMember, CommonNotion, DirectParent, @@ -36,9 +37,9 @@ import { GetLastMessageOptions, GetNonAllowedItemsOptions, } from "../FeedItem"; -import { OptimisticDiscussionFeedCardContent } from "./components"; +import { OptimisticFeedCardContent } from "./components"; -interface OptimisticDiscussionFeedCardProps { +interface OptimisticFeedCardProps { item: CommonFeed; governanceCircles?: Governance["circles"]; isMobileVersion?: boolean; @@ -65,11 +66,12 @@ interface OptimisticDiscussionFeedCardProps { onUserClick?: (userId: string) => void; onFeedItemClick: (feedItemId: string) => void; onInternalLinkClick: (data: InternalLinkData) => void; + type: CommonFeedType; } -const OptimisticDiscussionFeedCard = forwardRef< +const OptimisticFeedCard = forwardRef< FeedItemRef, - OptimisticDiscussionFeedCardProps + OptimisticFeedCardProps >((props, ref) => { const { setChatItem, @@ -98,6 +100,7 @@ const OptimisticDiscussionFeedCard = forwardRef< onUserClick, onFeedItemClick, onInternalLinkClick, + type, } = props; const { fetchUser: fetchDiscussionCreator, data: discussionCreator } = @@ -299,7 +302,7 @@ const OptimisticDiscussionFeedCard = forwardRef< linkedCommonIds={[]} > {(isExpanded || isActive) && ( - )} @@ -323,4 +327,4 @@ const OptimisticDiscussionFeedCard = forwardRef< ); }); -export default OptimisticDiscussionFeedCard; +export default OptimisticFeedCard; diff --git a/src/pages/common/components/OptimisticDiscussionFeedCard/components/OptimisticDiscussionFeedCardContent/OptimisticDiscussionFeedCardContent.tsx b/src/pages/common/components/OptimisticFeedCard/components/OptimisticFeedCardContent/OptimisticFeedCardContent.tsx similarity index 89% rename from src/pages/common/components/OptimisticDiscussionFeedCard/components/OptimisticDiscussionFeedCardContent/OptimisticDiscussionFeedCardContent.tsx rename to src/pages/common/components/OptimisticFeedCard/components/OptimisticFeedCardContent/OptimisticFeedCardContent.tsx index 8bab55824e..8bd1e086a7 100644 --- a/src/pages/common/components/OptimisticDiscussionFeedCard/components/OptimisticDiscussionFeedCardContent/OptimisticDiscussionFeedCardContent.tsx +++ b/src/pages/common/components/OptimisticFeedCard/components/OptimisticFeedCardContent/OptimisticFeedCardContent.tsx @@ -3,6 +3,7 @@ import { ContextMenuItem } from "@/shared/interfaces"; import { Common, CommonFeed, + CommonFeedType, DirectParent, DiscussionNotion, Governance, @@ -17,7 +18,7 @@ import { getVisibilityString, } from "../../../FeedCard"; -interface OptimisticDiscussionFeedCardContentProps { +interface OptimisticFeedCardContentProps { item: CommonFeed; governanceCircles?: Governance["circles"]; isMobileVersion?: boolean; @@ -34,10 +35,11 @@ interface OptimisticDiscussionFeedCardContentProps { handleOpenChat: () => void; onHover: (isMouseEnter: boolean) => void; isLoading: boolean; + type?: CommonFeedType; } -export function OptimisticDiscussionFeedCardContent( - props: OptimisticDiscussionFeedCardContentProps, +export function OptimisticFeedCardContent( + props: OptimisticFeedCardContentProps, ) { const { item, @@ -56,6 +58,7 @@ export function OptimisticDiscussionFeedCardContent( isLoading, discussionMessage, discussionImages, + type, } = props; if (isLoading || !commonId) { @@ -80,7 +83,9 @@ export function OptimisticDiscussionFeedCardContent( /> } - type={isHome ? "Home" : "Discussion"} + type={ + type === CommonFeedType.OptimisticProposal ? "Proposal" : "Discussion" + } circleVisibility={circleVisibility} menuItems={menuItems} isMobileVersion={isMobileVersion} diff --git a/src/pages/common/components/OptimisticFeedCard/components/OptimisticFeedCardContent/index.ts b/src/pages/common/components/OptimisticFeedCard/components/OptimisticFeedCardContent/index.ts new file mode 100644 index 0000000000..45174ea033 --- /dev/null +++ b/src/pages/common/components/OptimisticFeedCard/components/OptimisticFeedCardContent/index.ts @@ -0,0 +1 @@ +export * from "./OptimisticFeedCardContent"; \ No newline at end of file diff --git a/src/pages/common/components/OptimisticFeedCard/components/index.ts b/src/pages/common/components/OptimisticFeedCard/components/index.ts new file mode 100644 index 0000000000..b2b3ef2850 --- /dev/null +++ b/src/pages/common/components/OptimisticFeedCard/components/index.ts @@ -0,0 +1 @@ +export * from "./OptimisticFeedCardContent"; diff --git a/src/pages/common/components/OptimisticDiscussionFeedCard/hooks/index.ts b/src/pages/common/components/OptimisticFeedCard/hooks/index.ts similarity index 100% rename from src/pages/common/components/OptimisticDiscussionFeedCard/hooks/index.ts rename to src/pages/common/components/OptimisticFeedCard/hooks/index.ts diff --git a/src/pages/common/components/OptimisticDiscussionFeedCard/hooks/useMenuItems.tsx b/src/pages/common/components/OptimisticFeedCard/hooks/useMenuItems.tsx similarity index 100% rename from src/pages/common/components/OptimisticDiscussionFeedCard/hooks/useMenuItems.tsx rename to src/pages/common/components/OptimisticFeedCard/hooks/useMenuItems.tsx diff --git a/src/pages/common/components/OptimisticFeedCard/index.ts b/src/pages/common/components/OptimisticFeedCard/index.ts new file mode 100644 index 0000000000..8671496d94 --- /dev/null +++ b/src/pages/common/components/OptimisticFeedCard/index.ts @@ -0,0 +1 @@ +export { default as OptimisticFeedCard } from "./OptimisticFeedCard"; diff --git a/src/pages/common/components/OptimisticDiscussionFeedCard/utils/getAllowedItems.ts b/src/pages/common/components/OptimisticFeedCard/utils/getAllowedItems.ts similarity index 100% rename from src/pages/common/components/OptimisticDiscussionFeedCard/utils/getAllowedItems.ts rename to src/pages/common/components/OptimisticFeedCard/utils/getAllowedItems.ts diff --git a/src/pages/common/components/OptimisticDiscussionFeedCard/utils/index.ts b/src/pages/common/components/OptimisticFeedCard/utils/index.ts similarity index 100% rename from src/pages/common/components/OptimisticDiscussionFeedCard/utils/index.ts rename to src/pages/common/components/OptimisticFeedCard/utils/index.ts diff --git a/src/pages/common/components/index.ts b/src/pages/common/components/index.ts index 5007e04803..5222245c9a 100644 --- a/src/pages/common/components/index.ts +++ b/src/pages/common/components/index.ts @@ -3,7 +3,7 @@ export * from "./CommonMobileModal"; export * from "./CommonTabPanels"; export * from "./CommonTopNavigation"; export * from "./DiscussionFeedCard"; -export * from "./OptimisticDiscussionFeedCard"; +export * from "./OptimisticFeedCard"; export * from "./FeedCard"; export * from "./FeedItem"; export * from "./FeedItems"; diff --git a/src/shared/hooks/useCases/useCommonFeedItems.ts b/src/shared/hooks/useCases/useCommonFeedItems.ts index 76c3d94640..97d6c1a023 100644 --- a/src/shared/hooks/useCases/useCommonFeedItems.ts +++ b/src/shared/hooks/useCases/useCommonFeedItems.ts @@ -62,13 +62,14 @@ export const useCommonFeedItems = ( } ); data.forEach((item) => { - const discussionId = item.commonFeedItem.data.id; + const discussionId = item.commonFeedItem.data.discussionId ?? item.commonFeedItem.data.id; if(optItemIds.includes(discussionId)) { dispatch(commonActions.removeOptimisticFeedItemState({id: discussionId})) } }) + console.log('-----data',data); const finalData = idsForNotListeningRef.current.length > 0 ? data.filter( diff --git a/src/shared/models/CommonFeed.tsx b/src/shared/models/CommonFeed.tsx index aeb4660d50..3f56f79986 100644 --- a/src/shared/models/CommonFeed.tsx +++ b/src/shared/models/CommonFeed.tsx @@ -7,6 +7,7 @@ export enum CommonFeedType { Proposal = "Proposal", Discussion = "Discussion", OptimisticDiscussion = "OptimisticDiscussion", + OptimisticProposal = "OptimisticProposal", Project = "Project", PayIn = "PayIn", ProjectCreation = "ProjectCreation", diff --git a/src/shared/utils/generateOptimisticFeedItem.ts b/src/shared/utils/generateOptimisticFeedItem.ts new file mode 100644 index 0000000000..615c42779e --- /dev/null +++ b/src/shared/utils/generateOptimisticFeedItem.ts @@ -0,0 +1,63 @@ +import { Timestamp as FirestoreTimestamp } from "firebase/firestore"; +import { v4 as uuidv4 } from "uuid"; +import { CommonFeed, CommonFeedType, OptimisticFeedItemState } from "../models"; + +interface GenerateOptimisticFeedItemPayload { + userId: string; + discussionId: string; + commonId: string; + type: CommonFeedType, + title: string; + content: string; + circleVisibility: string[]; +} + +export const generateOptimisticFeedItem = ({ + userId, + discussionId, + commonId, + type, + title, + content, + circleVisibility +}: GenerateOptimisticFeedItemPayload): CommonFeed => { + + const optimisticFeedItemId = uuidv4(); + const currentDate = FirestoreTimestamp.now(); + return { + id: optimisticFeedItemId, + createdAt: currentDate, + updatedAt: currentDate, + isDeleted: false, + userId, + commonId, + data: { + type, + id: discussionId, + discussionId: null, + hasFiles: false, + hasImages: false, + }, + optimisticData: { + id: discussionId, + title: title, + message: content, + ownerId: userId, + commonId, + lastMessage: currentDate, + updatedAt: currentDate, + createdAt: currentDate, + messageCount: 0, + followers: [], + files: [], + images: [], + discussionMessages: [], + isDeleted: false, + circleVisibility, + circleVisibilityByCommon: null, + linkedCommonIds: [], + state: OptimisticFeedItemState.loading, + }, + circleVisibility, + } +} \ No newline at end of file diff --git a/src/shared/utils/index.tsx b/src/shared/utils/index.tsx index af54f66cf5..ade45e0565 100755 --- a/src/shared/utils/index.tsx +++ b/src/shared/utils/index.tsx @@ -45,3 +45,4 @@ export * from "./joinWithLast"; export * from "./getResizedFileUrl"; export * from "./areTimestampsEqual"; export * from "./parseMessageLink"; +export * from "./generateOptimisticFeedItem"; diff --git a/src/store/states/common/reducer.ts b/src/store/states/common/reducer.ts index adf5f49e45..1fd39d71f0 100644 --- a/src/store/states/common/reducer.ts +++ b/src/store/states/common/reducer.ts @@ -701,8 +701,9 @@ export const reducer = createReducer(initialState) produce(state, (nextState) => { const updatedMap = new Map(nextState.optimisticFeedItems); + const optimisticItemId = payload.data.discussionId ?? payload.data.id; // Add the new item to the Map - updatedMap.set(payload.data.id, { + updatedMap.set(optimisticItemId, { type: InboxItemType.FeedItemFollow, itemId: payload.id, feedItem: payload, @@ -710,7 +711,7 @@ export const reducer = createReducer(initialState) // Assign the new Map back to the state nextState.optimisticFeedItems = updatedMap; - nextState.recentStreamId = payload.data.id; + nextState.recentStreamId = optimisticItemId; }), ) .handleAction(actions.updateOptimisticFeedItemState, (state, { payload }) =>