2021-12-24 11:39:58 +02:00
|
|
|
import React, { useState, useEffect } from 'react';
|
2021-12-22 16:48:32 +02:00
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import './RoomSettings.scss';
|
|
|
|
|
2021-12-24 11:39:58 +02:00
|
|
|
import initMatrix from '../../../client/initMatrix';
|
2021-12-22 16:48:32 +02:00
|
|
|
import cons from '../../../client/state/cons';
|
|
|
|
import navigation from '../../../client/state/navigation';
|
2021-12-24 11:39:58 +02:00
|
|
|
import { openInviteUser } from '../../../client/action/navigation';
|
|
|
|
import * as roomActions from '../../../client/action/room';
|
2021-12-22 16:48:32 +02:00
|
|
|
|
|
|
|
import Text from '../../atoms/text/Text';
|
|
|
|
import Header, { TitleWrapper } from '../../atoms/header/Header';
|
|
|
|
import ScrollView from '../../atoms/scroll/ScrollView';
|
|
|
|
import Tabs from '../../atoms/tabs/Tabs';
|
2021-12-24 11:39:58 +02:00
|
|
|
import { MenuHeader, MenuItem } from '../../atoms/context-menu/ContextMenu';
|
2021-12-22 16:48:32 +02:00
|
|
|
import RoomProfile from '../../molecules/room-profile/RoomProfile';
|
2022-01-16 10:47:50 +02:00
|
|
|
import RoomSearch from '../../molecules/room-search/RoomSearch';
|
2021-12-24 11:39:58 +02:00
|
|
|
import RoomNotification from '../../molecules/room-notification/RoomNotification';
|
2021-12-26 12:04:20 +02:00
|
|
|
import RoomVisibility from '../../molecules/room-visibility/RoomVisibility';
|
2022-01-01 08:13:35 +02:00
|
|
|
import RoomAliases from '../../molecules/room-aliases/RoomAliases';
|
2022-01-01 12:57:36 +02:00
|
|
|
import RoomHistoryVisibility from '../../molecules/room-history-visibility/RoomHistoryVisibility';
|
2022-01-02 08:38:19 +02:00
|
|
|
import RoomEncryption from '../../molecules/room-encryption/RoomEncryption';
|
2022-01-10 17:04:54 +02:00
|
|
|
import RoomPermissions from '../../molecules/room-permissions/RoomPermissions';
|
2021-12-22 16:48:32 +02:00
|
|
|
|
|
|
|
import SettingsIC from '../../../../public/res/ic/outlined/settings.svg';
|
|
|
|
import SearchIC from '../../../../public/res/ic/outlined/search.svg';
|
|
|
|
import ShieldUserIC from '../../../../public/res/ic/outlined/shield-user.svg';
|
|
|
|
import LockIC from '../../../../public/res/ic/outlined/lock.svg';
|
2021-12-24 11:39:58 +02:00
|
|
|
import AddUserIC from '../../../../public/res/ic/outlined/add-user.svg';
|
|
|
|
import LeaveArrowIC from '../../../../public/res/ic/outlined/leave-arrow.svg';
|
2021-12-22 16:48:32 +02:00
|
|
|
|
|
|
|
import { useForceUpdate } from '../../hooks/useForceUpdate';
|
|
|
|
|
2022-01-01 12:57:36 +02:00
|
|
|
const tabText = {
|
|
|
|
GENERAL: 'General',
|
|
|
|
SEARCH: 'Search',
|
|
|
|
PERMISSIONS: 'Permissions',
|
|
|
|
SECURITY: 'Security',
|
|
|
|
};
|
|
|
|
|
2021-12-22 16:48:32 +02:00
|
|
|
const tabItems = [{
|
|
|
|
iconSrc: SettingsIC,
|
2022-01-01 12:57:36 +02:00
|
|
|
text: tabText.GENERAL,
|
2021-12-22 16:48:32 +02:00
|
|
|
disabled: false,
|
|
|
|
}, {
|
|
|
|
iconSrc: SearchIC,
|
2022-01-01 12:57:36 +02:00
|
|
|
text: tabText.SEARCH,
|
2021-12-22 16:48:32 +02:00
|
|
|
disabled: false,
|
|
|
|
}, {
|
|
|
|
iconSrc: ShieldUserIC,
|
2022-01-01 12:57:36 +02:00
|
|
|
text: tabText.PERMISSIONS,
|
2021-12-22 16:48:32 +02:00
|
|
|
disabled: false,
|
|
|
|
}, {
|
|
|
|
iconSrc: LockIC,
|
2022-01-01 12:57:36 +02:00
|
|
|
text: tabText.SECURITY,
|
2021-12-22 16:48:32 +02:00
|
|
|
disabled: false,
|
|
|
|
}];
|
|
|
|
|
2021-12-24 11:39:58 +02:00
|
|
|
function GeneralSettings({ roomId }) {
|
|
|
|
const mx = initMatrix.matrixClient;
|
|
|
|
const room = mx.getRoom(roomId);
|
|
|
|
const canInvite = room.canInvite(mx.getUserId());
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<div className="room-settings__card">
|
2021-12-26 12:04:20 +02:00
|
|
|
<MenuHeader>Notification (Changing this will only affect you)</MenuHeader>
|
2021-12-24 11:39:58 +02:00
|
|
|
<RoomNotification roomId={roomId} />
|
|
|
|
</div>
|
|
|
|
<div className="room-settings__card">
|
|
|
|
<MenuItem
|
|
|
|
disabled={!canInvite}
|
|
|
|
onClick={() => openInviteUser(roomId)}
|
|
|
|
iconSrc={AddUserIC}
|
|
|
|
>
|
|
|
|
Invite
|
|
|
|
</MenuItem>
|
|
|
|
<MenuItem variant="danger" onClick={() => roomActions.leave(roomId)} iconSrc={LeaveArrowIC}>Leave</MenuItem>
|
|
|
|
</div>
|
2021-12-26 12:04:20 +02:00
|
|
|
<div className="room-settings__card">
|
2022-01-01 08:13:35 +02:00
|
|
|
<MenuHeader>Room visibility (who can join)</MenuHeader>
|
2021-12-26 12:04:20 +02:00
|
|
|
<RoomVisibility roomId={roomId} />
|
|
|
|
</div>
|
2022-01-01 08:13:35 +02:00
|
|
|
<div className="room-settings__card">
|
|
|
|
<MenuHeader>Room addresses</MenuHeader>
|
|
|
|
<RoomAliases roomId={roomId} />
|
|
|
|
</div>
|
2021-12-24 11:39:58 +02:00
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
GeneralSettings.propTypes = {
|
|
|
|
roomId: PropTypes.string.isRequired,
|
|
|
|
};
|
|
|
|
|
2022-01-01 12:57:36 +02:00
|
|
|
function SecuritySettings({ roomId }) {
|
|
|
|
return (
|
|
|
|
<>
|
2022-01-02 08:38:19 +02:00
|
|
|
<div className="room-settings__card">
|
|
|
|
<MenuHeader>Encryption</MenuHeader>
|
|
|
|
<RoomEncryption roomId={roomId} />
|
|
|
|
</div>
|
2022-01-01 12:57:36 +02:00
|
|
|
<div className="room-settings__card">
|
|
|
|
<MenuHeader>Message history visibility (Who can read history)</MenuHeader>
|
|
|
|
<RoomHistoryVisibility roomId={roomId} />
|
|
|
|
</div>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
SecuritySettings.propTypes = {
|
|
|
|
roomId: PropTypes.string.isRequired,
|
|
|
|
};
|
|
|
|
|
2021-12-22 16:48:32 +02:00
|
|
|
function RoomSettings({ roomId }) {
|
|
|
|
const [, forceUpdate] = useForceUpdate();
|
2021-12-24 11:39:58 +02:00
|
|
|
const [selectedTab, setSelectedTab] = useState(tabItems[0]);
|
|
|
|
|
|
|
|
const handleTabChange = (tabItem) => {
|
|
|
|
setSelectedTab(tabItem);
|
|
|
|
};
|
2021-12-22 16:48:32 +02:00
|
|
|
|
|
|
|
useEffect(() => {
|
2021-12-24 11:39:58 +02:00
|
|
|
let mounted = true;
|
2021-12-22 16:48:32 +02:00
|
|
|
const settingsToggle = (isVisible) => {
|
2021-12-24 11:39:58 +02:00
|
|
|
if (!mounted) return;
|
2021-12-22 16:48:32 +02:00
|
|
|
if (isVisible) forceUpdate();
|
|
|
|
else setTimeout(() => forceUpdate(), 200);
|
|
|
|
};
|
|
|
|
navigation.on(cons.events.navigation.ROOM_SETTINGS_TOGGLED, settingsToggle);
|
|
|
|
return () => {
|
2021-12-24 11:39:58 +02:00
|
|
|
mounted = false;
|
2021-12-22 16:48:32 +02:00
|
|
|
navigation.removeListener(cons.events.navigation.ROOM_SETTINGS_TOGGLED, settingsToggle);
|
|
|
|
};
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
if (!navigation.isRoomSettings) return null;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="room-settings">
|
|
|
|
<ScrollView autoHide>
|
|
|
|
<div className="room-settings__content">
|
|
|
|
<Header>
|
|
|
|
<TitleWrapper>
|
|
|
|
<Text variant="s1" weight="medium" primary>Room settings</Text>
|
|
|
|
</TitleWrapper>
|
|
|
|
</Header>
|
|
|
|
<RoomProfile roomId={roomId} />
|
2021-12-26 12:04:20 +02:00
|
|
|
<Tabs
|
|
|
|
items={tabItems}
|
|
|
|
defaultSelected={tabItems.findIndex((tab) => tab.text === selectedTab.text)}
|
|
|
|
onSelect={handleTabChange}
|
|
|
|
/>
|
2021-12-22 16:48:32 +02:00
|
|
|
<div className="room-settings__cards-wrapper">
|
2022-01-01 12:57:36 +02:00
|
|
|
{selectedTab.text === tabText.GENERAL && <GeneralSettings roomId={roomId} />}
|
2022-01-16 10:47:50 +02:00
|
|
|
{selectedTab.text === tabText.SEARCH && <RoomSearch roomId={roomId} />}
|
2022-01-10 17:04:54 +02:00
|
|
|
{selectedTab.text === tabText.PERMISSIONS && <RoomPermissions roomId={roomId} />}
|
2022-01-01 12:57:36 +02:00
|
|
|
{selectedTab.text === tabText.SECURITY && <SecuritySettings roomId={roomId} />}
|
2021-12-22 16:48:32 +02:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</ScrollView>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
RoomSettings.propTypes = {
|
|
|
|
roomId: PropTypes.string.isRequired,
|
|
|
|
};
|
|
|
|
|
|
|
|
export default RoomSettings;
|