Skip to content

Commit eb0ff68

Browse files
committed
fix resolve
1 parent ddc3036 commit eb0ff68

File tree

7 files changed

+78
-21
lines changed

7 files changed

+78
-21
lines changed

apps/array/src/renderer/features/code-editor/components/CodeEditorPanel.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ export function CodeEditorPanel({
8686
filePath={absolutePath}
8787
readOnly
8888
prNumber={prNumber}
89+
directoryPath={repoPath}
8990
/>
9091
</Box>
9192
);

apps/array/src/renderer/features/code-editor/components/CodeMirrorEditor.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ interface CodeMirrorEditorProps {
99
readOnly?: boolean;
1010
enableComments?: boolean;
1111
prNumber?: number;
12+
directoryPath?: string;
1213
}
1314

1415
export function CodeMirrorEditor({
@@ -18,11 +19,13 @@ export function CodeMirrorEditor({
1819
readOnly = false,
1920
enableComments = false,
2021
prNumber,
22+
directoryPath,
2123
}: CodeMirrorEditorProps) {
2224
const extensions = useEditorExtensions(filePath, readOnly, {
2325
enableComments,
2426
fileId: fileId || filePath,
2527
prNumber,
28+
directoryPath,
2629
});
2730
const options = useMemo(
2831
() => ({ doc: content, extensions, filePath }),

apps/array/src/renderer/features/code-editor/components/DiffEditorPanel.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ export function DiffEditorPanel({
145145
readOnly
146146
enableComments
147147
prNumber={prNumber}
148+
directoryPath={repoPath}
148149
/>
149150
)}
150151
</Box>

apps/array/src/renderer/features/code-editor/hooks/useEditorExtensions.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,12 @@ export function useEditorExtensions(
104104
);
105105
// Inline comment display
106106
extensions.push(
107-
commentWidgetExtension(() => getCommentsForFile(fileId), showComments),
107+
commentWidgetExtension(
108+
() => getCommentsForFile(fileId),
109+
showComments,
110+
prNumber,
111+
directoryPath,
112+
),
108113
);
109114
}
110115

@@ -121,5 +126,7 @@ export function useEditorExtensions(
121126
handleSubmitComment,
122127
closeComposer,
123128
composerState,
129+
directoryPath,
130+
prNumber,
124131
]);
125132
}

apps/array/src/renderer/features/comments/components/CommentBubble.tsx

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import { isCurrentUser } from "../utils/currentUser";
1717
interface CommentBubbleProps {
1818
comment: Comment;
1919
isReply?: boolean;
20+
directoryPath?: string;
2021
}
2122

2223
function formatRelativeTime(date: Date): string {
@@ -45,6 +46,7 @@ function getInitials(name: string): string {
4546
export function CommentBubble({
4647
comment,
4748
isReply = false,
49+
directoryPath,
4850
}: CommentBubbleProps) {
4951
const [isEditing, setIsEditing] = useState(false);
5052
const [editContent, setEditContent] = useState(comment.content);
@@ -66,17 +68,18 @@ export function CommentBubble({
6668

6769
const handleSaveEdit = useCallback(async () => {
6870
const trimmed = editContent.trim();
69-
if (!trimmed) return;
71+
if (!trimmed || !directoryPath) return;
7072

71-
await updateComment(comment.id, trimmed, ""); // TODO: Get actual directory path from context
73+
await updateComment(comment.id, trimmed, directoryPath);
7274
setIsEditing(false);
73-
}, [editContent, comment.id, updateComment]);
75+
}, [editContent, comment.id, updateComment, directoryPath]);
7476

7577
const handleDelete = useCallback(async () => {
78+
if (!directoryPath) return;
7679
if (window.confirm("Delete this comment? This action cannot be undone.")) {
77-
await deleteComment(comment.id, ""); // TODO: Get actual directory path from context
80+
await deleteComment(comment.id, directoryPath);
7881
}
79-
}, [comment.id, deleteComment]);
82+
}, [comment.id, deleteComment, directoryPath]);
8083

8184
const handleKeyDown = useCallback(
8285
(e: React.KeyboardEvent) => {

apps/array/src/renderer/features/comments/components/CommentThread.tsx

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,15 @@ import { CommentBubble } from "./CommentBubble";
88

99
interface CommentThreadProps {
1010
comment: Comment;
11+
prNumber?: number;
12+
directoryPath?: string;
1113
}
1214

13-
export function CommentThread({ comment: initialComment }: CommentThreadProps) {
15+
export function CommentThread({
16+
comment: initialComment,
17+
prNumber,
18+
directoryPath,
19+
}: CommentThreadProps) {
1420
const [isReplying, setIsReplying] = useState(false);
1521
const [replyContent, setReplyContent] = useState("");
1622
const [isCollapsed, setIsCollapsed] = useState(false);
@@ -35,28 +41,33 @@ export function CommentThread({ comment: initialComment }: CommentThreadProps) {
3541

3642
const handleSubmitReply = useCallback(async () => {
3743
const trimmed = replyContent.trim();
38-
if (!trimmed || !comment) return;
44+
if (!trimmed || !comment || !prNumber || !directoryPath) return;
3945

4046
const input: CreateReplyInput = {
4147
parentId: comment.id,
42-
prNumber: 0, // TODO: Get actual PR number from context
43-
directoryPath: "", // TODO: Get actual directory path from context
48+
prNumber,
49+
directoryPath,
4450
content: trimmed,
4551
};
4652

4753
await createReply(input);
4854
setReplyContent("");
4955
setIsReplying(false);
50-
}, [replyContent, comment, createReply]);
56+
}, [replyContent, comment, createReply, prNumber, directoryPath]);
5157

5258
const handleToggleResolved = useCallback(async () => {
53-
if (!comment) return;
54-
await resolveComment(comment.id, !comment.resolved, "", 0); // TODO: Get actual directory path and PR number from context
59+
if (!comment || !directoryPath || !prNumber) return;
60+
await resolveComment(
61+
comment.id,
62+
!comment.resolved,
63+
directoryPath,
64+
prNumber,
65+
);
5566
// Auto-collapse when resolving
5667
if (!comment.resolved) {
5768
setIsCollapsed(true);
5869
}
59-
}, [comment, resolveComment]);
70+
}, [comment, resolveComment, directoryPath, prNumber]);
6071

6172
const handleKeyDown = useCallback(
6273
(e: React.KeyboardEvent) => {
@@ -120,11 +131,16 @@ export function CommentThread({ comment: initialComment }: CommentThreadProps) {
120131
}}
121132
>
122133
<Flex direction="column" gap="2">
123-
<CommentBubble comment={comment} />
134+
<CommentBubble comment={comment} directoryPath={directoryPath} />
124135

125136
{/* Replies */}
126137
{comment.replies.map((reply) => (
127-
<CommentBubble key={reply.id} comment={reply} isReply />
138+
<CommentBubble
139+
key={reply.id}
140+
comment={reply}
141+
isReply
142+
directoryPath={directoryPath}
143+
/>
128144
))}
129145

130146
{/* Reply composer */}

apps/array/src/renderer/features/comments/extensions/commentWidgetExtension.ts

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,11 @@ import { CommentThread } from "../components/CommentThread";
1616
class CommentWidget extends WidgetType {
1717
private root: Root | null = null;
1818

19-
constructor(readonly comment: Comment) {
19+
constructor(
20+
readonly comment: Comment,
21+
readonly prNumber?: number,
22+
readonly directoryPath?: string,
23+
) {
2024
super();
2125
}
2226

@@ -38,7 +42,13 @@ class CommentWidget extends WidgetType {
3842

3943
// Use React to render the CommentThread
4044
this.root = createRoot(container);
41-
this.root.render(createElement(CommentThread, { comment: this.comment }));
45+
this.root.render(
46+
createElement(CommentThread, {
47+
comment: this.comment,
48+
prNumber: this.prNumber,
49+
directoryPath: this.directoryPath,
50+
}),
51+
);
4252

4353
return container;
4454
}
@@ -62,6 +72,8 @@ class CommentWidget extends WidgetType {
6272
function createCommentDecorations(
6373
comments: Comment[],
6474
doc: { lines: number; line: (n: number) => { to: number } },
75+
prNumber?: number,
76+
directoryPath?: string,
6577
): DecorationSet {
6678
const decorations: Array<{ pos: number; widget: CommentWidget }> = [];
6779

@@ -71,7 +83,7 @@ function createCommentDecorations(
7183
if (lineNum < 1 || lineNum > doc.lines) continue;
7284

7385
const line = doc.line(lineNum);
74-
const widget = new CommentWidget(comment);
86+
const widget = new CommentWidget(comment, prNumber, directoryPath);
7587

7688
decorations.push({
7789
pos: line.to,
@@ -105,10 +117,14 @@ export type CommentsFacetValue = Comment[];
105117
*
106118
* @param getComments - Function to get comments for the current file
107119
* @param showComments - Whether to show comments
120+
* @param prNumber - Pull request number if available
121+
* @param directoryPath - Repository directory path
108122
*/
109123
export function commentWidgetExtension(
110124
getComments: () => Comment[],
111125
showComments: boolean,
126+
prNumber?: number,
127+
directoryPath?: string,
112128
): Extension {
113129
// If comments are disabled, return an empty extension
114130
if (!showComments) {
@@ -118,12 +134,22 @@ export function commentWidgetExtension(
118134
const commentField = StateField.define<DecorationSet>({
119135
create(state) {
120136
const comments = getComments();
121-
return createCommentDecorations(comments, state.doc);
137+
return createCommentDecorations(
138+
comments,
139+
state.doc,
140+
prNumber,
141+
directoryPath,
142+
);
122143
},
123144
update(decorations, tr) {
124145
if (tr.docChanged) {
125146
const comments = getComments();
126-
return createCommentDecorations(comments, tr.state.doc);
147+
return createCommentDecorations(
148+
comments,
149+
tr.state.doc,
150+
prNumber,
151+
directoryPath,
152+
);
127153
}
128154
return decorations;
129155
},

0 commit comments

Comments
 (0)