({
note,
draft,
onCaptureDraft,
onClearDraft,
onJump
}: Props)
| 55 | } |
| 56 | |
| 57 | export function CommentsPanel({ |
| 58 | note, |
| 59 | draft, |
| 60 | onCaptureDraft, |
| 61 | onClearDraft, |
| 62 | onJump |
| 63 | }: Props): JSX.Element { |
| 64 | const comments = useStore((s) => s.noteComments[note.path] ?? EMPTY_COMMENTS) |
| 65 | const activeCommentId = useStore((s) => s.activeCommentId) |
| 66 | const loadNoteComments = useStore((s) => s.loadNoteComments) |
| 67 | const addNoteComment = useStore((s) => s.addNoteComment) |
| 68 | const updateNoteComment = useStore((s) => s.updateNoteComment) |
| 69 | const deleteNoteComment = useStore((s) => s.deleteNoteComment) |
| 70 | const setActiveCommentId = useStore((s) => s.setActiveCommentId) |
| 71 | const setFocusedPanel = useStore((s) => s.setFocusedPanel) |
| 72 | const focusedPanel = useStore((s) => s.focusedPanel) |
| 73 | const panelWidth = useStore((s) => s.panelWidths.comments) |
| 74 | const setPanelWidth = useStore((s) => s.setPanelWidth) |
| 75 | const { startResize } = usePanelResize(panelWidth, (px) => setPanelWidth('comments', px)) |
| 76 | |
| 77 | const [body, setBody] = useState('') |
| 78 | const [editingId, setEditingId] = useState<string | null>(null) |
| 79 | const [editBody, setEditBody] = useState('') |
| 80 | const textareaRef = useRef<HTMLTextAreaElement | null>(null) |
| 81 | const panelRef = useRef<HTMLElement | null>(null) |
| 82 | const notePathRef = useRef(note.path) |
| 83 | const commentsFocused = focusedPanel === 'comments' |
| 84 | |
| 85 | useEffect(() => { |
| 86 | void loadNoteComments(note.path) |
| 87 | }, [loadNoteComments, note.path]) |
| 88 | |
| 89 | useEffect(() => { |
| 90 | if (!draft) return |
| 91 | const raf = requestAnimationFrame(() => textareaRef.current?.focus()) |
| 92 | return () => cancelAnimationFrame(raf) |
| 93 | }, [draft]) |
| 94 | |
| 95 | useEffect(() => { |
| 96 | if (notePathRef.current === note.path) return |
| 97 | notePathRef.current = note.path |
| 98 | setBody('') |
| 99 | setEditingId(null) |
| 100 | setEditBody('') |
| 101 | onClearDraft() |
| 102 | }, [note.path]) |
| 103 | |
| 104 | useEffect(() => { |
| 105 | if (!activeCommentId) return |
| 106 | const raf = requestAnimationFrame(() => { |
| 107 | document |
| 108 | .querySelector<HTMLElement>(`[data-comment-card-id="${cssEscape(activeCommentId)}"]`) |
| 109 | ?.scrollIntoView({ block: 'nearest' }) |
| 110 | }) |
| 111 | return () => cancelAnimationFrame(raf) |
| 112 | }, [activeCommentId, comments]) |
| 113 | |
| 114 | const unresolved = useMemo( |
nothing calls this directly
no test coverage detected