import React, { useRef, useEffect, useState } from 'react'; import './DesktopLayout.scss'; import UiKitTheme from '../../themes/UiKitTheme'; type LayoutItems = { dialogsView: React.ReactNode; dialogMessagesView: React.ReactNode; dialogInfoView: React.ReactNode; theme?: UiKitTheme; mainContainerStyles?: React.CSSProperties; onHeightChange?: (height: number) => void; }; function DesktopLayout({ dialogsView, dialogMessagesView, dialogInfoView, theme = undefined, onHeightChange, mainContainerStyles = {}, }: LayoutItems) { const containerRef = useRef(null); const [height, setHeight] = useState(0); const handleResize = () => { if (containerRef.current) { const newHeight = containerRef.current.offsetHeight; if (newHeight !== height) { setHeight(newHeight); if (onHeightChange) { onHeightChange(newHeight); } } } }; useEffect(() => { window.addEventListener('resize', handleResize); handleResize(); return () => { window.removeEventListener('resize', handleResize); }; }, [height, onHeightChange]); const columnContainerStyles = theme ? { color: theme.mainText(), backgroundColor: theme.mainBackground(), // border: `1px solid ${theme.divider()}`, } : {}; return (
{dialogsView && (
{dialogsView}
)} {dialogMessagesView && (
{dialogMessagesView}
)} {dialogInfoView && (
{dialogInfoView}
)}
); } export default DesktopLayout;