mirror of
https://github.com/vector-im/element-web.git
synced 2026-05-08 13:46:16 +02:00
Update RoomPublishSetting and SpaceSettingVisibilityTab to use SettingsToggleInput with a warning
This commit is contained in:
parent
b58492fa40
commit
5454c2bfbe
@ -6,15 +6,16 @@ SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Com
|
||||
Please see LICENSE files in the repository root for full details.
|
||||
*/
|
||||
|
||||
import React, { ChangeEventHandler } from "react";
|
||||
import React, { type ChangeEventHandler } from "react";
|
||||
import { JoinRule, Visibility } from "matrix-js-sdk/src/matrix";
|
||||
import { SettingsToggleInput } from "@vector-im/compound-web";
|
||||
|
||||
import { _t } from "../../../languageHandler";
|
||||
import { MatrixClientPeg } from "../../../MatrixClientPeg";
|
||||
import DirectoryCustomisations from "../../../customisations/Directory";
|
||||
import Modal from "../../../Modal";
|
||||
import ErrorDialog from "../dialogs/ErrorDialog";
|
||||
import { SettingsToggleInput } from "@vector-im/compound-web";
|
||||
import { logger } from "matrix-js-sdk/src/logger";
|
||||
|
||||
interface IProps {
|
||||
roomId: string;
|
||||
@ -50,10 +51,13 @@ export default class RoomPublishSetting extends React.PureComponent<IProps, ISta
|
||||
const client = MatrixClientPeg.safeGet();
|
||||
|
||||
try {
|
||||
await client
|
||||
.setRoomDirectoryVisibility(this.props.roomId, newValue ? Visibility.Public : Visibility.Private)
|
||||
await client.setRoomDirectoryVisibility(
|
||||
this.props.roomId,
|
||||
newValue ? Visibility.Public : Visibility.Private,
|
||||
);
|
||||
this.setState({ isRoomPublished: newValue });
|
||||
} catch (ex) {
|
||||
logger.error("Error while setting room directory visibility", ex);
|
||||
this.showError();
|
||||
} finally {
|
||||
this.setState({ busy: false });
|
||||
@ -72,16 +76,18 @@ export default class RoomPublishSetting extends React.PureComponent<IProps, ISta
|
||||
|
||||
const room = client.getRoom(this.props.roomId);
|
||||
const isRoomPublishable = room && room.getJoinRule() !== JoinRule.Invite;
|
||||
const canSetCanonicalAlias = (DirectoryCustomisations.requireCanonicalAliasAccessToPublish?.() === false || this.props.canSetCanonicalAlias);
|
||||
const canSetCanonicalAlias =
|
||||
DirectoryCustomisations.requireCanonicalAliasAccessToPublish?.() === false ||
|
||||
this.props.canSetCanonicalAlias;
|
||||
|
||||
let disabledMessage;
|
||||
if (!isRoomPublishable) {
|
||||
disabledMessage = _t("room_settings|general|publish_warn_invite_only");
|
||||
} else if (!canSetCanonicalAlias) {
|
||||
disabledMessage = _t("room_settings|general|publish_warn_cannot_set_canonical");
|
||||
disabledMessage = _t("room_settings|general|publish_warn_no_canonical_permission");
|
||||
}
|
||||
|
||||
const enabled =canSetCanonicalAlias && (isRoomPublishable || this.state.isRoomPublished);
|
||||
const enabled = canSetCanonicalAlias && (isRoomPublishable || this.state.isRoomPublished);
|
||||
|
||||
return (
|
||||
<SettingsToggleInput
|
||||
|
||||
@ -6,7 +6,7 @@ SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Com
|
||||
Please see LICENSE files in the repository root for full details.
|
||||
*/
|
||||
|
||||
import React, { type JSX, useState } from "react";
|
||||
import React, { type ChangeEventHandler, type JSX, useCallback, useState } from "react";
|
||||
import {
|
||||
type Room,
|
||||
EventType,
|
||||
@ -15,12 +15,12 @@ import {
|
||||
JoinRule,
|
||||
type MatrixClient,
|
||||
} from "matrix-js-sdk/src/matrix";
|
||||
import { SettingsToggleInput } from "@vector-im/compound-web";
|
||||
|
||||
import { _t } from "../../../languageHandler";
|
||||
import AccessibleButton from "../elements/AccessibleButton";
|
||||
import AliasSettings from "../room_settings/AliasSettings";
|
||||
import { useStateToggle } from "../../../hooks/useStateToggle";
|
||||
import LabelledToggleSwitch from "../elements/LabelledToggleSwitch";
|
||||
import { useLocalEcho } from "../../../hooks/useLocalEcho";
|
||||
import JoinRuleSettings from "../settings/JoinRuleSettings";
|
||||
import { useRoomState } from "../../../hooks/useRoomState";
|
||||
@ -50,6 +50,7 @@ const SpaceSettingsVisibilityTab: React.FC<IProps> = ({ matrixClient: cli, space
|
||||
const userId = cli.getUserId()!;
|
||||
|
||||
const joinRule = useRoomState(space, (state) => state.getJoinRule());
|
||||
|
||||
const [guestAccessEnabled, setGuestAccessEnabled] = useLocalEcho<boolean>(
|
||||
() =>
|
||||
space.currentState.getStateEvents(EventType.RoomGuestAccess, "")?.getContent()?.guest_access ===
|
||||
@ -65,6 +66,10 @@ const SpaceSettingsVisibilityTab: React.FC<IProps> = ({ matrixClient: cli, space
|
||||
),
|
||||
() => setError(_t("room_settings|visibility|error_update_guest_access")),
|
||||
);
|
||||
const onGuestAccessEnabledChanged = useCallback<ChangeEventHandler<HTMLInputElement>>(
|
||||
(e) => setGuestAccessEnabled(e.target.checked),
|
||||
[setGuestAccessEnabled],
|
||||
);
|
||||
const [historyVisibility, setHistoryVisibility] = useLocalEcho<HistoryVisibility>(
|
||||
() =>
|
||||
space.currentState.getStateEvents(EventType.RoomHistoryVisibility, "")?.getContent()?.history_visibility ||
|
||||
@ -104,17 +109,15 @@ const SpaceSettingsVisibilityTab: React.FC<IProps> = ({ matrixClient: cli, space
|
||||
|
||||
{showAdvancedSection && (
|
||||
<div className="mx_SettingsTab_toggleWithDescription">
|
||||
<LabelledToggleSwitch
|
||||
value={guestAccessEnabled}
|
||||
onChange={setGuestAccessEnabled}
|
||||
<SettingsToggleInput
|
||||
name="guest-access-enabled"
|
||||
checked={guestAccessEnabled}
|
||||
onChange={onGuestAccessEnabledChanged}
|
||||
disabled={!canSetGuestAccess}
|
||||
disabledMessage={_t("room_settings|visibility|guest_access_disabled")}
|
||||
helpMessage={_t("room_settings|visibility|guest_access_explainer")}
|
||||
label={_t("room_settings|visibility|guest_access_label")}
|
||||
/>
|
||||
<p>
|
||||
{_t("room_settings|visibility|guest_access_explainer")}
|
||||
<br />
|
||||
{_t("room_settings|visibility|guest_access_explainer_public_space")}
|
||||
</p>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
@ -157,19 +160,20 @@ const SpaceSettingsVisibilityTab: React.FC<IProps> = ({ matrixClient: cli, space
|
||||
/>
|
||||
{advancedSection}
|
||||
<div className="mx_SettingsTab_toggleWithDescription">
|
||||
<LabelledToggleSwitch
|
||||
value={historyVisibility === HistoryVisibility.WorldReadable}
|
||||
onChange={(checked: boolean): void => {
|
||||
<SettingsToggleInput
|
||||
name="space-history-visibility"
|
||||
checked={historyVisibility === HistoryVisibility.WorldReadable}
|
||||
onChange={(evt): void => {
|
||||
setHistoryVisibility(
|
||||
checked ? HistoryVisibility.WorldReadable : HistoryVisibility.Shared,
|
||||
evt.target.checked ? HistoryVisibility.WorldReadable : HistoryVisibility.Shared,
|
||||
);
|
||||
}}
|
||||
helpMessage={_t("room_settings|visibility|history_visibility_anyone_space_description")}
|
||||
disabled={!canSetHistoryVisibility}
|
||||
disabledMessage={_t("room_settings|visibility|history_visibility_anyone_space_disabled")}
|
||||
label={_t("room_settings|visibility|history_visibility_anyone_space")}
|
||||
/>
|
||||
<p>
|
||||
{_t("room_settings|visibility|history_visibility_anyone_space_description")}
|
||||
<br />
|
||||
<strong>
|
||||
{_t("room_settings|visibility|history_visibility_anyone_space_recommendation")}
|
||||
</strong>
|
||||
|
||||
@ -2281,6 +2281,8 @@
|
||||
"no_aliases_space": "This space has no local addresses",
|
||||
"other_section": "Other",
|
||||
"publish_toggle": "Publish this room to the public in %(domain)s's room directory?",
|
||||
"publish_warn_invite_only": "You cannot publish a room that is invite-only.",
|
||||
"publish_warn_no_canonical_permission": "You must have permission to set the main address to publish this room.",
|
||||
"published_aliases_description": "To publish an address, it needs to be set as a local address first.",
|
||||
"published_aliases_explainer_room": "Published addresses can be used by anyone on any server to join your room.",
|
||||
"published_aliases_explainer_space": "Published addresses can be used by anyone on any server to join your space.",
|
||||
@ -2431,11 +2433,12 @@
|
||||
"error_failed_save": "Failed to update the visibility of this space",
|
||||
"error_update_guest_access": "Failed to update the guest access of this space",
|
||||
"error_update_history_visibility": "Failed to update the history visibility of this space",
|
||||
"guest_access_explainer": "Guests can join a space without having an account.",
|
||||
"guest_access_explainer_public_space": "This may be useful for public spaces.",
|
||||
"guest_access_explainer": "Guests can join a space without having an account. This may be useful for public spaces.",
|
||||
"guest_access_label": "Enable guest access",
|
||||
"guest_access_disabled": "You do not have permission to change guest access.",
|
||||
"history_visibility_anyone_space": "Preview Space",
|
||||
"history_visibility_anyone_space_description": "Allow people to preview your space before they join.",
|
||||
"history_visibility_anyone_space_disabled":"You do not have permission to change history visibilty.",
|
||||
"history_visibility_anyone_space_recommendation": "Recommended for public spaces.",
|
||||
"title": "Visibility"
|
||||
},
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user