Split types

This commit is contained in:
Manav Rathi 2024-05-26 21:52:29 +05:30
parent 8ebd50606a
commit 05406333e4
No known key found for this signature in database
17 changed files with 52 additions and 43 deletions

View file

@ -1,16 +1,12 @@
import { TwoFactorType } from "@ente/accounts/constants/twofactor"; import { TwoFactorType } from "@ente/accounts/constants/twofactor";
import RecoverPage from "@ente/accounts/pages/recover"; import RecoverPage from "@ente/accounts/pages/two-factor/recover";
import { APPS } from "@ente/shared/apps/constants"; import { useAppContext } from "../../_app";
import { AppContext } from "pages/_app";
import { useContext } from "react";
export default function Recover() { const Page = () => (
const appContext = useContext(AppContext); <RecoverPage
return ( appContext={useAppContext()}
<RecoverPage twoFactorType={TwoFactorType.PASSKEY}
appContext={appContext} />
appName={APPS.PHOTOS} );
twoFactorType={TwoFactorType.PASSKEY}
/> export default Page;
);
}

View file

@ -602,7 +602,7 @@ const UtilitySection: React.FC<UtilitySectionProps> = ({ closeSidebar }) => {
label={t("PREFERENCES")} label={t("PREFERENCES")}
/> />
<RecoveryKey <RecoveryKey
appContext={appContext} isMobile={appContext.isMobile}
show={recoverModalView} show={recoverModalView}
onHide={closeRecoveryKeyModal} onHide={closeRecoveryKeyModal}
somethingWentWrong={somethingWentWrong} somethingWentWrong={somethingWentWrong}

View file

@ -7,7 +7,6 @@ import {
appNameToAppNameOld, appNameToAppNameOld,
type APPS, type APPS,
} from "@ente/shared/apps/constants"; } from "@ente/shared/apps/constants";
import type { PageProps } from "@ente/shared/apps/types";
import { VerticallyCentered } from "@ente/shared/components/Container"; import { VerticallyCentered } from "@ente/shared/components/Container";
import FormPaper from "@ente/shared/components/Form/FormPaper"; import FormPaper from "@ente/shared/components/Form/FormPaper";
import FormPaperFooter from "@ente/shared/components/Form/FormPaper/Footer"; import FormPaperFooter from "@ente/shared/components/Form/FormPaper/Footer";
@ -22,6 +21,7 @@ import { useRouter } from "next/router";
import { useEffect, useState } from "react"; import { useEffect, useState } from "react";
import { Trans } from "react-i18next"; import { Trans } from "react-i18next";
import * as Yup from "yup"; import * as Yup from "yup";
import type { PageProps } from "../types/page";
const Page: React.FC<PageProps> = ({ appContext }) => { const Page: React.FC<PageProps> = ({ appContext }) => {
const { appName } = appContext; const { appName } = appContext;

View file

@ -14,7 +14,6 @@ import {
convertBufferToBase64, convertBufferToBase64,
} from "@ente/accounts/utils"; } from "@ente/accounts/utils";
import { APP_HOMES, appNameToAppNameOld } from "@ente/shared/apps/constants"; import { APP_HOMES, appNameToAppNameOld } from "@ente/shared/apps/constants";
import type { PageProps } from "@ente/shared/apps/types";
import { VerticallyCentered } from "@ente/shared/components/Container"; import { VerticallyCentered } from "@ente/shared/components/Container";
import FormPaper from "@ente/shared/components/Form/FormPaper"; import FormPaper from "@ente/shared/components/Form/FormPaper";
import FormPaperFooter from "@ente/shared/components/Form/FormPaper/Footer"; import FormPaperFooter from "@ente/shared/components/Form/FormPaper/Footer";
@ -34,6 +33,7 @@ import type { KEK, KeyAttributes, User } from "@ente/shared/user/types";
import { t } from "i18next"; import { t } from "i18next";
import { useRouter } from "next/router"; import { useRouter } from "next/router";
import { useEffect, useState } from "react"; import { useEffect, useState } from "react";
import type { PageProps } from "../types/page";
const Page: React.FC<PageProps> = ({ appContext }) => { const Page: React.FC<PageProps> = ({ appContext }) => {
const { appName } = appContext; const { appName } = appContext;

View file

@ -2,7 +2,6 @@ import { isDevBuild } from "@/next/env";
import log from "@/next/log"; import log from "@/next/log";
import { ensure } from "@/utils/ensure"; import { ensure } from "@/utils/ensure";
import { APP_HOMES, appNameToAppNameOld } from "@ente/shared/apps/constants"; import { APP_HOMES, appNameToAppNameOld } from "@ente/shared/apps/constants";
import type { PageProps } from "@ente/shared/apps/types";
import { VerticallyCentered } from "@ente/shared/components/Container"; import { VerticallyCentered } from "@ente/shared/components/Container";
import EnteSpinner from "@ente/shared/components/EnteSpinner"; import EnteSpinner from "@ente/shared/components/EnteSpinner";
import FormPaper from "@ente/shared/components/Form/FormPaper"; import FormPaper from "@ente/shared/components/Form/FormPaper";
@ -51,6 +50,7 @@ import {
generateSRPSetupAttributes, generateSRPSetupAttributes,
loginViaSRP, loginViaSRP,
} from "../services/srp"; } from "../services/srp";
import type { PageProps } from "../types/page";
import type { SRPAttributes } from "../types/srp"; import type { SRPAttributes } from "../types/srp";
const Page: React.FC<PageProps> = ({ appContext }) => { const Page: React.FC<PageProps> = ({ appContext }) => {

View file

@ -8,7 +8,6 @@ import { PAGES } from "@ente/accounts/constants/pages";
import { configureSRP } from "@ente/accounts/services/srp"; import { configureSRP } from "@ente/accounts/services/srp";
import { generateKeyAndSRPAttributes } from "@ente/accounts/utils/srp"; import { generateKeyAndSRPAttributes } from "@ente/accounts/utils/srp";
import { APP_HOMES, appNameToAppNameOld } from "@ente/shared/apps/constants"; import { APP_HOMES, appNameToAppNameOld } from "@ente/shared/apps/constants";
import type { PageProps } from "@ente/shared/apps/types";
import { VerticallyCentered } from "@ente/shared/components/Container"; import { VerticallyCentered } from "@ente/shared/components/Container";
import EnteSpinner from "@ente/shared/components/EnteSpinner"; import EnteSpinner from "@ente/shared/components/EnteSpinner";
import FormPaper from "@ente/shared/components/Form/FormPaper"; import FormPaper from "@ente/shared/components/Form/FormPaper";
@ -30,6 +29,7 @@ import type { KeyAttributes, User } from "@ente/shared/user/types";
import { t } from "i18next"; import { t } from "i18next";
import { useRouter } from "next/router"; import { useRouter } from "next/router";
import { useEffect, useState } from "react"; import { useEffect, useState } from "react";
import type { PageProps } from "../types/page";
const Page: React.FC<PageProps> = ({ appContext }) => { const Page: React.FC<PageProps> = ({ appContext }) => {
const { appName, logout } = appContext; const { appName, logout } = appContext;
@ -105,7 +105,7 @@ const Page: React.FC<PageProps> = ({ appContext }) => {
</VerticallyCentered> </VerticallyCentered>
) : recoverModalView ? ( ) : recoverModalView ? (
<RecoveryKey <RecoveryKey
appContext={appContext} isMobile={appContext.isMobile}
show={recoverModalView} show={recoverModalView}
onHide={() => { onHide={() => {
setRecoveryModalView(false); setRecoveryModalView(false);

View file

@ -1,4 +1,3 @@
import type { PageProps } from "@ente/shared/apps/types";
import { VerticallyCentered } from "@ente/shared/components/Container"; import { VerticallyCentered } from "@ente/shared/components/Container";
import EnteSpinner from "@ente/shared/components/EnteSpinner"; import EnteSpinner from "@ente/shared/components/EnteSpinner";
import FormPaper from "@ente/shared/components/Form/FormPaper"; import FormPaper from "@ente/shared/components/Form/FormPaper";
@ -7,6 +6,7 @@ import { useRouter } from "next/router";
import React, { useEffect, useState } from "react"; import React, { useEffect, useState } from "react";
import { Login } from "../components/Login"; import { Login } from "../components/Login";
import { PAGES } from "../constants/pages"; import { PAGES } from "../constants/pages";
import type { PageProps } from "../types/page";
const Page: React.FC<PageProps> = ({ appContext }) => { const Page: React.FC<PageProps> = ({ appContext }) => {
const { appName, showNavBar } = appContext; const { appName, showNavBar } = appContext;

View file

@ -4,9 +4,9 @@ import EnteSpinner from "@ente/shared/components/EnteSpinner";
import InMemoryStore, { MS_KEYS } from "@ente/shared/storage/InMemoryStore"; import InMemoryStore, { MS_KEYS } from "@ente/shared/storage/InMemoryStore";
import { LS_KEYS, getData, setData } from "@ente/shared/storage/localStorage"; import { LS_KEYS, getData, setData } from "@ente/shared/storage/localStorage";
import { useRouter } from "next/router"; import { useRouter } from "next/router";
import { useEffect } from "react"; import React, { useEffect } from "react";
const Page = () => { const Page: React.FC = () => {
const router = useRouter(); const router = useRouter();
const init = async () => { const init = async () => {

View file

@ -3,7 +3,6 @@ import { ensure } from "@/utils/ensure";
import { sendOtt } from "@ente/accounts/api/user"; import { sendOtt } from "@ente/accounts/api/user";
import { PAGES } from "@ente/accounts/constants/pages"; import { PAGES } from "@ente/accounts/constants/pages";
import { APP_HOMES, appNameToAppNameOld } from "@ente/shared/apps/constants"; import { APP_HOMES, appNameToAppNameOld } from "@ente/shared/apps/constants";
import type { PageProps } from "@ente/shared/apps/types";
import { VerticallyCentered } from "@ente/shared/components/Container"; import { VerticallyCentered } from "@ente/shared/components/Container";
import FormPaper from "@ente/shared/components/Form/FormPaper"; import FormPaper from "@ente/shared/components/Form/FormPaper";
import FormPaperFooter from "@ente/shared/components/Form/FormPaper/Footer"; import FormPaperFooter from "@ente/shared/components/Form/FormPaper/Footer";
@ -24,6 +23,7 @@ import type { KeyAttributes, User } from "@ente/shared/user/types";
import { t } from "i18next"; import { t } from "i18next";
import { useRouter } from "next/router"; import { useRouter } from "next/router";
import { useEffect, useState } from "react"; import { useEffect, useState } from "react";
import type { PageProps } from "../types/page";
const bip39 = require("bip39"); const bip39 = require("bip39");
// mobile client library only supports english. // mobile client library only supports english.

View file

@ -1,12 +1,12 @@
import { PAGES } from "@ente/accounts/constants/pages"; import { PAGES } from "@ente/accounts/constants/pages";
import { LS_KEYS, getData } from "@ente/shared//storage/localStorage"; import { LS_KEYS, getData } from "@ente/shared//storage/localStorage";
import type { PageProps } from "@ente/shared/apps/types";
import { VerticallyCentered } from "@ente/shared/components/Container"; import { VerticallyCentered } from "@ente/shared/components/Container";
import EnteSpinner from "@ente/shared/components/EnteSpinner"; import EnteSpinner from "@ente/shared/components/EnteSpinner";
import FormPaper from "@ente/shared/components/Form/FormPaper"; import FormPaper from "@ente/shared/components/Form/FormPaper";
import { useRouter } from "next/router"; import { useRouter } from "next/router";
import React, { useEffect, useState } from "react"; import React, { useEffect, useState } from "react";
import { SignUp } from "../components/SignUp"; import { SignUp } from "../components/SignUp";
import type { PageProps } from "../types/page";
const Page: React.FC<PageProps> = ({ appContext }) => { const Page: React.FC<PageProps> = ({ appContext }) => {
const { appName } = appContext; const { appName } = appContext;

View file

@ -1,9 +1,10 @@
import log from "@/next/log"; import log from "@/next/log";
import type { BaseAppContextT } from "@/next/types/app";
import { ensure } from "@/utils/ensure"; import { ensure } from "@/utils/ensure";
import { recoverTwoFactor, removeTwoFactor } from "@ente/accounts/api/user"; import { recoverTwoFactor, removeTwoFactor } from "@ente/accounts/api/user";
import { PAGES } from "@ente/accounts/constants/pages"; import { PAGES } from "@ente/accounts/constants/pages";
import { TwoFactorType } from "@ente/accounts/constants/twofactor"; import { TwoFactorType } from "@ente/accounts/constants/twofactor";
import type { PageProps } from "@ente/shared/apps/types"; import { APPS } from "@ente/shared/apps/constants";
import { VerticallyCentered } from "@ente/shared/components/Container"; import { VerticallyCentered } from "@ente/shared/components/Container";
import type { DialogBoxAttributesV2 } from "@ente/shared/components/DialogBoxV2/types"; import type { DialogBoxAttributesV2 } from "@ente/shared/components/DialogBoxV2/types";
import FormPaper from "@ente/shared/components/Form/FormPaper"; import FormPaper from "@ente/shared/components/Form/FormPaper";
@ -29,7 +30,13 @@ const bip39 = require("bip39");
// mobile client library only supports english. // mobile client library only supports english.
bip39.setDefaultWordlist("english"); bip39.setDefaultWordlist("english");
const Page: React.FC<PageProps> = ({ export interface RecoverPageProps {
appContext: BaseAppContextT;
appName?: APPS;
twoFactorType?: TwoFactorType;
}
const Page: React.FC<RecoverPageProps> = ({
appContext, appContext,
twoFactorType = TwoFactorType.TOTP, twoFactorType = TwoFactorType.TOTP,
}) => { }) => {

View file

@ -7,7 +7,6 @@ import VerifyTwoFactor, {
import { TwoFactorSetup } from "@ente/accounts/components/two-factor/setup"; import { TwoFactorSetup } from "@ente/accounts/components/two-factor/setup";
import type { TwoFactorSecret } from "@ente/accounts/types/user"; import type { TwoFactorSecret } from "@ente/accounts/types/user";
import { APP_HOMES, appNameToAppNameOld } from "@ente/shared/apps/constants"; import { APP_HOMES, appNameToAppNameOld } from "@ente/shared/apps/constants";
import type { PageProps } from "@ente/shared/apps/types";
import { VerticallyCentered } from "@ente/shared/components/Container"; import { VerticallyCentered } from "@ente/shared/components/Container";
import LinkButton from "@ente/shared/components/LinkButton"; import LinkButton from "@ente/shared/components/LinkButton";
import { encryptWithRecoveryKey } from "@ente/shared/crypto/helpers"; import { encryptWithRecoveryKey } from "@ente/shared/crypto/helpers";
@ -17,6 +16,7 @@ import Card from "@mui/material/Card";
import { t } from "i18next"; import { t } from "i18next";
import { useRouter } from "next/router"; import { useRouter } from "next/router";
import { useEffect, useState } from "react"; import { useEffect, useState } from "react";
import type { PageProps } from "../../types/page";
export enum SetupMode { export enum SetupMode {
QR_CODE, QR_CODE,

View file

@ -4,7 +4,6 @@ import VerifyTwoFactor, {
type VerifyTwoFactorCallback, type VerifyTwoFactorCallback,
} from "@ente/accounts/components/two-factor/VerifyForm"; } from "@ente/accounts/components/two-factor/VerifyForm";
import { PAGES } from "@ente/accounts/constants/pages"; import { PAGES } from "@ente/accounts/constants/pages";
import type { PageProps } from "@ente/shared/apps/types";
import { VerticallyCentered } from "@ente/shared/components/Container"; import { VerticallyCentered } from "@ente/shared/components/Container";
import FormPaper from "@ente/shared/components/Form/FormPaper"; import FormPaper from "@ente/shared/components/Form/FormPaper";
import FormPaperFooter from "@ente/shared/components/Form/FormPaper/Footer"; import FormPaperFooter from "@ente/shared/components/Form/FormPaper/Footer";
@ -18,6 +17,7 @@ import { HttpStatusCode } from "axios";
import { t } from "i18next"; import { t } from "i18next";
import { useRouter } from "next/router"; import { useRouter } from "next/router";
import { useEffect, useState } from "react"; import { useEffect, useState } from "react";
import type { PageProps } from "../../types/page";
const Page: React.FC<PageProps> = ({ appContext }) => { const Page: React.FC<PageProps> = ({ appContext }) => {
const { logout } = appContext; const { logout } = appContext;

View file

@ -1,7 +1,6 @@
import { ensure } from "@/utils/ensure"; import { ensure } from "@/utils/ensure";
import type { UserVerificationResponse } from "@ente/accounts/types/user"; import type { UserVerificationResponse } from "@ente/accounts/types/user";
import { appNameToAppNameOld } from "@ente/shared/apps/constants"; import { appNameToAppNameOld } from "@ente/shared/apps/constants";
import type { PageProps } from "@ente/shared/apps/types";
import { VerticallyCentered } from "@ente/shared/components/Container"; import { VerticallyCentered } from "@ente/shared/components/Container";
import EnteSpinner from "@ente/shared/components/EnteSpinner"; import EnteSpinner from "@ente/shared/components/EnteSpinner";
import FormPaper from "@ente/shared/components/Form/FormPaper"; import FormPaper from "@ente/shared/components/Form/FormPaper";
@ -31,6 +30,7 @@ import { Trans } from "react-i18next";
import { putAttributes, sendOtt, verifyOtt } from "../api/user"; import { putAttributes, sendOtt, verifyOtt } from "../api/user";
import { PAGES } from "../constants/pages"; import { PAGES } from "../constants/pages";
import { configureSRP } from "../services/srp"; import { configureSRP } from "../services/srp";
import type { PageProps } from "../types/page";
import type { SRPSetupAttributes } from "../types/srp"; import type { SRPSetupAttributes } from "../types/srp";
const Page: React.FC<PageProps> = ({ appContext }) => { const Page: React.FC<PageProps> = ({ appContext }) => {

View file

@ -0,0 +1,16 @@
import type { BaseAppContextT } from "@/next/types/app";
/**
* The default type for pages exposed by this package.
*
* Some specific pages might extend this further (e.g. the two-factor/recover).
*/
export interface PageProps {
/**
* The common denominator AppContext.
*
* Within this package we do not have access to the context object declared
* with the app's code, so we need to take the context as a parameter.
*/
appContext: BaseAppContextT;
}

View file

@ -1,9 +0,0 @@
import type { BaseAppContextT } from "@/next/types/app";
import { TwoFactorType } from "@ente/accounts/constants/twofactor";
import { APPS } from "./constants";
export interface PageProps {
appContext: BaseAppContextT;
appName?: APPS;
twoFactorType?: TwoFactorType;
}

View file

@ -1,5 +1,4 @@
import { ensure } from "@/utils/ensure"; import { ensure } from "@/utils/ensure";
import type { PageProps } from "@ente/shared/apps/types";
import CodeBlock from "@ente/shared/components/CodeBlock"; import CodeBlock from "@ente/shared/components/CodeBlock";
import DialogTitleWithCloseButton from "@ente/shared/components/DialogBox/TitleWithCloseButton"; import DialogTitleWithCloseButton from "@ente/shared/components/DialogBox/TitleWithCloseButton";
import { getRecoveryKey } from "@ente/shared/crypto/helpers"; import { getRecoveryKey } from "@ente/shared/crypto/helpers";
@ -22,13 +21,13 @@ bip39.setDefaultWordlist("english");
const RECOVERY_KEY_FILE_NAME = "ente-recovery-key.txt"; const RECOVERY_KEY_FILE_NAME = "ente-recovery-key.txt";
interface Props { interface Props {
appContext: PageProps["appContext"]; isMobile: boolean;
show: boolean; show: boolean;
onHide: () => void; onHide: () => void;
somethingWentWrong: any; somethingWentWrong: any;
} }
function RecoveryKey({ somethingWentWrong, appContext, ...props }: Props) { function RecoveryKey({ somethingWentWrong, isMobile, ...props }: Props) {
const [recoveryKey, setRecoveryKey] = useState<string | null>(null); const [recoveryKey, setRecoveryKey] = useState<string | null>(null);
useEffect(() => { useEffect(() => {
@ -54,7 +53,7 @@ function RecoveryKey({ somethingWentWrong, appContext, ...props }: Props) {
return ( return (
<Dialog <Dialog
fullScreen={appContext.isMobile} fullScreen={isMobile}
open={props.show} open={props.show}
onClose={props.onHide} onClose={props.onHide}
maxWidth="xs" maxWidth="xs"