-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add recovery section without breadcrumb
- Loading branch information
1 parent
5df5dc2
commit b3dc812
Showing
6 changed files
with
134 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
85
src/components/views/settings/encryption/RecoveryPanel.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.tsx"; | ||
import { _t } from "../../../../languageHandler.tsx"; | ||
import { useMatrixClientContext } from "../../../../contexts/MatrixClientContext.tsx"; | ||
import { SettingsHeader } from "../SettingsHeader.tsx"; | ||
|
||
/** | ||
* 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> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters