Skip to content

Commit

Permalink
Add recovery section without breadcrumb
Browse files Browse the repository at this point in the history
  • Loading branch information
florianduros committed Dec 6, 2024
1 parent 8747e62 commit 98d86e0
Show file tree
Hide file tree
Showing 6 changed files with 134 additions and 8 deletions.
22 changes: 15 additions & 7 deletions res/css/_common.pcss
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,9 @@ legend {
.mx_Dialog
button:not(.mx_Dialog_nonDialogButton):not([class|="maplibregl"]):not(.mx_AccessibleButton):not(
.mx_UserProfileSettings button
):not(.mx_ThemeChoicePanel_CustomTheme button):not(.mx_UnpinAllDialog button):not(.mx_ShareDialog button),
):not(.mx_ThemeChoicePanel_CustomTheme button):not(.mx_UnpinAllDialog button):not(.mx_ShareDialog button):not(
.mx_EncryptionUserSettingsTab button
),
.mx_Dialog input[type="submit"],
.mx_Dialog_buttons button:not(.mx_Dialog_nonDialogButton):not(.mx_AccessibleButton),
.mx_Dialog_buttons input[type="submit"] {
Expand All @@ -616,16 +618,18 @@ legend {
.mx_Dialog
button:not(.mx_Dialog_nonDialogButton):not([class|="maplibregl"]):not(.mx_AccessibleButton):not(
.mx_UserProfileSettings button
):not(.mx_ThemeChoicePanel_CustomTheme button):not(.mx_UnpinAllDialog button):not(
.mx_ShareDialog button
):not(.mx_ThemeChoicePanel_CustomTheme button):not(.mx_UnpinAllDialog button):not(.mx_ShareDialog button):not(
.mx_EncryptionUserSettingsTab button
):last-child {
margin-right: 0px;
}

.mx_Dialog
button:not(.mx_Dialog_nonDialogButton):not([class|="maplibregl"]):not(.mx_AccessibleButton):not(
.mx_UserProfileSettings button
):not(.mx_ThemeChoicePanel_CustomTheme button):not(.mx_UnpinAllDialog button):not(.mx_ShareDialog button):focus,
):not(.mx_ThemeChoicePanel_CustomTheme button):not(.mx_UnpinAllDialog button):not(.mx_ShareDialog button):not(
.mx_EncryptionUserSettingsTab button
):focus,
.mx_Dialog input[type="submit"]:focus,
.mx_Dialog_buttons button:not(.mx_Dialog_nonDialogButton):not(.mx_AccessibleButton):focus,
.mx_Dialog_buttons input[type="submit"]:focus {
Expand All @@ -637,7 +641,9 @@ legend {
.mx_Dialog_buttons
button.mx_Dialog_primary:not(.mx_Dialog_nonDialogButton):not(.mx_AccessibleButton):not(
.mx_UserProfileSettings button
):not(.mx_ThemeChoicePanel_CustomTheme button):not(.mx_UnpinAllDialog button):not(.mx_ShareDialog button),
):not(.mx_ThemeChoicePanel_CustomTheme button):not(.mx_UnpinAllDialog button):not(.mx_ShareDialog button):not(
.mx_EncryptionUserSettingsTab button
),
.mx_Dialog_buttons input[type="submit"].mx_Dialog_primary {
color: var(--cpd-color-text-on-solid-primary);
background-color: var(--cpd-color-bg-action-primary-rest);
Expand All @@ -650,7 +656,7 @@ legend {
.mx_Dialog_buttons
button.danger:not(.mx_Dialog_nonDialogButton):not(.mx_AccessibleButton):not(.mx_UserProfileSettings button):not(
.mx_ThemeChoicePanel_CustomTheme button
):not(.mx_UnpinAllDialog button):not(.mx_ShareDialog button),
):not(.mx_UnpinAllDialog button):not(.mx_ShareDialog button):not(.mx_EncryptionUserSettingsTab button),
.mx_Dialog_buttons input[type="submit"].danger {
background-color: var(--cpd-color-bg-critical-primary);
border: solid 1px var(--cpd-color-bg-critical-primary);
Expand All @@ -666,7 +672,9 @@ legend {
.mx_Dialog
button:not(.mx_Dialog_nonDialogButton):not([class|="maplibregl"]):not(.mx_AccessibleButton):not(
.mx_UserProfileSettings button
):not(.mx_ThemeChoicePanel_CustomTheme button):not(.mx_UnpinAllDialog button):not(.mx_ShareDialog button):disabled,
):not(.mx_ThemeChoicePanel_CustomTheme button):not(.mx_UnpinAllDialog button):not(.mx_ShareDialog button):not(
.mx_EncryptionUserSettingsTab button
):disabled,
.mx_Dialog input[type="submit"]:disabled,
.mx_Dialog_buttons button:not(.mx_Dialog_nonDialogButton):not(.mx_AccessibleButton):disabled,
.mx_Dialog_buttons input[type="submit"]:disabled {
Expand Down
1 change: 1 addition & 0 deletions res/css/_components.pcss
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,7 @@
@import "./views/settings/_ThemeChoicePanel.pcss";
@import "./views/settings/_UpdateCheckButton.pcss";
@import "./views/settings/_UserProfileSettings.pcss";
@import "./views/settings/encryption/_RecoveryPanel.pcss";
@import "./views/settings/tabs/_SettingsBanner.pcss";
@import "./views/settings/tabs/_SettingsIndent.pcss";
@import "./views/settings/tabs/_SettingsSection.pcss";
Expand Down
22 changes: 22 additions & 0 deletions res/css/views/settings/encryption/_RecoveryPanel.pcss
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Copyright 2024 New Vector Ltd.
*
* SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only
* Please see LICENSE files in the repository root for full details.
*/

.mx_RecoveryPanel {
.mx_RecoveryPanel_Subheader {
display: flex;
flex-direction: column;
gap: var(--cpd-space-2x);

> span {
display: flex;
align-items: center;
gap: var(--cpd-space-2x);
font: var(--cpd-font-body-sm-medium);
color: var(--cpd-color-text-success-primary);
}
}
}
85 changes: 85 additions & 0 deletions src/components/views/settings/encryption/RecoveryPanel.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/*
* Copyright 2024 New Vector Ltd.
*
* SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only
* Please see LICENSE files in the repository root for full details.
*/

import React, { JSX, useEffect, useState } from "react";
import { Button, InlineSpinner } from "@vector-im/compound-web";
import KeyIcon from "@vector-im/compound-design-tokens/assets/web/icons/key";
import CheckCircleIcon from "@vector-im/compound-design-tokens/assets/web/icons/check-circle-solid";

import { SettingsSection } from "../shared/SettingsSection";
import { _t } from "../../../../languageHandler";
import { useMatrixClientContext } from "../../../../contexts/MatrixClientContext";
import { SettingsHeader } from "../SettingsHeader";

/**
* This component allows the user to set up or change their recovery key.
*/
export function RecoveryPanel(): JSX.Element {
const [hasRecoveryKey, setHasRecoveryKey] = useState<boolean | null>(null);
const isLoading = hasRecoveryKey === null;
const matrixClient = useMatrixClientContext();

useEffect(() => {
const getRecoveryKey = async (): Promise<void> =>
setHasRecoveryKey(Boolean(await matrixClient.getCrypto()?.getKeyBackupInfo()));
getRecoveryKey();
}, [matrixClient]);

return (
<SettingsSection
legacy={false}
heading={
<SettingsHeader
hasRecommendedTag={!isLoading && !hasRecoveryKey}
label={_t("settings|encryption|recovery_title")}
/>
}
subHeading={<Subheader hasRecoveryKey={hasRecoveryKey} />}
className="mx_RecoveryPanel"
>
{isLoading && <InlineSpinner />}
{!isLoading && (
<>
{hasRecoveryKey ? (
<Button size="sm" kind="secondary" Icon={KeyIcon}>
{_t("settings|encryption|recovery_change_recovery_key")}
</Button>
) : (
<Button size="sm" kind="primary" Icon={KeyIcon}>
{_t("settings|encryption|recovery_set_up_recovery")}
</Button>
)}
</>
)}
</SettingsSection>
);
}

/**
* The subheader for the recovery panel.
*/
interface SubheaderProps {
/**
* Whether the user has a recovery key.
* If null, the recovery key is still fetching.
*/
hasRecoveryKey: boolean | null;
}

function Subheader({ hasRecoveryKey }: SubheaderProps): JSX.Element {
if (!hasRecoveryKey) return <>{_t("settings|encryption|recovery_description")}</>;

return (
<div className="mx_RecoveryPanel_Subheader">
{_t("settings|encryption|recovery_description")}
<span>
<CheckCircleIcon width="20" height="20" />
{_t("settings|encryption|recovery_key_active")}
</span>
</div>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@
import React, { JSX } from "react";

import SettingsTab from "../SettingsTab";
import { RecoveryPanel } from "../../encryption/RecoveryPanel";

export function EncryptionUserSettingsTab(): JSX.Element {
return <SettingsTab />;
return (
<SettingsTab className="mx_EncryptionUserSettingsTab">
<RecoveryPanel />
</SettingsTab>
);
}
5 changes: 5 additions & 0 deletions src/i18n/strings/en_EN.json
Original file line number Diff line number Diff line change
Expand Up @@ -2464,6 +2464,11 @@
"enable_markdown_description": "Start messages with <code>/plain</code> to send without markdown.",
"encryption": {
"dialog_title": "<strong>Settings:</strong> Encryption",
"recovery_change_recovery_key": "Change recovery key",
"recovery_description": "Recover your cryptographic identity and message history with a recovery key if you’ve lost all your existing devices.",
"recovery_key_active": "Recovery key active",
"recovery_set_up_recovery": "Set up recovery",
"recovery_title": "Recovery",
"title": "Encryption"
},
"general": {
Expand Down

0 comments on commit 98d86e0

Please sign in to comment.