MCPcopy Create free account
hub / github.com/Detaysoft/react-chat-elements / MessageList

Function MessageList

src/MessageList/MessageList.tsx:10–183  ·  view source on GitHub ↗
({
  referance = null,
  lockable = false,
  toBottomHeight = 300,
  downButton,
  ...props
})

Source from the content-addressed store, hash-verified

8import { IMessageListProps, MessageListEvent } from '../type'
9
10const MessageList: FC<IMessageListProps> = ({
11 referance = null,
12 lockable = false,
13 toBottomHeight = 300,
14 downButton,
15 ...props
16}) => {
17 const [scrollBottom, setScrollBottom] = useState(0)
18 const [_downButton, setDownButton] = useState(false)
19 const prevProps = useRef(props)
20
21 const checkScroll = () => {
22 var e = referance
23 if (!e || !e.current) return
24
25 if (toBottomHeight === '100%' || (toBottomHeight && scrollBottom < toBottomHeight)) {
26 e.current.scrollTop = e.current.scrollHeight // scroll to bottom
27 } else {
28 if (lockable === true) {
29 e.current.scrollTop = e.current.scrollHeight - e.current.offsetHeight - scrollBottom
30 }
31 }
32 }
33
34 useEffect(() => {
35 if (!referance) return
36
37 if (prevProps.current.dataSource.length !== props.dataSource.length) {
38 setScrollBottom(getBottom(referance))
39 checkScroll()
40 }
41
42 prevProps.current = props
43 }, [prevProps, props])
44
45 const getBottom = (e: any) => {
46 if (e.current) return e.current.scrollHeight - e.current.scrollTop - e.current.offsetHeight
47 return e.scrollHeight - e.scrollTop - e.offsetHeight
48 }
49
50 const onOpen: MessageListEvent = (item, index, event) => {
51 if (props.onOpen instanceof Function) props.onOpen(item, index, event)
52 }
53
54 const onDownload: MessageListEvent = (item, index, event) => {
55 if (props.onDownload instanceof Function) props.onDownload(item, index, event)
56 }
57
58 const onPhotoError: MessageListEvent = (item, index, event) => {
59 if (props.onPhotoError instanceof Function) props.onPhotoError(item, index, event)
60 }
61
62 const onClick: MessageListEvent = (item, index, event) => {
63 if (props.onClick instanceof Function) props.onClick(item, index, event)
64 }
65
66 const onTitleClick: MessageListEvent = (item, index, event) => {
67 if (props.onTitleClick instanceof Function) props.onTitleClick(item, index, event)

Callers

nothing calls this directly

Calls 15

getBottomFunction · 0.85
checkScrollFunction · 0.85
onOpenFunction · 0.85
onPhotoErrorFunction · 0.85
onDownloadFunction · 0.85
onTitleClickFunction · 0.85
onForwardClickFunction · 0.85
onReplyClickFunction · 0.85
onReplyMessageClickFunction · 0.85
onRemoveMessageClickFunction · 0.85
onMeetingMoreSelectFunction · 0.85
onMessageFocusedFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…