Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Rework

Manav Rathidea20345da60
diff --git a/web/packages/shared/components/CodeBlock.tsx b/web/packages/accounts/components/CodeBlock.tsx
similarity index 65%
rename from web/packages/shared/components/CodeBlock.tsx
rename to web/packages/accounts/components/CodeBlock.tsx
index 7f27ffc968..c22a074c5b 100644
--- a/web/packages/shared/components/CodeBlock.tsx
+++ b/web/packages/accounts/components/CodeBlock.tsx
@@ -1,14 +1,23 @@
import { ActivityIndicator } from "@/base/components/mui/ActivityIndicator";
import { CenteredFlex } from "@ente/shared/components/Container";
-import { type BoxProps, styled } from "@mui/material";
+import CopyButton from "@ente/shared/components/CopyButton";
+import { styled } from "@mui/material";
import React from "react";
-import CopyButton from "./CopyButton";
-type Iprops = React.PropsWithChildren<{
- code: string | null | undefined;
-}>;
+interface CodeBlockProps {
+ /**
+ * The code (an arbitrary string) to show.
+ *
+ * If not present, then an activity indicator will be shown.
+ */
+ code: string | undefined;
+}
-export default function CodeBlock({ code, ...props }: BoxProps<"div", Iprops>) {
+/**
+ * A component that shows a "code" (e.g. the user's recovery key, or a 2FA setup
+ * code), alongwith a button to copy it.
+ */
+export const CodeBlock: React.FC<CodeBlockProps> = ({ code }) => {
if (!code) {
return (
<Wrapper>
@@ -18,16 +27,14 @@ export default function CodeBlock({ code, ...props }: BoxProps<"div", Iprops>) {
}
return (
- <Wrapper {...props}>
- <CodeWrapper>
- <FreeFlowText>{code}</FreeFlowText>
- </CodeWrapper>
+ <Wrapper>
+ <CodeWrapper>{code}</CodeWrapper>
<CopyButtonWrapper>
<CopyButton code={code} />
</CopyButtonWrapper>
</Wrapper>
);
-}
+};
const Wrapper = styled(CenteredFlex)(
({ theme }) => `
@@ -42,14 +49,11 @@ const CodeWrapper = styled("div")(
({ theme }) => `
padding: 16px 36px 16px 16px;
border-radius: ${theme.shape.borderRadius}px;
-`,
-);
-
-const FreeFlowText = styled("div")`
word-break: break-word;
min-width: 30%;
text-align: left;
-`;
+`,
+);
const CopyButtonWrapper = styled("div")(
({ theme }) => `
diff --git a/web/packages/accounts/components/RecoveryKey.tsx b/web/packages/accounts/components/RecoveryKey.tsx
index 83c867657d..67305cb19f 100644
--- a/web/packages/accounts/components/RecoveryKey.tsx
+++ b/web/packages/accounts/components/RecoveryKey.tsx
@@ -7,7 +7,6 @@ import type { ModalVisibilityProps } from "@/base/components/utils/modal";
import log from "@/base/log";
import { downloadString } from "@/base/utils/web";
import { DialogCloseIconButton } from "@/new/photos/components/mui/Dialog";
-import CodeBlock from "@ente/shared/components/CodeBlock";
import { getRecoveryKey } from "@ente/shared/crypto/helpers";
import {
Dialog,
@@ -20,6 +19,7 @@ import {
import * as bip39 from "bip39";
import { t } from "i18next";
import { useCallback, useEffect, useState } from "react";
+import { CodeBlock } from "./CodeBlock";
// mobile client library only supports english.
bip39.setDefaultWordlist("english");
diff --git a/web/packages/accounts/components/two-factor/TwoFactorSetup.tsx b/web/packages/accounts/components/two-factor/TwoFactorSetup.tsx
index 89005fff45..1a64d70e9e 100644
--- a/web/packages/accounts/components/two-factor/TwoFactorSetup.tsx
+++ b/web/packages/accounts/components/two-factor/TwoFactorSetup.tsx
@@ -1,8 +1,8 @@
+import { CodeBlock } from "@/accounts/components/CodeBlock";
import { ActivityIndicator } from "@/base/components/mui/ActivityIndicator";
-import CodeBlock from "@ente/shared/components/CodeBlock";
import { VerticallyCentered } from "@ente/shared/components/Container";
import LinkButton from "@ente/shared/components/LinkButton";
-import { styled, Typography } from "@mui/material";
+import { Stack, styled, Typography } from "@mui/material";
import { t } from "i18next";
import { useState } from "react";
import { type SetupMode } from "../../pages/two-factor/setup";
@@ -45,15 +45,15 @@ function SetupManualMode({
changeToQRMode,
}: SetupManualModeProps) {
return (
- <>
+ <Stack sx={{ gap: 3 }}>
<Typography sx={{ color: "text.muted" }}>
{t("two_factor_manual_entry_message")}
</Typography>
- <CodeBlock code={twoFactorSecret?.secretCode ?? ""} my={2} />
+ <CodeBlock code={twoFactorSecret?.secretCode ?? ""} />
<LinkButton onClick={changeToQRMode}>
{t("scan_qr_title")}
</LinkButton>
- </>
+ </Stack>
);
}