Skip to content

Commit 2695c67

Browse files
author
Emre Güdür
committed
fix: renderAddCmp, chatlist drag drop problem
1 parent a8dff29 commit 2695c67

5 files changed

Lines changed: 23 additions & 6 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-chat-elements",
3-
"version": "12.0.7",
3+
"version": "12.0.8",
44
"description": "Reactjs chat components",
55
"author": "Avare Kodcu <abdurrahmaneker58@gmail.com>",
66
"main": "dist/main.js",

src/ChatItem/ChatItem.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { Key, useState } from 'react'
1+
import React, { Key, useEffect, useState } from 'react'
22
import './ChatItem.css'
33

44
import Avatar from '../Avatar/Avatar'
@@ -22,6 +22,10 @@ const ChatItem: React.FC<IChatItemProps> = ({
2222
const [onHoverTool, setOnHoverTool] = useState(false)
2323
const [onDrag, setOnDrag] = useState(false)
2424

25+
useEffect(() => {
26+
props.setDragStates(setOnDrag)
27+
}, [])
28+
2529
const handleOnMouseEnter = () => {
2630
setOnHoverTool(true)
2731
}

src/ChatList/ChatList.tsx

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
import React, { Key } from 'react'
1+
import React, { Dispatch, Key, SetStateAction } from 'react'
22
import classNames from 'classnames'
33
import './ChatList.css'
44

55
import ChatItem from '../ChatItem/ChatItem'
66
import { IChatListProps, ChatListEvent } from '../type'
77

8+
let list: Dispatch<SetStateAction<any>>[] = []
9+
810
const ChatList: React.FC<IChatListProps> = props => {
911
const onClick: ChatListEvent = (item, index, event) => {
1012
if (props.onClick instanceof Function) props.onClick(item, index, event)
@@ -19,6 +21,15 @@ const ChatList: React.FC<IChatListProps> = props => {
1921
if (props.onAvatarError instanceof Function) props.onAvatarError(item, index, event)
2022
}
2123

24+
const setDragStates = <S,>(state: Dispatch<SetStateAction<S>>) => {
25+
list.push(state)
26+
}
27+
28+
const onDragLeaveMW = (e: React.MouseEvent<HTMLElement>, id: Number | string) => {
29+
if (list.length > 0) list.forEach(item => item(false))
30+
props.onDragLeave(e, id)
31+
}
32+
2233
return (
2334
<div className={classNames('rce-container-clist', props.className)}>
2435
{props.dataSource.map((x, i: number) => (
@@ -34,8 +45,9 @@ const ChatList: React.FC<IChatListProps> = props => {
3445
onDragOver={props?.onDragOver}
3546
onDragEnter={props?.onDragEnter}
3647
onDrop={props.onDrop}
37-
onDragLeave={props.onDragLeave}
48+
onDragLeave={onDragLeaveMW}
3849
onDragComponent={props.onDragComponent}
50+
setDragStates={setDragStates}
3951
/>
4052
))}
4153
</div>

src/MessageBox/MessageBox.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ const MessageBox: React.FC<MessageBoxType> = ({ focus = false, notch = true, sty
4848

4949
return (
5050
<div ref={messageRef} className={classNames('rce-container-mbox', props.className)} onClick={props.onClick}>
51-
{/* {props.renderAddCmp instanceof Function && props.renderAddCmp()} */}
51+
{props.renderAddCmp instanceof Function && props.renderAddCmp()}
5252
{props.type === 'system' ? (
5353
<SystemMessage {...props} focus={focus} notch={notch} />
5454
) : (

src/type.d.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ export interface IChatItemProps {
5757
onDragEnter?: Function
5858
onDrop?: Function
5959
onDragLeave?: Function
60+
setDragStates?: Function
6061
onDragComponent?: any
6162
letterItem?: ILetterItem
6263
customStatusComponents?: React.ElementType<any>[]
@@ -518,7 +519,7 @@ export interface ISpotifyMessageProps extends ISpotifyMessage {}
518519
*/
519520
export interface IMessageBoxProps {
520521
onMessageFocused?: any
521-
renderAddCmp?: React.Component
522+
renderAddCmp?: JSX.Element
522523
onClick?: React.MouseEventHandler
523524
onOpen?: React.MouseEventHandler
524525
onPhotoError?: React.MouseEventHandler

0 commit comments

Comments
 (0)