Skip to content

Commit

Permalink
show "loading" label only when message data is being fetched
Browse files Browse the repository at this point in the history
  • Loading branch information
budnik9 committed Nov 1, 2023
1 parent 3a612a9 commit f51bc42
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 @@ -401,7 +412,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 f51bc42

Please sign in to comment.