cinny/src/app/organisms/pw/Windows.jsx

93 lines
3 KiB
React
Raw Normal View History

2021-07-28 16:15:52 +03:00
import React, { useState, useEffect } from 'react';
import cons from '../../../client/state/cons';
import navigation from '../../../client/state/navigation';
import InviteList from '../invite-list/InviteList';
2021-08-31 16:13:31 +03:00
import PublicRooms from '../public-rooms/PublicRooms';
import CreateRoom from '../create-room/CreateRoom';
2021-07-28 16:15:52 +03:00
import InviteUser from '../invite-user/InviteUser';
import Settings from '../settings/Settings';
import SpaceSettings from '../space-settings/SpaceSettings';
2021-07-28 16:15:52 +03:00
function Windows() {
const [isInviteList, changeInviteList] = useState(false);
2021-08-31 16:13:31 +03:00
const [publicRooms, changePublicRooms] = useState({
isOpen: false, searchTerm: undefined,
});
2021-08-31 16:13:31 +03:00
const [isCreateRoom, changeCreateRoom] = useState(false);
const [inviteUser, changeInviteUser] = useState({
isOpen: false, roomId: undefined, term: undefined,
});
2021-07-28 16:15:52 +03:00
const [settings, changeSettings] = useState(false);
function openInviteList() {
changeInviteList(true);
}
2021-08-31 16:13:31 +03:00
function openPublicRooms(searchTerm) {
changePublicRooms({
isOpen: true,
searchTerm,
});
2021-07-28 16:15:52 +03:00
}
2021-08-31 16:13:31 +03:00
function openCreateRoom() {
changeCreateRoom(true);
2021-07-28 16:15:52 +03:00
}
function openInviteUser(roomId, searchTerm) {
2021-07-28 16:15:52 +03:00
changeInviteUser({
isOpen: true,
roomId,
searchTerm,
2021-07-28 16:15:52 +03:00
});
}
function openSettings() {
changeSettings(true);
}
useEffect(() => {
navigation.on(cons.events.navigation.INVITE_LIST_OPENED, openInviteList);
2021-08-31 16:13:31 +03:00
navigation.on(cons.events.navigation.PUBLIC_ROOMS_OPENED, openPublicRooms);
navigation.on(cons.events.navigation.CREATE_ROOM_OPENED, openCreateRoom);
2021-07-28 16:15:52 +03:00
navigation.on(cons.events.navigation.INVITE_USER_OPENED, openInviteUser);
navigation.on(cons.events.navigation.SETTINGS_OPENED, openSettings);
return () => {
navigation.removeListener(cons.events.navigation.INVITE_LIST_OPENED, openInviteList);
2021-08-31 16:13:31 +03:00
navigation.removeListener(cons.events.navigation.PUBLIC_ROOMS_OPENED, openPublicRooms);
navigation.removeListener(cons.events.navigation.CREATE_ROOM_OPENED, openCreateRoom);
2021-07-28 16:15:52 +03:00
navigation.removeListener(cons.events.navigation.INVITE_USER_OPENED, openInviteUser);
navigation.removeListener(cons.events.navigation.SETTINGS_OPENED, openSettings);
};
}, []);
return (
<>
<InviteList
isOpen={isInviteList}
onRequestClose={() => changeInviteList(false)}
/>
2021-08-31 16:13:31 +03:00
<PublicRooms
isOpen={publicRooms.isOpen}
searchTerm={publicRooms.searchTerm}
onRequestClose={() => changePublicRooms({ isOpen: false, searchTerm: undefined })}
2021-07-28 16:15:52 +03:00
/>
2021-08-31 16:13:31 +03:00
<CreateRoom
isOpen={isCreateRoom}
onRequestClose={() => changeCreateRoom(false)}
2021-07-28 16:15:52 +03:00
/>
<InviteUser
isOpen={inviteUser.isOpen}
roomId={inviteUser.roomId}
searchTerm={inviteUser.searchTerm}
2021-07-28 16:15:52 +03:00
onRequestClose={() => changeInviteUser({ isOpen: false, roomId: undefined })}
/>
<Settings
isOpen={settings}
onRequestClose={() => changeSettings(false)}
/>
<SpaceSettings />
2021-07-28 16:15:52 +03:00
</>
);
}
export default Windows;