Bin
2025-12-16 9e0b2ba2c317b1a86212f24cbae3195ad1f3dbfa
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import { createContext, type FC, useCallback, useMemo } from "react";
import { observer } from "mobx-react";
 
import { LINK_COMMENT_MODE } from "../../../stores/Annotation/LinkingModes";
import { cn } from "../../../utils/bem";
import { CommentItem } from "./CommentItem";
 
export type CommentContextType = {
  startLinkingMode: (comment: any) => void;
  globalLinking: boolean;
  currentComment: any;
};
 
export const CommentsContext = createContext<CommentContextType>({
  startLinkingMode: () => {},
  globalLinking: false,
  currentComment: null,
});
 
export const CommentsList: FC<{ commentStore: any }> = observer(({ commentStore }) => {
  const startLinkingMode = useCallback(
    (comment: any) => {
      commentStore.annotation.startLinkingMode(LINK_COMMENT_MODE, comment);
    },
    [commentStore],
  );
  const globalLinking = commentStore.annotation?.linkingMode === LINK_COMMENT_MODE;
  const currentComment = commentStore.annotation.currentLinkingMode?.comment;
  const contextValue = useMemo(
    () => ({ startLinkingMode, currentComment, globalLinking }),
    [startLinkingMode, currentComment, globalLinking],
  );
  return (
    <CommentsContext.Provider value={contextValue}>
      <CommentsListInner commentStore={commentStore} />
    </CommentsContext.Provider>
  );
});
 
export const CommentsListInner: FC<{ commentStore: any }> = observer(({ commentStore }) => {
  return (
    <div className={cn("comments-list").toClassName()}>
      {commentStore.comments.map((comment: any) => (
        <CommentItem
          key={comment.id}
          comment={comment}
          listComments={commentStore.listComments}
          classificationsItems={commentStore.commentClassificationsItems}
        />
      ))}
    </div>
  );
});