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';
|
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';
|
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';
|
|
|
|
import InfoIC from '../../../../public/res/ic/outlined/info.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';
|
|
|
|
|
|
|
|
const tabItems = [{
|
|
|
|
iconSrc: SettingsIC,
|
|
|
|
text: 'General',
|
|
|
|
disabled: false,
|
|
|
|
}, {
|
|
|
|
iconSrc: SearchIC,
|
|
|
|
text: 'Search',
|
|
|
|
disabled: false,
|
|
|
|
}, {
|
|
|
|
iconSrc: ShieldUserIC,
|
|
|
|
text: 'Permissions',
|
|
|
|
disabled: false,
|
|
|
|
}, {
|
|
|
|
iconSrc: LockIC,
|
|
|
|
text: 'Security',
|
|
|
|
disabled: false,
|
|
|
|
}, {
|
|
|
|
iconSrc: InfoIC,
|
|
|
|
text: 'Advanced',
|
|
|
|
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">
|
|
|
|
<MenuHeader>Visibility (who can join)</MenuHeader>
|
|
|
|
<RoomVisibility roomId={roomId} />
|
|
|
|
</div>
|
2021-12-24 11:39:58 +02:00
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
GeneralSettings.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">
|
2021-12-24 11:39:58 +02:00
|
|
|
{selectedTab.text === tabItems[0].text && <GeneralSettings roomId={roomId} />}
|
2021-12-22 16:48:32 +02:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</ScrollView>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
RoomSettings.propTypes = {
|
|
|
|
roomId: PropTypes.string.isRequired,
|
|
|
|
};
|
|
|
|
|
|
|
|
export default RoomSettings;
|