Skip to content

Commit

Permalink
Merge pull request #2309 from daostack/bugfix/CW-2283-redundant-loadi…
Browse files Browse the repository at this point in the history
…ng-label

PROD - Loading... below messages with images (instead of the text)
  • Loading branch information
andreymikhadyuk authored Nov 13, 2023
2 parents 17a5ff3 + 17ee00d commit a54ec9f
Showing 1 changed file with 31 additions and 20 deletions.
51 changes: 31 additions & 20 deletions src/shared/components/Chat/ChatMessage/ChatMessage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import React, {
} from "react";
import classNames from "classnames";
import { useLongPress } from "use-long-press";
import { Logger } from "@/services";
import {
ElementDropdown,
UserAvatar,
Expand Down Expand Up @@ -110,6 +111,7 @@ export default function ChatMessage({
!isUserDiscussionMessage || userId !== discussionMessageUserId;

const [messageText, setMessageText] = useState<(string | JSX.Element)[]>([]);
const [isMessageDataFetching, setIsMessageDataFetching] = useState(false);

const [replyMessageText, setReplyMessageText] = useState<
(string | JSX.Element)[]
Expand Down Expand Up @@ -144,26 +146,35 @@ export default function ChatMessage({
const emojiCount = countTextEditorEmojiElements(
parseStringToTextEditorValue(discussionMessage.text),
);
const parsedText = await getTextFromTextEditorString({
textEditorString: discussionMessage.text,
users,
mentionTextClassName: !isNotCurrentUserMessage
? styles.mentionTextCurrentUser
: "",
emojiTextClassName: classNames({
[styles.singleEmojiText]: emojiCount.isSingleEmoji,
[styles.multipleEmojiText]: emojiCount.isMultipleEmoji,
}),
commonId: discussionMessage.commonId,
systemMessage: isSystemMessage ? discussionMessage : undefined,
getCommonPagePath,
getCommonPageAboutTabPath,
directParent,
onUserClick,
onFeedItemClick,
});

setMessageText(parsedText);
setIsMessageDataFetching(true);

try {
const parsedText = await getTextFromTextEditorString({
textEditorString: discussionMessage.text,
users,
mentionTextClassName: !isNotCurrentUserMessage
? styles.mentionTextCurrentUser
: "",
emojiTextClassName: classNames({
[styles.singleEmojiText]: emojiCount.isSingleEmoji,
[styles.multipleEmojiText]: emojiCount.isMultipleEmoji,
}),
commonId: discussionMessage.commonId,
systemMessage: isSystemMessage ? discussionMessage : undefined,
getCommonPagePath,
getCommonPageAboutTabPath,
directParent,
onUserClick,
onFeedItemClick,
});

setMessageText(parsedText);
} catch (error) {
Logger.error(error);
} finally {
setIsMessageDataFetching(false);
}
})();
}, [
users,
Expand Down Expand Up @@ -400,7 +411,7 @@ export default function ChatMessage({
<ChatMessageLinkify
onInternalLinkClick={handleInternalLinkClick}
>
{!messageText.length ? (
{!messageText.length && isMessageDataFetching ? (
<i>Loading...</i>
) : (
messageText.map((text) => text)
Expand Down

0 comments on commit a54ec9f

Please sign in to comment.