Move useEffect on window size and remove sidebars in phone layout

This commit is contained in:
Hristo Nedelkov 2023-11-03 11:07:25 +02:00
parent 23d3699991
commit 6602d2b90f

View File

@ -3,13 +3,37 @@ import { XStack } from 'tamagui'
import LeftSidebar from '../../components/General/LeftSidebar/LeftSidebar'
import RightSidebar from '../../components/General/RightSideBar/RightSidebar'
import DashboardContent from './DashboardContent'
import { useEffect, useState } from 'react'
const Dashboard = () => (
<XStack style={{ height: '100vh' }}>
<LeftSidebar />
<DashboardContent />
<RightSidebar />
</XStack>
)
const Dashboard = () => {
const [windowWidth, setWindowWidth] = useState(window.innerWidth)
useEffect(() => {
const handleResize = () => {
setWindowWidth(+window.innerWidth)
}
window.addEventListener('resize', handleResize)
return () => {
window.removeEventListener('resize', handleResize)
}
}, [])
return (
<XStack style={{ height: '100vh' }} >
{windowWidth>900&&
(
<LeftSidebar />
)}
<DashboardContent windowWidth={windowWidth} />
{windowWidth>900&&
(
<RightSidebar />
)}
</XStack >
)
}
export default Dashboard