reduce accounts

This commit is contained in:
Manav Rathi 2024-05-26 20:26:57 +05:30
parent e95cba0ace
commit 71a8049a35
No known key found for this signature in database
10 changed files with 23 additions and 37 deletions

View file

@ -2,6 +2,7 @@ import { CustomHead } from "@/next/components/Head";
import { setupI18n } from "@/next/i18n";
import { logUnhandledErrorsAndRejections } from "@/next/log-web";
import type { AppName, BaseAppContextT } from "@/next/types/app";
import { ensure } from "@/utils/ensure";
import { PAGES } from "@ente/accounts/constants/pages";
import { accountLogout } from "@ente/accounts/services/logout";
import { APPS, APP_TITLES } from "@ente/shared/apps/constants";
@ -20,7 +21,7 @@ import { ThemeProvider } from "@mui/material/styles";
import { t } from "i18next";
import { AppProps } from "next/app";
import { useRouter } from "next/router";
import { createContext, useEffect, useState } from "react";
import { createContext, useContext, useEffect, useState } from "react";
import "styles/global.css";
/** The accounts app has no extra properties on top of the base context. */
@ -29,6 +30,9 @@ type AppContextT = BaseAppContextT;
/** The React {@link Context} available to all pages. */
export const AppContext = createContext<AppContextT | undefined>(undefined);
/** Utility hook to reduce amount of boilerplate in account related pages. */
export const useAppContext = () => ensure(useContext(AppContext));
export default function App({ Component, pageProps }: AppProps) {
const appName: AppName = "account";

View file

@ -1,8 +1,6 @@
import { ensure } from "@/utils/ensure";
import Page_ from "@ente/accounts/pages/credentials";
import { useContext } from "react";
import { AppContext } from "./_app";
import { useAppContext } from "./_app";
const Page = () => <Page_ appContext={ensure(useContext(AppContext))} />;
const Page = () => <Page_ appContext={useAppContext()} />;
export default Page;

View file

@ -1,8 +1,6 @@
import { ensure } from "@/utils/ensure";
import Page_ from "@ente/accounts/pages/generate";
import { useContext } from "react";
import { AppContext } from "./_app";
import { useAppContext } from "./_app";
const Page = () => <Page_ appContext={ensure(useContext(AppContext))} />;
const Page = () => <Page_ appContext={useAppContext()} />;
export default Page;

View file

@ -1,8 +1,6 @@
import { ensure } from "@/utils/ensure";
import Page_ from "@ente/accounts/pages/login";
import { useContext } from "react";
import { AppContext } from "./_app";
import { useAppContext } from "./_app";
const Page = () => <Page_ appContext={ensure(useContext(AppContext))} />;
const Page = () => <Page_ appContext={useAppContext()} />;
export default Page;

View file

@ -1,8 +1,6 @@
import { ensure } from "@/utils/ensure";
import Page_ from "@ente/accounts/pages/recover";
import { useContext } from "react";
import { AppContext } from "./_app";
import { useAppContext } from "./_app";
const Page = () => <Page_ appContext={ensure(useContext(AppContext))} />;
const Page = () => <Page_ appContext={useAppContext()} />;
export default Page;

View file

@ -1,8 +1,6 @@
import { ensure } from "@/utils/ensure";
import Page_ from "@ente/accounts/pages/signup";
import { useContext } from "react";
import { AppContext } from "./_app";
import { useAppContext } from "./_app";
const Page = () => <Page_ appContext={ensure(useContext(AppContext))} />;
const Page = () => <Page_ appContext={useAppContext()} />;
export default Page;

View file

@ -1,8 +1,6 @@
import { ensure } from "@/utils/ensure";
import Page_ from "@ente/accounts/pages/two-factor/recover";
import { useContext } from "react";
import { AppContext } from "../_app";
import { useAppContext } from "../_app";
const Page = () => <Page_ appContext={ensure(useContext(AppContext))} />;
const Page = () => <Page_ appContext={useAppContext()} />;
export default Page;

View file

@ -1,8 +1,6 @@
import { ensure } from "@/utils/ensure";
import Page_ from "@ente/accounts/pages/two-factor/setup";
import { useContext } from "react";
import { AppContext } from "../_app";
import { useAppContext } from "../_app";
const Page = () => <Page_ appContext={ensure(useContext(AppContext))} />;
const Page = () => <Page_ appContext={useAppContext()} />;
export default Page;

View file

@ -1,8 +1,6 @@
import { ensure } from "@/utils/ensure";
import Page_ from "@ente/accounts/pages/two-factor/verify";
import { useContext } from "react";
import { AppContext } from "../_app";
import { useAppContext } from "../_app";
const Page = () => <Page_ appContext={ensure(useContext(AppContext))} />;
const Page = () => <Page_ appContext={useAppContext()} />;
export default Page;

View file

@ -1,8 +1,6 @@
import { ensure } from "@/utils/ensure";
import Page_ from "@ente/accounts/pages/verify";
import { useContext } from "react";
import { AppContext } from "./_app";
import { useAppContext } from "./_app";
const Page = () => <Page_ appContext={ensure(useContext(AppContext))} />;
const Page = () => <Page_ appContext={useAppContext()} />;
export default Page;