Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/components/message.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ const ReplyToMessage = ({ message }: { message: Message }) => {

<p className="text-sm">
<strong>{message.replyTo.from.username}</strong>:{" "}
{message.replyTo.content}
{message.replyTo.content.length < 20
? message.replyTo.content
: `${message.replyTo.content.slice(0, 20)}...`}
Comment on lines +50 to +52
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Enhance message truncation implementation

The current implementation has several areas for improvement:

  1. The character limit is hard-coded
  2. The truncation might not handle multi-byte characters or emojis correctly
  3. Missing accessibility considerations for screen readers

Consider this improved implementation:

-          {message.replyTo.content.length < 20
-            ? message.replyTo.content
-            : `${message.replyTo.content.slice(0, 20)}...`}
+          <span title={message.replyTo.content}>
+            {message.replyTo.content.length <= MAX_REPLY_LENGTH
+              ? message.replyTo.content
+              : `${message.replyTo.content.slice(0, MAX_REPLY_LENGTH)}…`}
+          </span>

Add this constant at the top of the file:

const MAX_REPLY_LENGTH = 20; // Maximum length for reply message preview

The improvements include:

  • Using a named constant for better maintainability
  • Adding a title attribute for accessibility
  • Using proper ellipsis character (…)
  • Wrapping in a span for better semantic structure

</p>
</div>
);
Expand Down
Loading