Skip to content

Commit

Permalink
CW-mention-streams
Browse files Browse the repository at this point in the history
Added mentions streams
Added Stream mention component
  • Loading branch information
MeyerPV committed Nov 1, 2024
1 parent 1c1bc96 commit 56b9da4
Show file tree
Hide file tree
Showing 34 changed files with 297 additions and 25 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"@floating-ui/react-dom-interactions": "^0.13.1",
"@headlessui/react": "^1.7.4",
"@storybook/addon-viewport": "^6.5.13",
"@tanstack/react-query": "4.5.0",
"@tanstack/react-table": "^8.7.9",
"@types/react-pdf": "^5.7.2",
"axios": "^0.21.0",
Expand Down
31 changes: 20 additions & 11 deletions src/pages/App/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ import {
NotificationsHandler,
} from "./handlers";
import { Router } from "./router";
import {
QueryClient,
QueryClientProvider,
} from '@tanstack/react-query'

// Create a client
const queryClient = new QueryClient()

const App = () => {
const dispatch = useDispatch();
Expand All @@ -28,17 +35,19 @@ const App = () => {
}, [dispatch, isDesktop]);

return (
<ReactRouter history={history}>
<BackgroundNotificationModal />
<CommonHandler />
<TextDirectionHandler />
<ThemeHandler />
<UserNotificationsAmountHandler />
<WebViewLoginHandler />
<NotificationsHandler />
<LoginContainer />
<Router />
</ReactRouter>
<QueryClientProvider client={queryClient}>
<ReactRouter history={history}>
<BackgroundNotificationModal />
<CommonHandler />
<TextDirectionHandler />
<ThemeHandler />
<UserNotificationsAmountHandler />
<WebViewLoginHandler />
<NotificationsHandler />
<LoginContainer />
<Router />
</ReactRouter>
</QueryClientProvider>
);
};

Expand Down
9 changes: 9 additions & 0 deletions src/pages/common/components/ChatComponent/ChatComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {
useZoomDisabling,
useImageSizeCheck,
useQueryParams,
useFetchDiscussionsByCommonId,
} from "@/shared/hooks";
import { ArrowInCircleIcon } from "@/shared/icons";
import { LinkPreviewData } from "@/shared/interfaces";
Expand Down Expand Up @@ -108,6 +109,7 @@ interface ChatComponentInterface {
directParent?: DirectParent | null;
renderChatInput?: () => ReactNode;
onUserClick?: (userId: string) => void;
onStreamMentionClick?: (feedItemId: string) => void;
onFeedItemClick?: (feedItemId: string) => void;
onInternalLinkClick?: (data: InternalLinkData) => void;
}
Expand Down Expand Up @@ -156,6 +158,7 @@ export default function ChatComponent({
directParent,
renderChatInput: renderChatInputOuter,
onUserClick,
onStreamMentionClick,
onFeedItemClick,
onInternalLinkClick,
}: ChatComponentInterface) {
Expand Down Expand Up @@ -202,6 +205,7 @@ export default function ChatComponent({
},
onFeedItemClick,
onUserClick,
onStreamMentionClick,
commonId,
onInternalLinkClick,
});
Expand All @@ -215,6 +219,9 @@ export default function ChatComponent({
chatChannelId: chatChannel?.id || "",
participants: chatChannel?.participants,
});

const {data: discussionsData} = useFetchDiscussionsByCommonId(commonId);

const users = useMemo(
() => (chatChannel ? chatUsers : discussionUsers),
[chatUsers, discussionUsers, chatChannel],
Expand Down Expand Up @@ -827,6 +834,7 @@ export default function ChatComponent({
onMessageDelete={handleMessageDelete}
directParent={directParent}
onUserClick={onUserClick}
onStreamMentionClick={onStreamMentionClick}
onFeedItemClick={onFeedItemClick}
onInternalLinkClick={onInternalLinkClick}
isEmpty={
Expand Down Expand Up @@ -864,6 +872,7 @@ export default function ChatComponent({
onClearFinished={onClearFinished}
shouldReinitializeEditor={shouldReinitializeEditor}
users={users}
discussions={discussionsData ?? []}
onEnterKeyDown={onEnterKeyDown}
emojiCount={emojiCount}
setMessage={setMessage}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ interface ChatContentInterface {
onMessageDelete?: (messageId: string) => void;
directParent?: DirectParent | null;
onUserClick?: (userId: string) => void;
onStreamMentionClick?: (link: string) => void;
onFeedItemClick?: (feedItemId: string) => void;
onInternalLinkClick?: (data: InternalLinkData) => void;
isEmpty?: boolean;
Expand Down Expand Up @@ -106,6 +107,7 @@ const ChatContent: ForwardRefRenderFunction<
onMessageDelete,
directParent,
onUserClick,
onStreamMentionClick,
onFeedItemClick,
onInternalLinkClick,
isEmpty,
Expand Down Expand Up @@ -292,6 +294,7 @@ const ChatContent: ForwardRefRenderFunction<
onMessageDelete={onMessageDelete}
directParent={directParent}
onUserClick={onUserClick}
onStreamMentionClick={onStreamMentionClick}
onFeedItemClick={onFeedItemClick}
onInternalLinkClick={onInternalLinkClick}
chatChannelId={chatChannelId}
Expand All @@ -312,6 +315,7 @@ const ChatContent: ForwardRefRenderFunction<
onMessageDelete={onMessageDelete}
directParent={directParent}
onUserClick={onUserClick}
onStreamMentionClick={onStreamMentionClick}
onFeedItemClick={onFeedItemClick}
onInternalLinkClick={onInternalLinkClick}
isMessageEditAllowed={isMessageEditAllowed}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import React, {
import classNames from "classnames";
import { FILES_ACCEPTED_EXTENSIONS } from "@/shared/constants";
import { PlusIcon, SendIcon } from "@/shared/icons";
import { User } from "@/shared/models";
import { Discussion, User } from "@/shared/models";
import {
BaseTextEditor,
ButtonIcon,
Expand All @@ -30,6 +30,7 @@ interface ChatInputProps {
emojiCount: EmojiCount;
onEnterKeyDown: (event: React.KeyboardEvent<HTMLElement>) => void;
users: User[];
discussions: Discussion[];
shouldReinitializeEditor: boolean;
onClearFinished: () => void;
canSendMessage?: boolean;
Expand Down Expand Up @@ -58,6 +59,7 @@ export const ChatInput = React.memo(forwardRef<BaseTextEditorHandles, ChatInputP
emojiCount,
onEnterKeyDown,
users,
discussions,
shouldReinitializeEditor,
onClearFinished,
} = props;
Expand Down Expand Up @@ -114,6 +116,7 @@ export const ChatInput = React.memo(forwardRef<BaseTextEditorHandles, ChatInputP
placeholder="Message"
onKeyDown={onEnterKeyDown}
users={users}
discussions={discussions}
shouldReinitializeEditor={shouldReinitializeEditor}
onClearFinished={onClearFinished}
scrollSelectionIntoView={emptyFunction}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { InternalLinkData } from "@/shared/utils";
interface Options {
hasPermissionToHide: boolean;
onUserClick?: (userId: string) => void;
onStreamMentionClick?: (feedItemId: string) => void;
onFeedItemClick?: (feedItemId: string) => void;
onInternalLinkClick?: (data: InternalLinkData) => void;
directParent?: DirectParent | null;
Expand All @@ -37,6 +38,7 @@ export const useDiscussionChatAdapter = (options: Options): Return => {
discussionId,
onFeedItemClick,
onUserClick,
onStreamMentionClick,
commonId,
onInternalLinkClick,
} = options;
Expand All @@ -63,6 +65,7 @@ export const useDiscussionChatAdapter = (options: Options): Return => {
textStyles,
onFeedItemClick,
onUserClick,
onStreamMentionClick,
onInternalLinkClick,
});
const { markFeedItemAsSeen } = useUpdateFeedItemSeenState();
Expand Down
1 change: 1 addition & 0 deletions src/pages/common/components/FeedItem/FeedItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ const FeedItem = forwardRef<FeedItemRef, FeedItemProps>((props, ref) => {
shouldPreLoadMessages,
withoutMenu,
onUserClick: handleUserClick,
onStreamMentionClick: onFeedItemClick,
onFeedItemClick,
onInternalLinkClick,
}),
Expand Down
2 changes: 1 addition & 1 deletion src/pages/commonFeed/CommonFeed.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ const CommonFeedComponent: FC<CommonFeedProps> = (props) => {
const anotherCommonId =
userCommonIds[0] === commonId ? userCommonIds[1] : userCommonIds[0];
const pinnedItemIds = useMemo(
() => commonData?.common.pinnedFeedItems.map((item) => item.feedObjectId),
() => (commonData?.common.pinnedFeedItems ?? []).map((item) => item.feedObjectId),
[commonData?.common.pinnedFeedItems],
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ const DesktopChat: FC<ChatProps> = (props) => {
directParent={directParent}
renderChatInput={renderChatInput}
onUserClick={onUserClick}
onStreamMentionClick={onFeedItemClick}
onFeedItemClick={onFeedItemClick}
onInternalLinkClick={onInternalLinkClick}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ const MobileChat: FC<ChatProps> = (props) => {
directParent={directParent}
renderChatInput={renderChatInput}
onUserClick={onUserClick}
onStreamMentionClick={onFeedItemClick}
onFeedItemClick={onFeedItemClick}
onInternalLinkClick={onInternalLinkClick}
/>
Expand Down
15 changes: 15 additions & 0 deletions src/services/CommonFeed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
CommonFeedObjectUserUnique,
CommonFeedType,
CommonMember,
FeedItemFollow,
SubCollections,
Timestamp,
} from "@/shared/models";
Expand Down Expand Up @@ -318,6 +319,20 @@ class CommonFeedService {
}
});
};


public getFeedItemByCommonAndDiscussionId = async ({commonId, discussionId}: {commonId: string; discussionId: string}): Promise<CommonFeed | null> => {
try {
const feedItems = await this.getCommonFeedSubCollection(commonId)
.where("data.id", "==", discussionId)
.get();

const data = feedItems.docs.map(doc => doc.data());
return data?.[0];
} catch (error) {
return null;
}
};
}

export default new CommonFeedService();
11 changes: 11 additions & 0 deletions src/services/Discussion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,17 @@ class DiscussionService {
public deleteDiscussion = async (discussionId: string): Promise<void> => {
await Api.delete(ApiEndpoint.DeleteDiscussion(discussionId));
};

public getDiscussionsByCommonId = async (commonId: string) => {
const discussionCollection = await this.getDiscussionCollection()
.where("commonId", "==", commonId) // Query for documents where commonId matches
.get();

// Map the Firestore document data
const data = discussionCollection.docs.map(doc => doc.data());
return data;
};

}

export default new DiscussionService();
5 changes: 5 additions & 0 deletions src/shared/components/Chat/ChatMessage/ChatMessage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ interface ChatMessageProps {
onMessageDelete?: (messageId: string) => void;
directParent?: DirectParent | null;
onUserClick?: (userId: string) => void;
onStreamMentionClick?: (feedItemID: string) => void;
onFeedItemClick?: (feedItemId: string) => void;
onInternalLinkClick?: (data: InternalLinkData) => void;
isMessageEditAllowed: boolean;
Expand Down Expand Up @@ -109,6 +110,7 @@ const ChatMessage = ({
onMessageDelete,
directParent,
onUserClick,
onStreamMentionClick,
onFeedItemClick,
onInternalLinkClick,
isMessageEditAllowed,
Expand Down Expand Up @@ -165,6 +167,7 @@ const ChatMessage = ({
directParent,
onUserClick,
onFeedItemClick,
onStreamMentionClick,
onInternalLinkClick,
});

Expand All @@ -177,6 +180,7 @@ const ChatMessage = ({
isNotCurrentUserMessage,
discussionMessage.commonId,
onUserClick,
onStreamMentionClick,
onInternalLinkClick,
]);

Expand Down Expand Up @@ -302,6 +306,7 @@ const ChatMessage = ({
commonId: discussionMessage.commonId,
directParent,
onUserClick,
onStreamMentionClick,
onFeedItemClick,
onInternalLinkClick,
});
Expand Down
6 changes: 6 additions & 0 deletions src/shared/components/Chat/ChatMessage/DMChatMessage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ interface ChatMessageProps {
onMessageDelete?: (messageId: string) => void;
directParent?: DirectParent | null;
onUserClick?: (userId: string) => void;
onStreamMentionClick?: (feedItemId: string) => void;
onFeedItemClick?: (feedItemId: string) => void;
onInternalLinkClick?: (data: InternalLinkData) => void;
chatChannelId?: string;
Expand Down Expand Up @@ -112,6 +113,7 @@ export default function DMChatMessage({
onMessageDelete,
directParent,
onUserClick,
onStreamMentionClick,
onFeedItemClick,
onInternalLinkClick,
chatChannelId,
Expand Down Expand Up @@ -181,6 +183,7 @@ export default function DMChatMessage({
getCommonPageAboutTabPath,
directParent,
onUserClick,
onStreamMentionClick,
onFeedItemClick,
onInternalLinkClick,
});
Expand All @@ -201,6 +204,7 @@ export default function DMChatMessage({
getCommonPagePath,
getCommonPageAboutTabPath,
onUserClick,
onStreamMentionClick,
]);

useEffect(() => {
Expand All @@ -217,6 +221,7 @@ export default function DMChatMessage({
commonId: discussionMessage.commonId,
directParent,
onUserClick,
onStreamMentionClick,
onFeedItemClick,
onInternalLinkClick,
});
Expand All @@ -229,6 +234,7 @@ export default function DMChatMessage({
isNotCurrentUserMessage,
discussionMessage.commonId,
onUserClick,
onStreamMentionClick,
discussionMessageUserId,
userId,
onInternalLinkClick,
Expand Down
Loading

0 comments on commit 56b9da4

Please sign in to comment.