chore: formatting cleanup

This commit is contained in:
CREDO23 2026-01-16 11:36:17 +02:00
parent 8de448a8ce
commit 09317cd9f7
13 changed files with 36 additions and 63 deletions

View file

@ -10,18 +10,16 @@ import { MemberMentionPicker } from "../member-mention-picker/member-mention-pic
import type { MemberOption } from "../member-mention-picker/types";
import type { CommentComposerProps, InsertedMention, MentionState } from "./types";
function convertDisplayToData(
displayContent: string,
mentions: InsertedMention[]
): string {
function convertDisplayToData(displayContent: string, mentions: InsertedMention[]): string {
let result = displayContent;
const sortedMentions = [...mentions].sort(
(a, b) => b.displayName.length - a.displayName.length
);
const sortedMentions = [...mentions].sort((a, b) => b.displayName.length - a.displayName.length);
for (const mention of sortedMentions) {
const displayPattern = new RegExp(`@${escapeRegExp(mention.displayName)}(?=\\s|$|[.,!?;:])`, 'g');
const displayPattern = new RegExp(
`@${escapeRegExp(mention.displayName)}(?=\\s|$|[.,!?;:])`,
"g"
);
const dataFormat = `@[${mention.id}]`;
result = result.replace(displayPattern, dataFormat);
}
@ -30,7 +28,7 @@ function convertDisplayToData(
}
function escapeRegExp(string: string): string {
return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
return string.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
}
function findMentionTrigger(
@ -39,9 +37,9 @@ function findMentionTrigger(
insertedMentions: InsertedMention[]
): { isActive: boolean; query: string; startIndex: number } {
const textBeforeCursor = text.slice(0, cursorPos);
const mentionMatch = textBeforeCursor.match(/(?:^|[\s])@([^\s]*)$/);
if (!mentionMatch) {
return { isActive: false, query: "", startIndex: 0 };
}
@ -58,10 +56,10 @@ function findMentionTrigger(
}
const textFromAt = text.slice(atIndex);
for (const mention of insertedMentions) {
const mentionPattern = `@${mention.displayName}`;
if (textFromAt.startsWith(mentionPattern)) {
const charAfterMention = text[atIndex + mentionPattern.length];
if (!charAfterMention || /[\s.,!?;:]/.test(charAfterMention)) {
@ -146,7 +144,7 @@ export function CommentComposer({
setDisplayContent(value);
const triggerResult = findMentionTrigger(value, cursorPos, insertedMentions);
if (triggerResult.isActive) {
setMentionState(triggerResult);
setHighlightedIndex(0);
@ -169,21 +167,15 @@ export function CommentComposer({
case "Tab":
if (!e.shiftKey) {
e.preventDefault();
setHighlightedIndex((prev) =>
prev < filteredMembers.length - 1 ? prev + 1 : 0
);
setHighlightedIndex((prev) => (prev < filteredMembers.length - 1 ? prev + 1 : 0));
} else if (e.key === "Tab") {
e.preventDefault();
setHighlightedIndex((prev) =>
prev > 0 ? prev - 1 : filteredMembers.length - 1
);
setHighlightedIndex((prev) => (prev > 0 ? prev - 1 : filteredMembers.length - 1));
}
break;
case "ArrowUp":
e.preventDefault();
setHighlightedIndex((prev) =>
prev > 0 ? prev - 1 : filteredMembers.length - 1
);
setHighlightedIndex((prev) => (prev > 0 ? prev - 1 : filteredMembers.length - 1));
break;
case "Enter":
e.preventDefault();

View file

@ -21,4 +21,3 @@ export interface InsertedMention {
id: string;
displayName: string;
}

View file

@ -10,12 +10,7 @@ import {
} from "@/components/ui/dropdown-menu";
import type { CommentActionsProps } from "./types";
export function CommentActions({
canEdit,
canDelete,
onEdit,
onDelete,
}: CommentActionsProps) {
export function CommentActions({ canEdit, canDelete, onEdit, onDelete }: CommentActionsProps) {
if (!canEdit && !canDelete) {
return null;
}
@ -48,4 +43,3 @@ export function CommentActions({
</DropdownMenu>
);
}

View file

@ -56,11 +56,13 @@ function formatTimestamp(dateString: string): string {
return `${dayName} at ${timeStr}`;
}
return date.toLocaleDateString("en-US", {
month: "short",
day: "numeric",
year: date.getFullYear() !== now.getFullYear() ? "numeric" : undefined,
}) + ` at ${timeStr}`;
return (
date.toLocaleDateString("en-US", {
month: "short",
day: "numeric",
year: date.getFullYear() !== now.getFullYear() ? "numeric" : undefined,
}) + ` at ${timeStr}`
);
}
function renderMentions(content: string): React.ReactNode {
@ -75,10 +77,7 @@ function renderMentions(content: string): React.ReactNode {
}
parts.push(
<span
key={match.index}
className="rounded bg-primary/10 px-1 font-medium text-primary"
>
<span key={match.index} className="rounded bg-primary/10 px-1 font-medium text-primary">
{match[0]}
</span>
);
@ -100,11 +99,12 @@ export function CommentItem({
onReply,
isReply = false,
}: CommentItemProps) {
const displayName = comment.author?.displayName || comment.author?.email.split("@")[0] || "Unknown";
const displayName =
comment.author?.displayName || comment.author?.email.split("@")[0] || "Unknown";
const email = comment.author?.email || "";
return (
<div className={cn("group flex gap-3", isReply && "ml-10")}>
<div className={cn("group flex gap-3")}>
<Avatar className="size-8 shrink-0">
{comment.author?.avatarUrl && (
<AvatarImage src={comment.author.avatarUrl} alt={displayName} />
@ -152,4 +152,3 @@ export function CommentItem({
</div>
);
}

View file

@ -31,4 +31,3 @@ export interface CommentActionsProps {
onEdit: () => void;
onDelete: () => void;
}

View file

@ -1,5 +1,5 @@
import type { MemberOption } from "../member-mention-picker/types";
import type { CommentData } from "../comment-item/types";
import type { MemberOption } from "../member-mention-picker/types";
export interface CommentThreadData {
id: number;
@ -25,4 +25,3 @@ export interface CommentThreadProps {
onDeleteComment: (commentId: number) => void;
isSubmitting?: boolean;
}

View file

@ -47,4 +47,3 @@ export function MemberMentionItem({
</button>
);
}

View file

@ -53,4 +53,3 @@ export function MemberMentionPicker({
</ScrollArea>
);
}

View file

@ -20,4 +20,3 @@ export interface MemberMentionItemProps {
onSelect: (member: MemberOption) => void;
onMouseEnter: () => void;
}