import { useState,useEffect } from 'react'; import { useSelector } from 'react-redux'; import { makeStyles } from '@material-ui/core' import AudioList from './AudioList'; import MediaList from './MediaList'; import FilesList from './FilesList'; import TextList from './TextList'; import VideoList from './VideoList' import { getMessagesMemo } from '../../../../../redux/messages/selector' import { handleSort } from '../../../../../helpers'; import { getChat } from '../../../../../redux/chat/selector' import { TMessages } from '../../../../../typescript/redux/messages/types' const useStyles = makeStyles({ container: { borderBottom: 'solid 2px #dddddd', display: 'flex', justifyContent: 'space-around', alignContent: "center", alignItems:"center", flexWrap: 'nowrap', height:'7vh', color:'rgba(0, 0, 0, 0.6)' }, item: { height:'100%', display: 'flex', flexDirection: 'column', justifyContent: 'center', alignContent: "center", alignItems: "center", cursor:'pointer', }, icon: { fontSize: '1rem', lineHeight: 0, marginBottom: 0, fontWeight:600 }, underline: { fontSize: '2.5rem', lineHeight: 0, }, }) const ProfileLists = ({setDisabled,chatDivRef}:{setDisabled: React.Dispatch,chatDivRef: any | null}) => { const classes = useStyles() const { sort } = useSelector(getChat) const messagesMemo = useSelector(getMessagesMemo) const [isActive, setIsActive] = useState(0) const handleIsActive = (newValue: number): void => setIsActive(newValue) const handleScrollToTheMessage = (_id: string) => { const childNodes = chatDivRef.current.childNodes[0].childNodes let toScrollNode = [...childNodes].find((el: any) => el.id === _id) if (toScrollNode) { toScrollNode = [...toScrollNode.childNodes].slice(-1)[0] toScrollNode.style.boxShadow = '0px 0px 6px 0px #555555' toScrollNode.scrollIntoView({ behavior: 'smooth' }) setTimeout(() => { toScrollNode.style.boxShadow = 'unset' }, 2000) } } const filterBy = ['text', 'image', 'text', 'audio', 'video'] const sorted: TMessages = handleSort('createdAt', messagesMemo, sort) const filteredAndSorted = sorted.filter((el) => { if (isActive !== 0) { if(el.type === filterBy[isActive]) return el } else { if(el.type !== filterBy[isActive]) return el } }) useEffect(() => { setDisabled(filteredAndSorted.length > 0?false:true) }, [filteredAndSorted, setDisabled]) return ( <>
handleIsActive(0)}> Files ___
handleIsActive(1)}> Media ___
handleIsActive(2)}> Text ___
handleIsActive(3)}> Audio ___
handleIsActive(4)}> Video ___
{isActive === 0 && } {isActive === 1 && } {isActive === 2 && } {isActive === 3 && } {isActive === 4 && } ) } export default ProfileLists