Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
Added conditional rendering for the JoinRule DropDown based on labs f…
Browse files Browse the repository at this point in the history
…eature

Signed-off-by: ankur12-1610 <[email protected]>
  • Loading branch information
ankur12-1610 committed Jul 23, 2022
1 parent df17929 commit ea01bc7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
9 changes: 7 additions & 2 deletions src/components/views/dialogs/CreateRoomDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { Room } from "matrix-js-sdk/src/models/room";
import { RoomType } from "matrix-js-sdk/src/@types/event";
import { JoinRule, Preset, Visibility } from "matrix-js-sdk/src/@types/partials";

import SettingsStore from '../../../settings/SettingsStore';
import SdkConfig from '../../../SdkConfig';
import withValidation, { IFieldState } from '../elements/Validation';
import { _t } from '../../../languageHandler';
Expand Down Expand Up @@ -59,19 +60,23 @@ interface IState {

export default class CreateRoomDialog extends React.Component<IProps, IState> {
private readonly supportsRestricted: boolean;
private readonly knockingEnabled: boolean;
private nameField = createRef<Field>();
private aliasField = createRef<RoomAliasField>();

constructor(props) {
super(props);

this.supportsRestricted = !!this.props.parentSpace;
this.knockingEnabled = SettingsStore.getValue("feature_knocking");

let joinRule = JoinRule.Invite;
if (this.props.defaultPublic) {
joinRule = JoinRule.Public;
} else if (this.supportsRestricted) {
joinRule = JoinRule.Restricted;
} else if (this.knockingEnabled) {
joinRule = JoinRule.Knock;
}

this.state = {
Expand Down Expand Up @@ -269,7 +274,7 @@ export default class CreateRoomDialog extends React.Component<IProps, IState> {
&nbsp;
{ _t("You can change this at any time from room settings.") }
</p>;
} else if (this.state.joinRule === JoinRule.Knock) {
} else if (this.state.joinRule === JoinRule.Knock && this.knockingEnabled) {
publicPrivateLabel = <p>
{ _t("Anyone can knock on this room to join.") }
&nbsp;
Expand Down Expand Up @@ -353,7 +358,7 @@ export default class CreateRoomDialog extends React.Component<IProps, IState> {
<JoinRuleDropdown
label={_t("Room visibility")}
labelInvite={_t("Private room (invite only)")}
labelKnock = {_t("Anyone can knock to join")}
labelKnock={this.knockingEnabled ? _t("Anyone can knock to join") : undefined}
labelPublic={_t("Public room")}
labelRestricted={this.supportsRestricted ? _t("Visible to space members") : undefined}
value={this.state.joinRule}
Expand Down
7 changes: 4 additions & 3 deletions src/components/views/elements/JoinRuleDropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,6 @@ const JoinRuleDropdown = ({
<div key={JoinRule.Invite} className="mx_JoinRuleDropdown_invite">
{ labelInvite }
</div>,
<div key={JoinRule.Knock} className="mx_JoinRuleDropdown_knock">
{ labelKnock }
</div>,
<div key={JoinRule.Public} className="mx_JoinRuleDropdown_public">
{ labelPublic }
</div>,
Expand All @@ -56,6 +53,10 @@ const JoinRuleDropdown = ({
options.unshift(<div key={JoinRule.Restricted} className="mx_JoinRuleDropdown_restricted">
{ labelRestricted }
</div>);
} else if (labelKnock) {
options.unshift(<div key={JoinRule.Knock} className="mx_JoinRuleDropdown_knock">
{ labelKnock }
</div>);
}

return <Dropdown
Expand Down

0 comments on commit ea01bc7

Please sign in to comment.