* Replace icons with Compound alternatives Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Remove unused icon Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Replace more icons with Compound alternatives Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Swap for outline icons in spotlight & update screenshots Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Switch emoji picker to use emoji for header icons Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Update screenshot Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Update football emoji Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Switch from svg masks to svg rendering in ExtensionsCard Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Switch from svg masks to svg rendering in BaseCard Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Switch from svg masks to svg rendering in EmojiPicker Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Switch from svg masks to svg rendering in Spotlight Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Update snapshot Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Update screenshots Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Tweak emoji and fix disabled state Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Switch from svg masks to svg rendering in HomePage Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Switch from svg masks to svg rendering in DecoratedRoomAvatar Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Switch from svg masks to svg rendering in SpaceRoomView Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Switch from svg masks to svg rendering in DialPadBackspaceButton Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Switch from svg masks to svg rendering in NewRoomIntro Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Switch from svg masks to svg rendering in SpaceCreateMenu Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Switch from svg masks to svg rendering in InlineTermsAgreement Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Switch from svg masks to svg rendering in PollCreateDialog Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Switch from svg masks to svg rendering in ServerPicker Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Revert size change Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Delint Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Update snapshots Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --------- Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
104 lines
3.5 KiB
TypeScript
104 lines
3.5 KiB
TypeScript
/*
|
|
Copyright 2024 New Vector Ltd.
|
|
Copyright 2020, 2021 The Matrix.org Foundation C.I.C.
|
|
|
|
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial
|
|
Please see LICENSE files in the repository root for full details.
|
|
*/
|
|
|
|
import React from "react";
|
|
import { InfoIcon } from "@vector-im/compound-design-tokens/assets/web/icons";
|
|
|
|
import AccessibleButton from "./AccessibleButton";
|
|
import { type ValidatedServerConfig } from "../../../utils/ValidatedServerConfig";
|
|
import { _t } from "../../../languageHandler";
|
|
import TextWithTooltip from "./TextWithTooltip";
|
|
import SdkConfig from "../../../SdkConfig";
|
|
import Modal from "../../../Modal";
|
|
import ServerPickerDialog from "../dialogs/ServerPickerDialog";
|
|
import InfoDialog from "../dialogs/InfoDialog";
|
|
|
|
interface IProps {
|
|
title?: string;
|
|
dialogTitle?: string;
|
|
serverConfig: ValidatedServerConfig;
|
|
disabled?: boolean;
|
|
onServerConfigChange?(config: ValidatedServerConfig): void;
|
|
}
|
|
|
|
const showPickerDialog = (
|
|
title: string | undefined,
|
|
serverConfig: ValidatedServerConfig,
|
|
onFinished: (config?: ValidatedServerConfig) => void,
|
|
): void => {
|
|
const { finished } = Modal.createDialog(ServerPickerDialog, { title, serverConfig });
|
|
finished.then(([config]) => onFinished(config));
|
|
};
|
|
|
|
const onHelpClick = (): void => {
|
|
const brand = SdkConfig.get().brand;
|
|
Modal.createDialog(
|
|
InfoDialog,
|
|
{
|
|
title: _t("auth|server_picker_title_default"),
|
|
description: _t("auth|server_picker_description", { brand }),
|
|
button: _t("action|dismiss"),
|
|
hasCloseButton: false,
|
|
fixedWidth: false,
|
|
},
|
|
"mx_ServerPicker_helpDialog",
|
|
);
|
|
};
|
|
|
|
const ServerPicker: React.FC<IProps> = ({ title, dialogTitle, serverConfig, onServerConfigChange, disabled }) => {
|
|
const disableCustomUrls = SdkConfig.get("disable_custom_urls");
|
|
|
|
let editBtn;
|
|
if (!disableCustomUrls && onServerConfigChange) {
|
|
const onClick = (): void => {
|
|
showPickerDialog(dialogTitle, serverConfig, (config?: ValidatedServerConfig) => {
|
|
if (config) {
|
|
onServerConfigChange(config);
|
|
}
|
|
});
|
|
};
|
|
editBtn = (
|
|
<AccessibleButton className="mx_ServerPicker_change" kind="link" onClick={onClick} disabled={disabled}>
|
|
{_t("action|edit")}
|
|
</AccessibleButton>
|
|
);
|
|
}
|
|
|
|
let serverName: React.ReactNode = serverConfig.isNameResolvable ? serverConfig.hsName : serverConfig.hsUrl;
|
|
if (serverConfig.hsNameIsDifferent) {
|
|
serverName = (
|
|
<TextWithTooltip className="mx_Login_underlinedServerName" tooltip={serverConfig.hsUrl}>
|
|
{serverConfig.hsName}
|
|
</TextWithTooltip>
|
|
);
|
|
}
|
|
|
|
let desc;
|
|
if (serverConfig.hsName === "matrix.org") {
|
|
desc = <span className="mx_ServerPicker_desc">{_t("auth|server_picker_description_matrix.org")}</span>;
|
|
}
|
|
|
|
return (
|
|
<div className="mx_ServerPicker">
|
|
<h2>{title || _t("common|homeserver")}</h2>
|
|
{!disableCustomUrls ? (
|
|
<AccessibleButton className="mx_ServerPicker_help" onClick={onHelpClick} aria-label={_t("common|help")}>
|
|
<InfoIcon />
|
|
</AccessibleButton>
|
|
) : null}
|
|
<span className="mx_ServerPicker_server" title={typeof serverName === "string" ? serverName : undefined}>
|
|
{serverName}
|
|
</span>
|
|
{editBtn}
|
|
{desc}
|
|
</div>
|
|
);
|
|
};
|
|
|
|
export default ServerPicker;
|