Add a create room in space CTA to Space View

This commit is contained in:
Michael Telatynski 2021-03-02 13:28:05 +00:00
parent ab4b7b73ea
commit a687b9883c
5 changed files with 51 additions and 1 deletions

View file

@ -188,6 +188,16 @@ $SpaceRoomViewInnerWidth: 428px;
} }
} }
&.mx_SpaceRoomView_landing_createButton {
&::before {
background-color: #368bd6;
}
&::after {
mask-image: url('$(res)/img/element-icons/roomlist/explore.svg');
}
}
&.mx_SpaceRoomView_landing_settingsButton { &.mx_SpaceRoomView_landing_settingsButton {
&::before { &::before {
background-color: #5c56f5; background-color: #5c56f5;

View file

@ -46,7 +46,7 @@ import {RightPanelPhases} from "../../stores/RightPanelStorePhases";
import {SetRightPanelPhasePayload} from "../../dispatcher/payloads/SetRightPanelPhasePayload"; import {SetRightPanelPhasePayload} from "../../dispatcher/payloads/SetRightPanelPhasePayload";
import {useStateArray} from "../../hooks/useStateArray"; import {useStateArray} from "../../hooks/useStateArray";
import SpacePublicShare from "../views/spaces/SpacePublicShare"; import SpacePublicShare from "../views/spaces/SpacePublicShare";
import {shouldShowSpaceSettings, showSpaceSettings} from "../../utils/space"; import {showCreateNewRoom, shouldShowSpaceSettings, showSpaceSettings} from "../../utils/space";
import MemberAvatar from "../views/avatars/MemberAvatar"; import MemberAvatar from "../views/avatars/MemberAvatar";
interface IProps { interface IProps {
@ -119,6 +119,19 @@ const SpaceLanding = ({ space, onJoinButtonClicked, onRejectButtonClicked }) =>
); );
} }
const canAddRooms = myMembership === "join" && space.currentState.maySendStateEvent(EventType.SpaceChild, userId);
let addRoomButtons;
if (canAddRooms) {
addRoomButtons = <React.Fragment>
<AccessibleButton className="mx_SpaceRoomView_landing_createButton" onClick={() => {
showCreateNewRoom(cli, space);
}}>
{ _t("Create a new room") }
</AccessibleButton>
</React.Fragment>;
}
let settingsButton; let settingsButton;
if (shouldShowSpaceSettings(cli, space)) { if (shouldShowSpaceSettings(cli, space)) {
settingsButton = <AccessibleButton className="mx_SpaceRoomView_landing_settingsButton" onClick={() => { settingsButton = <AccessibleButton className="mx_SpaceRoomView_landing_settingsButton" onClick={() => {
@ -189,6 +202,7 @@ const SpaceLanding = ({ space, onJoinButtonClicked, onRejectButtonClicked }) =>
{ joinButtons } { joinButtons }
<div className="mx_SpaceRoomView_landing_adminButtons"> <div className="mx_SpaceRoomView_landing_adminButtons">
{ inviteButton } { inviteButton }
{ addRoomButtons }
{ settingsButton } { settingsButton }
</div> </div>
</div>; </div>;

View file

@ -17,6 +17,8 @@ limitations under the License.
import React from 'react'; import React from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import {Room} from "matrix-js-sdk/src/models/room";
import * as sdk from '../../../index'; import * as sdk from '../../../index';
import SdkConfig from '../../../SdkConfig'; import SdkConfig from '../../../SdkConfig';
import withValidation from '../elements/Validation'; import withValidation from '../elements/Validation';
@ -30,6 +32,7 @@ export default class CreateRoomDialog extends React.Component {
static propTypes = { static propTypes = {
onFinished: PropTypes.func.isRequired, onFinished: PropTypes.func.isRequired,
defaultPublic: PropTypes.bool, defaultPublic: PropTypes.bool,
parentSpace: PropTypes.instanceOf(Room),
}; };
constructor(props) { constructor(props) {
@ -85,6 +88,10 @@ export default class CreateRoomDialog extends React.Component {
opts.associatedWithCommunity = CommunityPrototypeStore.instance.getSelectedCommunityId(); opts.associatedWithCommunity = CommunityPrototypeStore.instance.getSelectedCommunityId();
} }
if (this.props.parentSpace) {
opts.parentSpace = this.props.parentSpace;
}
return opts; return opts;
} }

View file

@ -2570,6 +2570,7 @@
"You have %(count)s unread notifications in a prior version of this room.|one": "You have %(count)s unread notification in a prior version of this room.", "You have %(count)s unread notifications in a prior version of this room.|one": "You have %(count)s unread notification in a prior version of this room.",
"Accept Invite": "Accept Invite", "Accept Invite": "Accept Invite",
"Invite people": "Invite people", "Invite people": "Invite people",
"Create a new room": "Create a new room",
"%(count)s members|other": "%(count)s members", "%(count)s members|other": "%(count)s members",
"%(count)s members|one": "%(count)s member", "%(count)s members|one": "%(count)s member",
"<inviter/> invited you to <name/>": "<inviter/> invited you to <name/>", "<inviter/> invited you to <name/>": "<inviter/> invited you to <name/>",

View file

@ -21,6 +21,8 @@ import {EventType} from "matrix-js-sdk/src/@types/event";
import {calculateRoomVia} from "../utils/permalinks/Permalinks"; import {calculateRoomVia} from "../utils/permalinks/Permalinks";
import Modal from "../Modal"; import Modal from "../Modal";
import SpaceSettingsDialog from "../components/views/dialogs/SpaceSettingsDialog"; import SpaceSettingsDialog from "../components/views/dialogs/SpaceSettingsDialog";
import CreateRoomDialog from "../components/views/dialogs/CreateRoomDialog";
import createRoom, {IOpts} from "../createRoom";
export const shouldShowSpaceSettings = (cli: MatrixClient, space: Room) => { export const shouldShowSpaceSettings = (cli: MatrixClient, space: Room) => {
const userId = cli.getUserId(); const userId = cli.getUserId();
@ -46,3 +48,19 @@ export const showSpaceSettings = (cli: MatrixClient, space: Room) => {
space, space,
}, /*className=*/null, /*isPriority=*/false, /*isStatic=*/true); }, /*className=*/null, /*isPriority=*/false, /*isStatic=*/true);
}; };
export const showCreateNewRoom = async (cli: MatrixClient, space: Room) => {
const modal = Modal.createTrackedDialog<[boolean, IOpts]>(
"Space Landing",
"Create Room",
CreateRoomDialog,
{
defaultPublic: space.getJoinRule() === "public",
parentSpace: space,
},
);
const [shouldCreate, opts] = await modal.finished;
if (shouldCreate) {
await createRoom(opts);
}
};