style: fix format issues (#255)
This commit is contained in:
@@ -1,16 +1,12 @@
|
||||
'use client';
|
||||
"use client";
|
||||
|
||||
import { useCallback, useMemo } from 'react';
|
||||
import { toast } from 'sonner';
|
||||
import type { SelectedLineRange } from '@pierre/diffs';
|
||||
import { useCommentsStore } from '@/lib/state/slices/comments';
|
||||
import { useDiffFileComments } from '@/hooks/domains/comments/use-diff-comments';
|
||||
import {
|
||||
commentsToAnnotations,
|
||||
extractCodeFromDiff,
|
||||
extractCodeFromContent,
|
||||
} from '@/lib/diff';
|
||||
import type { DiffComment, AnnotationSide, CommentAnnotation } from '@/lib/diff/types';
|
||||
import { useCallback, useMemo } from "react";
|
||||
import { toast } from "sonner";
|
||||
import type { SelectedLineRange } from "@pierre/diffs";
|
||||
import { useCommentsStore } from "@/lib/state/slices/comments";
|
||||
import { useDiffFileComments } from "@/hooks/domains/comments/use-diff-comments";
|
||||
import { commentsToAnnotations, extractCodeFromDiff, extractCodeFromContent } from "@/lib/diff";
|
||||
import type { DiffComment, AnnotationSide, CommentAnnotation } from "@/lib/diff/types";
|
||||
|
||||
interface UseDiffCommentsOptions {
|
||||
sessionId: string;
|
||||
@@ -29,10 +25,7 @@ interface UseDiffCommentsReturn {
|
||||
/** Annotations formatted for @pierre/diffs */
|
||||
annotations: CommentAnnotation[];
|
||||
/** Add a new comment */
|
||||
addComment: (
|
||||
range: SelectedLineRange,
|
||||
text: string
|
||||
) => void;
|
||||
addComment: (range: SelectedLineRange, text: string) => void;
|
||||
/** Remove a comment */
|
||||
removeComment: (commentId: string) => void;
|
||||
/** Update a comment */
|
||||
@@ -54,31 +47,26 @@ export function useDiffComments({
|
||||
oldContent,
|
||||
}: UseDiffCommentsOptions): UseDiffCommentsReturn {
|
||||
const comments = useDiffFileComments(sessionId, filePath);
|
||||
const editingCommentId = useCommentsStore(
|
||||
(state) => state.editingCommentId
|
||||
);
|
||||
const editingCommentId = useCommentsStore((state) => state.editingCommentId);
|
||||
const storeAddComment = useCommentsStore((state) => state.addComment);
|
||||
const storeRemoveComment = useCommentsStore((state) => state.removeComment);
|
||||
const storeUpdateComment = useCommentsStore((state) => state.updateComment);
|
||||
const storeSetEditingComment = useCommentsStore((state) => state.setEditingComment);
|
||||
|
||||
const annotations = useMemo(
|
||||
() => commentsToAnnotations(comments),
|
||||
[comments]
|
||||
);
|
||||
const annotations = useMemo(() => commentsToAnnotations(comments), [comments]);
|
||||
|
||||
const addComment = useCallback(
|
||||
(range: SelectedLineRange, text: string) => {
|
||||
const side = (range.side || 'additions') as AnnotationSide;
|
||||
const side = (range.side || "additions") as AnnotationSide;
|
||||
const startLine = Math.min(range.start, range.end);
|
||||
const endLine = Math.max(range.start, range.end);
|
||||
|
||||
// Extract the code content from the selected lines
|
||||
let codeContent = '';
|
||||
let codeContent = "";
|
||||
if (diff) {
|
||||
codeContent = extractCodeFromDiff(diff, startLine, endLine, side);
|
||||
} else {
|
||||
const content = side === 'additions' ? newContent : oldContent;
|
||||
const content = side === "additions" ? newContent : oldContent;
|
||||
if (content) {
|
||||
codeContent = extractCodeFromContent(content, startLine, endLine);
|
||||
}
|
||||
@@ -86,7 +74,7 @@ export function useDiffComments({
|
||||
|
||||
const comment: DiffComment = {
|
||||
id: `${filePath}-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`,
|
||||
source: 'diff',
|
||||
source: "diff",
|
||||
sessionId,
|
||||
filePath,
|
||||
startLine,
|
||||
@@ -95,37 +83,37 @@ export function useDiffComments({
|
||||
codeContent,
|
||||
text,
|
||||
createdAt: new Date().toISOString(),
|
||||
status: 'pending',
|
||||
status: "pending",
|
||||
};
|
||||
|
||||
storeAddComment(comment);
|
||||
toast.success('Comment added', {
|
||||
description: 'Your comment will be sent with your next message.',
|
||||
toast.success("Comment added", {
|
||||
description: "Your comment will be sent with your next message.",
|
||||
duration: 2000,
|
||||
});
|
||||
},
|
||||
[sessionId, filePath, diff, newContent, oldContent, storeAddComment]
|
||||
[sessionId, filePath, diff, newContent, oldContent, storeAddComment],
|
||||
);
|
||||
|
||||
const removeComment = useCallback(
|
||||
(commentId: string) => {
|
||||
storeRemoveComment(commentId);
|
||||
},
|
||||
[storeRemoveComment]
|
||||
[storeRemoveComment],
|
||||
);
|
||||
|
||||
const updateComment = useCallback(
|
||||
(commentId: string, updates: Partial<DiffComment>) => {
|
||||
storeUpdateComment(commentId, updates);
|
||||
},
|
||||
[storeUpdateComment]
|
||||
[storeUpdateComment],
|
||||
);
|
||||
|
||||
const setEditingComment = useCallback(
|
||||
(commentId: string | null) => {
|
||||
storeSetEditingComment(commentId);
|
||||
},
|
||||
[storeSetEditingComment]
|
||||
[storeSetEditingComment],
|
||||
);
|
||||
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user