mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-06-08 20:25:19 +02:00
chore: formatting cleanup
This commit is contained in:
parent
8de448a8ce
commit
09317cd9f7
13 changed files with 36 additions and 63 deletions
|
|
@ -107,4 +107,3 @@ export const markAllMentionsReadMutationAtom = atomWithMutation(() => ({
|
|||
toast.error("Failed to mark mentions as read");
|
||||
},
|
||||
}));
|
||||
|
||||
|
|
|
|||
|
|
@ -29,4 +29,3 @@ export const unreadMentionsAtom = atomWithQuery((get) => {
|
|||
},
|
||||
};
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -21,4 +21,3 @@ export interface InsertedMention {
|
|||
id: string;
|
||||
displayName: string;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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>
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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>
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -31,4 +31,3 @@ export interface CommentActionsProps {
|
|||
onEdit: () => void;
|
||||
onDelete: () => void;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -47,4 +47,3 @@ export function MemberMentionItem({
|
|||
</button>
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -53,4 +53,3 @@ export function MemberMentionPicker({
|
|||
</ScrollArea>
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -20,4 +20,3 @@ export interface MemberMentionItemProps {
|
|||
onSelect: (member: MemberOption) => void;
|
||||
onMouseEnter: () => void;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -16,4 +16,3 @@ export function useComments({ messageId, enabled = true }: UseCommentsOptions) {
|
|||
enabled: enabled && !!messageId,
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,24 +1,24 @@
|
|||
import {
|
||||
type CreateCommentRequest,
|
||||
type CreateReplyRequest,
|
||||
type DeleteCommentRequest,
|
||||
type GetCommentsRequest,
|
||||
type GetMentionsRequest,
|
||||
type MarkMentionReadRequest,
|
||||
type UpdateCommentRequest,
|
||||
createCommentRequest,
|
||||
createCommentResponse,
|
||||
createReplyRequest,
|
||||
createReplyResponse,
|
||||
type DeleteCommentRequest,
|
||||
deleteCommentRequest,
|
||||
deleteCommentResponse,
|
||||
type GetCommentsRequest,
|
||||
type GetMentionsRequest,
|
||||
getCommentsRequest,
|
||||
getCommentsResponse,
|
||||
getMentionsRequest,
|
||||
getMentionsResponse,
|
||||
type MarkMentionReadRequest,
|
||||
markAllMentionsReadResponse,
|
||||
markMentionReadRequest,
|
||||
markMentionReadResponse,
|
||||
type UpdateCommentRequest,
|
||||
updateCommentRequest,
|
||||
updateCommentResponse,
|
||||
} from "@/contracts/types/chat-comments.types";
|
||||
|
|
@ -90,11 +90,9 @@ class ChatCommentsApiService {
|
|||
throw new ValidationError(`Invalid request: ${errorMessage}`);
|
||||
}
|
||||
|
||||
return baseApiService.put(
|
||||
`/api/v1/comments/${parsed.data.comment_id}`,
|
||||
updateCommentResponse,
|
||||
{ body: { content: parsed.data.content } }
|
||||
);
|
||||
return baseApiService.put(`/api/v1/comments/${parsed.data.comment_id}`, updateCommentResponse, {
|
||||
body: { content: parsed.data.content },
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
@ -165,4 +163,3 @@ class ChatCommentsApiService {
|
|||
}
|
||||
|
||||
export const chatCommentsApiService = new ChatCommentsApiService();
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue