|
@@ -6,10 +6,14 @@ import InputBase from '@mui/material/InputBase';
|
|
import ArrowBackIcon from '@mui/icons-material/ArrowBack';
|
|
import ArrowBackIcon from '@mui/icons-material/ArrowBack';
|
|
import { styled, alpha } from '@mui/material/styles';
|
|
import { styled, alpha } from '@mui/material/styles';
|
|
import { makeStyles } from '@material-ui/core'
|
|
import { makeStyles } from '@material-ui/core'
|
|
-import React, { useState } from 'react';
|
|
|
|
|
|
+import { useState, useRef, useEffect } from 'react';
|
|
|
|
+import { createPortal } from 'react-dom';
|
|
|
|
|
|
import SearchBar from './SearchBar'
|
|
import SearchBar from './SearchBar'
|
|
import ChatsList from './ChatsList'
|
|
import ChatsList from './ChatsList'
|
|
|
|
+import MenuBar from './MenuBar'
|
|
|
|
+
|
|
|
|
+
|
|
|
|
|
|
const Search = styled('div')(({ theme }:any) => ({
|
|
const Search = styled('div')(({ theme }:any) => ({
|
|
position: 'relative',
|
|
position: 'relative',
|
|
@@ -78,10 +82,26 @@ const useStyles = makeStyles({
|
|
const ContactsBar = () => {
|
|
const ContactsBar = () => {
|
|
const classes = useStyles()
|
|
const classes = useStyles()
|
|
const [isOpen, setIsOpen] = useState<boolean>(false)
|
|
const [isOpen, setIsOpen] = useState<boolean>(false)
|
|
- const [value,setValue] = useState<string>('')
|
|
|
|
|
|
+ const [isMenu, setIsMenu] = useState<boolean>(false)
|
|
|
|
+ const [value, setValue] = useState<string>('')
|
|
|
|
+ const portalModal = useRef<HTMLDivElement|null>(null);
|
|
const handleFocus = (): void => setIsOpen(true)
|
|
const handleFocus = (): void => setIsOpen(true)
|
|
- const handleClick = (): void => setIsOpen(false)
|
|
|
|
- const handleSearch = (e:React.ChangeEvent<HTMLInputElement>) => setValue(e.target.value)
|
|
|
|
|
|
+ const handleClick = (): void => {
|
|
|
|
+ if(!isOpen) return setIsMenu(!isMenu)
|
|
|
|
+ setIsOpen(false)
|
|
|
|
+ }
|
|
|
|
+ const handleSearch = (e: React.ChangeEvent<HTMLInputElement>) => setValue(e.target.value)
|
|
|
|
+ useEffect(() => {
|
|
|
|
+ const handleCloseModal = () => setIsMenu(false)
|
|
|
|
+ const modal = document.getElementById('modal') as HTMLDivElement
|
|
|
|
+ modal.addEventListener('click',handleCloseModal)
|
|
|
|
+ portalModal.current = modal
|
|
|
|
+ return () => {
|
|
|
|
+ portalModal.current?.removeEventListener('click',handleCloseModal)
|
|
|
|
+ portalModal.current = null
|
|
|
|
+ }
|
|
|
|
+ }, [])
|
|
|
|
+
|
|
return (
|
|
return (
|
|
<>
|
|
<>
|
|
<Toolbar className={classes.toolBar}>
|
|
<Toolbar className={classes.toolBar}>
|
|
@@ -100,7 +120,8 @@ const ContactsBar = () => {
|
|
/>
|
|
/>
|
|
</Search>
|
|
</Search>
|
|
</Toolbar>
|
|
</Toolbar>
|
|
- {isOpen?<SearchBar />:<ChatsList/>}
|
|
|
|
|
|
+ {isOpen ? <SearchBar /> : <ChatsList />}
|
|
|
|
+ {isMenu&&portalModal.current&&createPortal(<MenuBar/>,portalModal.current)}
|
|
</>
|
|
</>
|
|
)
|
|
)
|
|
}
|
|
}
|