cinny/src/app/organisms/room/Room.jsx

41 lines
1.3 KiB
React
Raw Normal View History

2021-07-28 16:15:52 +03:00
import React, { useState, useEffect } from 'react';
2021-08-31 16:13:31 +03:00
import './Room.scss';
2021-07-28 16:15:52 +03:00
import cons from '../../../client/state/cons';
import navigation from '../../../client/state/navigation';
import Welcome from '../welcome/Welcome';
2021-08-31 16:13:31 +03:00
import RoomView from './RoomView';
2021-07-28 16:15:52 +03:00
import PeopleDrawer from './PeopleDrawer';
2021-08-31 16:13:31 +03:00
function Room() {
2021-07-28 16:15:52 +03:00
const [selectedRoomId, changeSelectedRoomId] = useState(null);
const [isDrawerVisible, toggleDrawerVisiblity] = useState(navigation.isPeopleDrawerVisible);
useEffect(() => {
const handleRoomSelected = (roomId) => {
changeSelectedRoomId(roomId);
};
const handleDrawerToggling = (visiblity) => {
toggleDrawerVisiblity(visiblity);
};
navigation.on(cons.events.navigation.ROOM_SELECTED, handleRoomSelected);
navigation.on(cons.events.navigation.PEOPLE_DRAWER_TOGGLED, handleDrawerToggling);
return () => {
navigation.removeListener(cons.events.navigation.ROOM_SELECTED, handleRoomSelected);
navigation.removeListener(cons.events.navigation.PEOPLE_DRAWER_TOGGLED, handleDrawerToggling);
};
}, []);
if (selectedRoomId === null) return <Welcome />;
return (
2021-08-31 16:13:31 +03:00
<div className="room-container">
<RoomView roomId={selectedRoomId} />
2021-07-28 16:15:52 +03:00
{ isDrawerVisible && <PeopleDrawer roomId={selectedRoomId} />}
</div>
);
}
2021-08-31 16:13:31 +03:00
export default Room;