|
@@ -9,14 +9,12 @@ import TextList from './TextList';
|
|
|
import AudioList from './AudioList'
|
|
|
import VideoList from './VideoList';
|
|
|
import { asyncGetAllMessages } from '../../../../redux/allMessages/operations';
|
|
|
-import { asyncGetChats } from '../../../../redux/chats/operations';
|
|
|
import { getStateMemo } from '../../../../redux/chats/selector';
|
|
|
import { getAllMessagesMemo } from '../../../../redux/allMessages/selector';
|
|
|
import { getIsOpen } from '../../../../redux/control/selector';
|
|
|
-import { sortByRecent,handleSort,timeStampFilter } from '../../../../helpers';
|
|
|
+import { sortByRecent,timeStampFilter } from '../../../../helpers';
|
|
|
import { asyncStartChatById } from '../../../../redux/chat/operations';
|
|
|
import { actionIsOpen } from '../../../../redux/control/action';
|
|
|
-import { TAllMessages } from '../../../../typescript/redux/allMessages/types';
|
|
|
import { TChats } from '../../../../typescript/redux/chats/types';
|
|
|
|
|
|
|
|
@@ -58,12 +56,13 @@ interface ISearchLists {
|
|
|
sort: boolean,
|
|
|
date: any,
|
|
|
setDate: React.Dispatch<any>,
|
|
|
+ setDisabled: React.Dispatch<boolean>,
|
|
|
}
|
|
|
|
|
|
-const SearchLists = ({ value,setValue,sort,date,setDate }: ISearchLists) => {
|
|
|
+const SearchLists = ({ value,setValue,sort,date,setDate,setDisabled }: ISearchLists) => {
|
|
|
const classes = useStyles()
|
|
|
const dispatch = useDispatch()
|
|
|
- const { chats } = useSelector(getStateMemo)
|
|
|
+ const { chats,total } = useSelector(getStateMemo)
|
|
|
const messagesMemo = useSelector(getAllMessagesMemo)
|
|
|
const isOpen = useSelector(getIsOpen)
|
|
|
const [isActive, setIsActive] = useState<number>(0)
|
|
@@ -87,42 +86,24 @@ const SearchLists = ({ value,setValue,sort,date,setDate }: ISearchLists) => {
|
|
|
return el
|
|
|
}
|
|
|
})
|
|
|
-
|
|
|
- const filteredMessages = (arr: TAllMessages) => arr.filter((el) => {
|
|
|
- if (!date) {
|
|
|
- if (!el.fullType && el.message.toLowerCase().includes(value.toLowerCase())) {
|
|
|
- return el
|
|
|
- }
|
|
|
- if (el.fullType && el.fullType.toLowerCase().includes(value.toLowerCase())) {
|
|
|
- return el
|
|
|
- }
|
|
|
- } else {
|
|
|
- if (!el.fullType && el.message.toLowerCase().includes(value.toLowerCase())
|
|
|
- && timeStampFilter(date) === timeStampFilter(el.createdAt)) {
|
|
|
- return el
|
|
|
- }
|
|
|
- if (el.fullType && el.fullType.toLowerCase().includes(value.toLowerCase())
|
|
|
- && timeStampFilter(date) === timeStampFilter(el.createdAt)) {
|
|
|
- return el
|
|
|
- }
|
|
|
- }
|
|
|
- })
|
|
|
|
|
|
useEffect(() => {
|
|
|
setDate('')
|
|
|
}, [setDate])
|
|
|
|
|
|
+ useEffect(() => {
|
|
|
+ if (isActive === 0) setDisabled(total === '0'?true:false)
|
|
|
+ }, [isActive,total,setDisabled])
|
|
|
+
|
|
|
useEffect(() => {
|
|
|
dispatch(asyncGetAllMessages())
|
|
|
- const handleReset = () => dispatch(asyncGetChats())
|
|
|
+ const handleReset = () => dispatch(asyncGetAllMessages())
|
|
|
const idInterval = setInterval(handleReset, 3000);
|
|
|
return () => clearInterval(idInterval);
|
|
|
}, [dispatch]);
|
|
|
|
|
|
|
|
|
const filteredAndSorted = filteredChats(sortByRecent(chats,sort))
|
|
|
- const allMessagesMemo = filteredMessages(handleSort('createdAt',messagesMemo,sort))
|
|
|
-
|
|
|
return (
|
|
|
<>
|
|
|
<div className={classes.container}>
|
|
@@ -159,11 +140,11 @@ const SearchLists = ({ value,setValue,sort,date,setDate }: ISearchLists) => {
|
|
|
</div>
|
|
|
{isActive === 0 && <ChatListRecent value={value} date={date}
|
|
|
filteredAndSorted={filteredAndSorted} handleListItemClick={handleListItemClick} />}
|
|
|
- {isActive === 1 && <FilesList allMessagesMemo={allMessagesMemo} value={value} date={date}/>}
|
|
|
- {isActive === 2 && <MediaList allMessagesMemo={allMessagesMemo} value={value} date={date}/>}
|
|
|
- {isActive === 3 && <TextList allMessagesMemo={allMessagesMemo} value={value} date={date}/>}
|
|
|
- {isActive === 4 && <AudioList allMessagesMemo={allMessagesMemo} value={value} date={date}/>}
|
|
|
- {isActive === 5 && <VideoList allMessagesMemo={allMessagesMemo} value={value} date={date}/>}
|
|
|
+ {isActive === 1 && <FilesList messagesMemo={messagesMemo} value={value} date={date} sort={sort} setDisabled={setDisabled}/>}
|
|
|
+ {isActive === 2 && <MediaList messagesMemo={messagesMemo} value={value} date={date} sort={sort} setDisabled={setDisabled}/>}
|
|
|
+ {isActive === 3 && <TextList messagesMemo={messagesMemo} value={value} date={date} sort={sort} setDisabled={setDisabled}/>}
|
|
|
+ {isActive === 4 && <AudioList messagesMemo={messagesMemo} value={value} date={date} sort={sort} setDisabled={setDisabled}/>}
|
|
|
+ {isActive === 5 && <VideoList messagesMemo={messagesMemo} value={value} date={date} sort={sort} setDisabled={setDisabled}/>}
|
|
|
</>
|
|
|
)
|
|
|
}
|