diff --git a/web/apps/accounts/src/pages/_app.tsx b/web/apps/accounts/src/pages/_app.tsx index 8cf45b741..6fc0936ea 100644 --- a/web/apps/accounts/src/pages/_app.tsx +++ b/web/apps/accounts/src/pages/_app.tsx @@ -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(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"; diff --git a/web/apps/accounts/src/pages/credentials.tsx b/web/apps/accounts/src/pages/credentials.tsx index 7d21b33ac..070aace4a 100644 --- a/web/apps/accounts/src/pages/credentials.tsx +++ b/web/apps/accounts/src/pages/credentials.tsx @@ -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 = () => ; +const Page = () => ; export default Page; diff --git a/web/apps/accounts/src/pages/generate.tsx b/web/apps/accounts/src/pages/generate.tsx index 718172d49..c6804255a 100644 --- a/web/apps/accounts/src/pages/generate.tsx +++ b/web/apps/accounts/src/pages/generate.tsx @@ -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 = () => ; +const Page = () => ; export default Page; diff --git a/web/apps/accounts/src/pages/login.tsx b/web/apps/accounts/src/pages/login.tsx index b40b9f914..1a7de0497 100644 --- a/web/apps/accounts/src/pages/login.tsx +++ b/web/apps/accounts/src/pages/login.tsx @@ -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 = () => ; +const Page = () => ; export default Page; diff --git a/web/apps/accounts/src/pages/recover.tsx b/web/apps/accounts/src/pages/recover.tsx index cc6d8da82..d825729e5 100644 --- a/web/apps/accounts/src/pages/recover.tsx +++ b/web/apps/accounts/src/pages/recover.tsx @@ -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 = () => ; +const Page = () => ; export default Page; diff --git a/web/apps/accounts/src/pages/signup.tsx b/web/apps/accounts/src/pages/signup.tsx index 8cc5202a8..403d3e735 100644 --- a/web/apps/accounts/src/pages/signup.tsx +++ b/web/apps/accounts/src/pages/signup.tsx @@ -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 = () => ; +const Page = () => ; export default Page; diff --git a/web/apps/accounts/src/pages/two-factor/recover.tsx b/web/apps/accounts/src/pages/two-factor/recover.tsx index aa9c6faf9..d3f40be49 100644 --- a/web/apps/accounts/src/pages/two-factor/recover.tsx +++ b/web/apps/accounts/src/pages/two-factor/recover.tsx @@ -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 = () => ; +const Page = () => ; export default Page; diff --git a/web/apps/accounts/src/pages/two-factor/setup.tsx b/web/apps/accounts/src/pages/two-factor/setup.tsx index 35a24149f..12716e2df 100644 --- a/web/apps/accounts/src/pages/two-factor/setup.tsx +++ b/web/apps/accounts/src/pages/two-factor/setup.tsx @@ -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 = () => ; +const Page = () => ; export default Page; diff --git a/web/apps/accounts/src/pages/two-factor/verify.tsx b/web/apps/accounts/src/pages/two-factor/verify.tsx index 3f4ed7e39..7c682b1b9 100644 --- a/web/apps/accounts/src/pages/two-factor/verify.tsx +++ b/web/apps/accounts/src/pages/two-factor/verify.tsx @@ -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 = () => ; +const Page = () => ; export default Page; diff --git a/web/apps/accounts/src/pages/verify.tsx b/web/apps/accounts/src/pages/verify.tsx index 5fb2ed10d..bb2dc8778 100644 --- a/web/apps/accounts/src/pages/verify.tsx +++ b/web/apps/accounts/src/pages/verify.tsx @@ -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 = () => ; +const Page = () => ; export default Page;