feat: improve comment system (#247)
This commit is contained in:
@@ -37,7 +37,7 @@ export function CommentDisplay({
|
||||
<div className="min-w-0 flex-1">
|
||||
<span className="text-muted-foreground">{lineRange}</span>
|
||||
<span className="mx-1 text-muted-foreground">·</span>
|
||||
<span className="break-words">{comment.annotation}</span>
|
||||
<span className="break-words">{comment.text}</span>
|
||||
</div>
|
||||
<div className="flex shrink-0 gap-0.5 opacity-0 group-hover:opacity-100">
|
||||
{onEdit && (
|
||||
@@ -111,7 +111,7 @@ export function CommentDisplay({
|
||||
|
||||
{/* Comment text */}
|
||||
<p className="whitespace-pre-wrap text-xs leading-relaxed text-foreground">
|
||||
{comment.annotation}
|
||||
{comment.text}
|
||||
</p>
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -45,7 +45,7 @@ const DATA_KEYS: (keyof FileDiffData)[] = ['filePath', 'diff', 'oldContent', 'ne
|
||||
function areCommentsEqual(prev: DiffComment[] | undefined, next: DiffComment[] | undefined): boolean {
|
||||
if (prev === next) return true;
|
||||
if (!prev || !next || prev.length !== next.length) return false;
|
||||
return prev.every((c, i) => c.id === next[i].id && c.annotation === next[i].annotation);
|
||||
return prev.every((c, i) => c.id === next[i].id && c.text === next[i].text);
|
||||
}
|
||||
|
||||
function arePropsEqual(prevProps: DiffViewerProps, nextProps: DiffViewerProps): boolean {
|
||||
|
||||
@@ -67,7 +67,7 @@ export function useAnnotationRenderer(opts: UseAnnotationRendererOpts) {
|
||||
return (
|
||||
<div className="my-1 px-2">
|
||||
<CommentForm
|
||||
initialContent={comment.annotation}
|
||||
initialContent={comment.text}
|
||||
onSubmit={(content) => handleCommentUpdate(comment.id, content)}
|
||||
onCancel={() => setEditingComment(null)}
|
||||
isEditing
|
||||
|
||||
@@ -3,10 +3,8 @@
|
||||
import { useCallback, useMemo } from 'react';
|
||||
import { toast } from 'sonner';
|
||||
import type { SelectedLineRange } from '@pierre/diffs';
|
||||
import {
|
||||
useDiffCommentsStore,
|
||||
useFileComments,
|
||||
} from '@/lib/state/slices/diff-comments';
|
||||
import { useCommentsStore } from '@/lib/state/slices/comments';
|
||||
import { useDiffFileComments } from '@/hooks/domains/comments/use-diff-comments';
|
||||
import {
|
||||
commentsToAnnotations,
|
||||
extractCodeFromDiff,
|
||||
@@ -33,7 +31,7 @@ interface UseDiffCommentsReturn {
|
||||
/** Add a new comment */
|
||||
addComment: (
|
||||
range: SelectedLineRange,
|
||||
annotation: string
|
||||
text: string
|
||||
) => void;
|
||||
/** Remove a comment */
|
||||
removeComment: (commentId: string) => void;
|
||||
@@ -55,14 +53,14 @@ export function useDiffComments({
|
||||
newContent,
|
||||
oldContent,
|
||||
}: UseDiffCommentsOptions): UseDiffCommentsReturn {
|
||||
const comments = useFileComments(sessionId, filePath);
|
||||
const editingCommentId = useDiffCommentsStore(
|
||||
const comments = useDiffFileComments(sessionId, filePath);
|
||||
const editingCommentId = useCommentsStore(
|
||||
(state) => state.editingCommentId
|
||||
);
|
||||
const storeAddComment = useDiffCommentsStore((state) => state.addComment);
|
||||
const storeRemoveComment = useDiffCommentsStore((state) => state.removeComment);
|
||||
const storeUpdateComment = useDiffCommentsStore((state) => state.updateComment);
|
||||
const storeSetEditingComment = useDiffCommentsStore((state) => state.setEditingComment);
|
||||
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),
|
||||
@@ -70,7 +68,7 @@ export function useDiffComments({
|
||||
);
|
||||
|
||||
const addComment = useCallback(
|
||||
(range: SelectedLineRange, annotation: string) => {
|
||||
(range: SelectedLineRange, text: string) => {
|
||||
const side = (range.side || 'additions') as AnnotationSide;
|
||||
const startLine = Math.min(range.start, range.end);
|
||||
const endLine = Math.max(range.start, range.end);
|
||||
@@ -88,13 +86,14 @@ export function useDiffComments({
|
||||
|
||||
const comment: DiffComment = {
|
||||
id: `${filePath}-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`,
|
||||
source: 'diff',
|
||||
sessionId,
|
||||
filePath,
|
||||
startLine,
|
||||
endLine,
|
||||
side,
|
||||
codeContent,
|
||||
annotation,
|
||||
text,
|
||||
createdAt: new Date().toISOString(),
|
||||
status: 'pending',
|
||||
};
|
||||
@@ -110,9 +109,9 @@ export function useDiffComments({
|
||||
|
||||
const removeComment = useCallback(
|
||||
(commentId: string) => {
|
||||
storeRemoveComment(sessionId, filePath, commentId);
|
||||
storeRemoveComment(commentId);
|
||||
},
|
||||
[sessionId, filePath, storeRemoveComment]
|
||||
[storeRemoveComment]
|
||||
);
|
||||
|
||||
const updateComment = useCallback(
|
||||
|
||||
@@ -188,7 +188,7 @@ export function useDiffViewerState(opts: UseDiffViewerStateOpts) {
|
||||
startLine: selectedLines.start,
|
||||
endLine: selectedLines.end,
|
||||
side: (selectedLines.side || 'additions') as DiffComment['side'],
|
||||
annotation: content,
|
||||
text: content,
|
||||
}));
|
||||
} else if (sessionId) {
|
||||
addComment(selectedLines, content);
|
||||
|
||||
Reference in New Issue
Block a user