From e06b9c4a68b548c2f044698221c03d93aa23b0a4 Mon Sep 17 00:00:00 2001 From: Charly Nguyen Date: Tue, 29 Aug 2023 16:18:08 +0200 Subject: [PATCH 1/3] Allow creating public knock rooms Signed-off-by: Charly Nguyen --- res/css/views/dialogs/_CreateRoomDialog.pcss | 5 ++ .../views/dialogs/CreateRoomDialog.tsx | 19 ++++ .../views/elements/LabelledCheckbox.tsx | 7 +- src/i18n/strings/en_EN.json | 1 + .../views/dialogs/CreateRoomDialog-test.tsx | 87 ++++++++++++------- .../views/elements/LabelledCheckbox-test.tsx | 12 +++ 6 files changed, 99 insertions(+), 32 deletions(-) diff --git a/res/css/views/dialogs/_CreateRoomDialog.pcss b/res/css/views/dialogs/_CreateRoomDialog.pcss index 437044cc8fe..4e3d90cffe6 100644 --- a/res/css/views/dialogs/_CreateRoomDialog.pcss +++ b/res/css/views/dialogs/_CreateRoomDialog.pcss @@ -113,3 +113,8 @@ limitations under the License. font-size: $font-12px; } } + +.mx_CreateRoomDialog_labelledCheckbox { + color: $muted-fg-color; + margin-top: var(--cpd-space-6x); +} diff --git a/src/components/views/dialogs/CreateRoomDialog.tsx b/src/components/views/dialogs/CreateRoomDialog.tsx index 276f1195b3d..6546d06a43e 100644 --- a/src/components/views/dialogs/CreateRoomDialog.tsx +++ b/src/components/views/dialogs/CreateRoomDialog.tsx @@ -33,6 +33,7 @@ import { getKeyBindingsManager } from "../../../KeyBindingsManager"; import { KeyBindingAction } from "../../../accessibility/KeyboardShortcuts"; import { privateShouldBeEncrypted } from "../../../utils/rooms"; import SettingsStore from "../../../settings/SettingsStore"; +import LabelledCheckbox from "../elements/LabelledCheckbox"; interface IProps { type?: RoomType; @@ -129,6 +130,7 @@ export default class CreateRoomDialog extends React.Component { if (this.state.joinRule === JoinRule.Knock) { opts.joinRule = JoinRule.Knock; + createOpts.visibility = this.state.isPublic ? Visibility.Public : Visibility.Private; } return opts; @@ -215,6 +217,10 @@ export default class CreateRoomDialog extends React.Component { return result; }; + private onIsPublicChange = (isPublic: boolean): void => { + this.setState({ isPublic }); + }; + private static validateRoomName = withValidation({ rules: [ { @@ -298,6 +304,18 @@ export default class CreateRoomDialog extends React.Component { ); } + let visibilitySection: JSX.Element | undefined; + if (this.state.joinRule === JoinRule.Knock) { + visibilitySection = ( + + ); + } + let e2eeSection: JSX.Element | undefined; if (this.state.joinRule !== JoinRule.Public) { let microcopy: string; @@ -383,6 +401,7 @@ export default class CreateRoomDialog extends React.Component { /> {publicPrivateLabel} + {visibilitySection} {e2eeSection} {aliasField}
diff --git a/src/components/views/elements/LabelledCheckbox.tsx b/src/components/views/elements/LabelledCheckbox.tsx index 86604d0989a..72eded8203a 100644 --- a/src/components/views/elements/LabelledCheckbox.tsx +++ b/src/components/views/elements/LabelledCheckbox.tsx @@ -15,6 +15,7 @@ limitations under the License. */ import React from "react"; +import classnames from "classnames"; import StyledCheckbox from "./StyledCheckbox"; @@ -29,11 +30,13 @@ interface IProps { disabled?: boolean; // The function to call when the value changes onChange(checked: boolean): void; + // Optional CSS class to apply to the label + className?: string; } -const LabelledCheckbox: React.FC = ({ value, label, byline, disabled, onChange }) => { +const LabelledCheckbox: React.FC = ({ value, label, byline, disabled, onChange, className }) => { return ( -