|
@@ -1,14 +1,28 @@
|
|
|
import BottomNavigation from '@mui/material/BottomNavigation';
|
|
|
import BottomNavigationAction from '@mui/material/BottomNavigationAction';
|
|
|
-import React, { useState } from 'react';
|
|
|
+import { useState, useEffect } from 'react';
|
|
|
+import { useDispatch,useSelector } from 'react-redux';
|
|
|
import { makeStyles } from '@material-ui/core'
|
|
|
|
|
|
import ChatListRecent from './ChatListRecent'
|
|
|
-import NotDoneList from '../../../reusableComponents/NotDoneList';
|
|
|
+import FilesList from './FilesList';
|
|
|
+import MediaList from './MediaList';
|
|
|
+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 } from '../../../../helpers';
|
|
|
+import { asyncStartChatById } from '../../../../redux/chat/operations';
|
|
|
+import { actionIsOpen } from '../../../../redux/control/action';
|
|
|
+
|
|
|
|
|
|
const useStyles = makeStyles({
|
|
|
bottomNavigation: {
|
|
|
- boxShadow: '0px 1px 1px 1px rgba(120,120,120,0.63)',
|
|
|
+ boxShadow: '0px 1px 1px 1px rgba(120,120,120,0.63)',
|
|
|
},
|
|
|
icon: {
|
|
|
fontSize: 17,
|
|
@@ -16,18 +30,51 @@ const useStyles = makeStyles({
|
|
|
marginBottom: 0,
|
|
|
fontWeight:600
|
|
|
},
|
|
|
-underline: {
|
|
|
+ underline: {
|
|
|
fontSize: 45,
|
|
|
lineHeight: 0,
|
|
|
},
|
|
|
})
|
|
|
|
|
|
-const SearchLists = ({value}:{value:string}) => {
|
|
|
- const [isActive, setIsActive] = useState<number>(0)
|
|
|
- const handleIsActive = (_e: React.SyntheticEvent<Element, Event>, newValue: number): void => setIsActive(newValue)
|
|
|
+interface ISearchLists {
|
|
|
+ value: string,
|
|
|
+ setValue: (value: string) => void
|
|
|
+}
|
|
|
+
|
|
|
+const SearchLists = ({ value,setValue }: ISearchLists) => {
|
|
|
const classes = useStyles()
|
|
|
+ const dispatch = useDispatch()
|
|
|
+ const { chats } = useSelector(getStateMemo)
|
|
|
+ const allMessagesMemo = useSelector(getAllMessagesMemo)
|
|
|
+ const isOpen = useSelector(getIsOpen)
|
|
|
+ const [isActive, setIsActive] = useState<number>(0)
|
|
|
+ const handleIsActive = (_e: React.SyntheticEvent<Element, Event>, newValue: number): void => {
|
|
|
+ setIsActive(newValue)
|
|
|
+ setValue('')
|
|
|
+ }
|
|
|
const Icon = ({ name }: { name: string }) => <span className={classes.icon}>{name}</span>
|
|
|
const Label = () => <span className={classes.underline}>__</span>
|
|
|
+ const handleListItemClick = (companionId: string) => {
|
|
|
+ isOpen&&dispatch(actionIsOpen(''))
|
|
|
+ dispatch(asyncStartChatById(companionId))
|
|
|
+ }
|
|
|
+ const filterAndSort = () => sortByRecent(chats).filter((el) => {
|
|
|
+ const credentials = el.name + ' ' + el.lastName
|
|
|
+ if(credentials.toLowerCase().includes(value.toLowerCase())) return el
|
|
|
+ })
|
|
|
+ useEffect(() => {
|
|
|
+ dispatch(asyncGetAllMessages())
|
|
|
+ dispatch(asyncGetChats())
|
|
|
+ const handleReset = () => {
|
|
|
+ dispatch(asyncGetAllMessages())
|
|
|
+ dispatch(asyncGetChats())
|
|
|
+ }
|
|
|
+ const idInterval = setInterval(handleReset, 5000);
|
|
|
+ return () => clearInterval(idInterval);
|
|
|
+ }, [dispatch]);
|
|
|
+
|
|
|
+ const filteredAndSorted = filterAndSort()
|
|
|
+
|
|
|
return (
|
|
|
<>
|
|
|
<BottomNavigation
|
|
@@ -36,18 +83,20 @@ const SearchLists = ({value}:{value:string}) => {
|
|
|
onChange={handleIsActive}
|
|
|
className={classes.bottomNavigation}
|
|
|
>
|
|
|
- <BottomNavigationAction label={<Label/>} icon={<Icon name='Chats' />} />
|
|
|
- <BottomNavigationAction label={<Label/>} icon={<Icon name='Media' />} />
|
|
|
- <BottomNavigationAction label={<Label/>} icon={<Icon name='Files' />} />
|
|
|
- <BottomNavigationAction label={<Label />} icon={<Icon name='Audio' />} />
|
|
|
- <BottomNavigationAction label={<Label/>} icon={<Icon name='Video' />} />
|
|
|
+ <BottomNavigationAction label={<Label />} icon={<Icon name='Chats' />} />
|
|
|
+ <BottomNavigationAction label={<Label/>} icon={<Icon name='Files' />} />
|
|
|
+ <BottomNavigationAction label={<Label />} icon={<Icon name='Media' />} />
|
|
|
+ <BottomNavigationAction label={<Label/>} icon={<Icon name='Text' />} />
|
|
|
+ <BottomNavigationAction label={<Label />} icon={<Icon name='Audio' />} />
|
|
|
+ <BottomNavigationAction label={<Label/>} icon={<Icon name='Video' />} />
|
|
|
</BottomNavigation>
|
|
|
- {isActive === 0 && <ChatListRecent value={value}/>}
|
|
|
- {isActive === 1 && <NotDoneList name='Media'/>}
|
|
|
- {isActive === 2 && <NotDoneList name='Links'/>}
|
|
|
- {isActive === 3 && <NotDoneList name='Files'/>}
|
|
|
- {isActive === 4 && <NotDoneList name='Music'/>}
|
|
|
- {isActive === 5 && <NotDoneList name='Voice'/>}
|
|
|
+ {isActive === 0 && <ChatListRecent value={value}
|
|
|
+ filteredAndSorted={filteredAndSorted} handleListItemClick={handleListItemClick} />}
|
|
|
+ {isActive === 1 && <FilesList allMessagesMemo={allMessagesMemo}/>}
|
|
|
+ {isActive === 2 && <MediaList allMessagesMemo={allMessagesMemo}/>}
|
|
|
+ {isActive === 3 && <TextList allMessagesMemo={allMessagesMemo}/>}
|
|
|
+ {isActive === 4 && <AudioList allMessagesMemo={allMessagesMemo}/>}
|
|
|
+ {isActive === 5 && <VideoList allMessagesMemo={allMessagesMemo}/>}
|
|
|
</>
|
|
|
)
|
|
|
}
|