|
@@ -78,10 +78,9 @@ const ChatBar = () => {
|
|
|
const dispatch = useDispatch()
|
|
|
const messages = useSelector(getMessagesMemo)
|
|
|
const userNumber = useSelector(getNumber)
|
|
|
- const { companionId,total } = useSelector(getChat)
|
|
|
+ const { companionId,total,seen } = useSelector(getChat)
|
|
|
const scroll = useSelector(getScroll)
|
|
|
const [isArrow, setIsArrow] = useState<boolean>(false)
|
|
|
- const [isScroll, setIsScroll] = useState<boolean>(true)
|
|
|
const [isNew, setIsNew] = useState<{new:number,mute:boolean}>({new:0,mute:false})
|
|
|
const divRef = useRef<any | null>(null)
|
|
|
let time:any
|
|
@@ -92,12 +91,11 @@ const ChatBar = () => {
|
|
|
})
|
|
|
}
|
|
|
|
|
|
- const handleScroll = useCallback(({ target }: any) => {
|
|
|
- isScroll&&setIsScroll(false)
|
|
|
- const different = target.scrollHeight - target.scrollTop
|
|
|
- if (different < 900) seenChat(companionId)
|
|
|
- setIsArrow(different < 1300 ? false : true)
|
|
|
- }, [isScroll, companionId])
|
|
|
+ const handleScroll = useCallback(({ target:{scrollHeight,scrollTop,clientHeight} }: any) => {
|
|
|
+ const different = scrollHeight - Math.trunc(scrollTop)
|
|
|
+ if (total !== seen&&clientHeight - different < 50) seenChat(companionId)
|
|
|
+ setIsArrow(different === clientHeight ? false : true)
|
|
|
+ }, [total,seen, companionId])
|
|
|
|
|
|
const debouncedHandleScroll = debounce(handleScroll, 300)
|
|
|
|
|
@@ -122,8 +120,8 @@ const ChatBar = () => {
|
|
|
useEffect(() => {
|
|
|
const scrollHeight = divRef.current.scrollHeight
|
|
|
const clientHeight = divRef.current.clientHeight
|
|
|
- if(isScroll&&scrollHeight === clientHeight) seenChat(companionId)
|
|
|
- }, [isScroll, companionId, total]);
|
|
|
+ if(total !== seen&&scrollHeight === clientHeight) seenChat(companionId)
|
|
|
+ }, [total,seen, companionId]);
|
|
|
|
|
|
return (
|
|
|
<div className={classes.container} >
|