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
|
|
|
|
2021-12-03 15:02:10 +02:00
|
|
|
import initMatrix from '../../../client/initMatrix';
|
2021-07-28 16:15:52 +03:00
|
|
|
import cons from '../../../client/state/cons';
|
|
|
|
import navigation from '../../../client/state/navigation';
|
2021-11-15 05:53:59 +02:00
|
|
|
import settings from '../../../client/state/settings';
|
2021-12-03 15:02:10 +02:00
|
|
|
import RoomTimeline from '../../../client/state/RoomTimeline';
|
2021-07-28 16:15:52 +03:00
|
|
|
|
|
|
|
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-12-03 15:02:10 +02:00
|
|
|
const [roomTimeline, setRoomTimeline] = useState(null);
|
|
|
|
const [eventId, setEventId] = useState(null);
|
|
|
|
const [isDrawer, setIsDrawer] = useState(settings.isPeopleDrawer);
|
|
|
|
|
|
|
|
const mx = initMatrix.matrixClient;
|
|
|
|
const handleRoomSelected = (rId, pRoomId, eId) => {
|
|
|
|
if (mx.getRoom(rId)) {
|
2021-12-08 10:19:47 +02:00
|
|
|
setRoomTimeline(new RoomTimeline(rId, initMatrix.notifications));
|
2021-12-03 15:02:10 +02:00
|
|
|
setEventId(eId);
|
|
|
|
} else {
|
|
|
|
// TODO: add ability to join room if roomId is invalid
|
|
|
|
setRoomTimeline(null);
|
|
|
|
setEventId(null);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
const handleDrawerToggling = (visiblity) => setIsDrawer(visiblity);
|
|
|
|
|
2021-07-28 16:15:52 +03:00
|
|
|
useEffect(() => {
|
|
|
|
navigation.on(cons.events.navigation.ROOM_SELECTED, handleRoomSelected);
|
2021-11-15 05:53:59 +02:00
|
|
|
settings.on(cons.events.settings.PEOPLE_DRAWER_TOGGLED, handleDrawerToggling);
|
2021-07-28 16:15:52 +03:00
|
|
|
return () => {
|
|
|
|
navigation.removeListener(cons.events.navigation.ROOM_SELECTED, handleRoomSelected);
|
2021-11-15 05:53:59 +02:00
|
|
|
settings.removeListener(cons.events.settings.PEOPLE_DRAWER_TOGGLED, handleDrawerToggling);
|
2021-12-03 15:02:10 +02:00
|
|
|
roomTimeline?.removeInternalListeners();
|
2021-07-28 16:15:52 +03:00
|
|
|
};
|
|
|
|
}, []);
|
|
|
|
|
2021-12-03 15:02:10 +02:00
|
|
|
if (roomTimeline === null) return <Welcome />;
|
2021-07-28 16:15:52 +03:00
|
|
|
|
|
|
|
return (
|
2021-08-31 16:13:31 +03:00
|
|
|
<div className="room-container">
|
2021-12-03 15:02:10 +02:00
|
|
|
<RoomView roomTimeline={roomTimeline} eventId={eventId} />
|
|
|
|
{ isDrawer && <PeopleDrawer roomId={roomTimeline.roomId} />}
|
2021-07-28 16:15:52 +03:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-08-31 16:13:31 +03:00
|
|
|
export default Room;
|