diff --git a/src/app/molecules/space-options/SpaceOptions.jsx b/src/app/molecules/space-options/SpaceOptions.jsx new file mode 100644 index 0000000..cfa8012 --- /dev/null +++ b/src/app/molecules/space-options/SpaceOptions.jsx @@ -0,0 +1,83 @@ +import React from 'react'; +import PropTypes from 'prop-types'; + +import { twemojify } from '../../../util/twemojify'; + +import initMatrix from '../../../client/initMatrix'; +import { openSpaceSettings, openInviteUser } from '../../../client/action/navigation'; +import { leave, createSpaceShortcut, deleteSpaceShortcut } from '../../../client/action/room'; + +import { MenuHeader, MenuItem } from '../../atoms/context-menu/ContextMenu'; + +import AddUserIC from '../../../../public/res/ic/outlined/add-user.svg'; +import SettingsIC from '../../../../public/res/ic/outlined/settings.svg'; +import LeaveArrowIC from '../../../../public/res/ic/outlined/leave-arrow.svg'; +import PinIC from '../../../../public/res/ic/outlined/pin.svg'; +import PinFilledIC from '../../../../public/res/ic/filled/pin.svg'; + +function SpaceOptions({ roomId, afterOptionSelect }) { + const mx = initMatrix.matrixClient; + const room = mx.getRoom(roomId); + const canInvite = room?.canInvite(mx.getUserId()); + const isPinned = initMatrix.roomList.spaceShortcut.has(roomId); + + const handleInviteClick = () => { + openInviteUser(roomId); + afterOptionSelect(); + }; + const handlePinClick = () => { + if (isPinned) deleteSpaceShortcut(roomId); + else createSpaceShortcut(roomId); + afterOptionSelect(); + }; + + const handleSettingsClick = () => { + openSpaceSettings(roomId); + afterOptionSelect(); + }; + + const handleLeaveClick = () => { + if (confirm('Are you really want to leave this space?')) { + leave(roomId); + afterOptionSelect(); + } + }; + + return ( + <> + {twemojify(`Options for ${initMatrix.matrixClient.getRoom(roomId)?.name}`)} + + {isPinned ? 'Unpin from sidebar' : 'Pin to sidebar'} + + + Invite + + Settings + + Leave + + + ); +} + +SpaceOptions.defaultProps = { + afterOptionSelect: null, +}; + +SpaceOptions.propTypes = { + roomId: PropTypes.string.isRequired, + afterOptionSelect: PropTypes.func, +}; + +export default SpaceOptions; diff --git a/src/app/organisms/navigation/DrawerHeader.jsx b/src/app/organisms/navigation/DrawerHeader.jsx index acdd48b..98a3eb4 100644 --- a/src/app/organisms/navigation/DrawerHeader.jsx +++ b/src/app/organisms/navigation/DrawerHeader.jsx @@ -7,9 +7,10 @@ import { twemojify } from '../../../util/twemojify'; import initMatrix from '../../../client/initMatrix'; import cons from '../../../client/state/cons'; import { - openSpaceSettings, openPublicRooms, openCreateRoom, openInviteUser, + openPublicRooms, openCreateRoom, openInviteUser, openReusableContextMenu, } from '../../../client/action/navigation'; import { createSpaceShortcut, deleteSpaceShortcut } from '../../../client/action/room'; +import { getEventCords } from '../../../util/common'; import { blurOnBubbling } from '../../atoms/button/script'; @@ -18,6 +19,7 @@ import RawIcon from '../../atoms/system-icons/RawIcon'; import Header, { TitleWrapper } from '../../atoms/header/Header'; import IconButton from '../../atoms/button/IconButton'; import ContextMenu, { MenuItem, MenuHeader } from '../../atoms/context-menu/ContextMenu'; +import SpaceOptions from '../../molecules/space-options/SpaceOptions'; import PlusIC from '../../../../public/res/ic/outlined/plus.svg'; import HashPlusIC from '../../../../public/res/ic/outlined/hash-plus.svg'; @@ -35,12 +37,21 @@ function DrawerHeader({ selectedTab, spaceId }) { const room = mx.getRoom(spaceId); const spaceName = selectedTab === cons.tabs.DIRECTS ? null : (room?.name || null); + const openSpaceOptions = (e) => { + e.preventDefault(); + openReusableContextMenu( + 'bottom', + getEventCords(e, '.drawer-header__btn'), + (closeMenu) => , + ); + }; + return (
{spaceName ? (