This commit is contained in:
Manav Rathi
2024-11-20 09:15:18 +05:30
parent 1ec67c6baf
commit 1ddd143b2e
19 changed files with 36 additions and 45 deletions

View File

@@ -12,7 +12,7 @@ type AppContextT = Omit<AccountsContextT, "logout">;
export const AppContext = createContext<AppContextT | undefined>(undefined);
/**
* Utility hook to get the {@link AppContextT}, throwing an exception if it is
* not defined.
* Utility hook to get the {@link AppContextT} expected to be available to all
* React components in the Accounts app's React tree.
*/
export const useAppContext = (): AppContextT => useContext(AppContext)!;

View File

@@ -16,12 +16,7 @@ export default [
"@typescript-eslint/no-unsafe-member-access": "off",
"@typescript-eslint/no-unsafe-argument": "off",
/** TODO: Disabled as we migrate, try to prune these again */
"@typescript-eslint/no-unnecessary-type-assertion": "off",
"@typescript-eslint/consistent-indexed-object-style": "off",
"@typescript-eslint/prefer-promise-reject-errors": "off",
"@typescript-eslint/no-useless-constructor": "off",
"react-hooks/exhaustive-deps": "off",
"react-refresh/only-export-components": "off",
},
},
];

View File

@@ -1,5 +1,4 @@
import { accountLogout } from "@/accounts/services/logout";
import type { AccountsContextT } from "@/accounts/types/context";
import { clientPackageName, staticAppTitle } from "@/base/app";
import { CustomHead } from "@/base/components/Head";
import { AttributedMiniDialog } from "@/base/components/MiniDialog";
@@ -28,30 +27,11 @@ import { ThemeProvider } from "@mui/material/styles";
import { t } from "i18next";
import type { AppProps } from "next/app";
import { useRouter } from "next/router";
import React, {
createContext,
useCallback,
useContext,
useEffect,
useState,
} from "react";
import React, { useCallback, useEffect, useState } from "react";
import { AppContext } from "types/context";
import "../../public/css/global.css";
/**
* Properties available via {@link AppContext} to the Auth app's React tree.
*/
type AppContextT = AccountsContextT & {
themeColor: THEME_COLOR;
setThemeColor: (themeColor: THEME_COLOR) => void;
};
/** 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 = () => useContext(AppContext)!;
const App: React.FC<AppProps> = ({ Component, pageProps }) => {
const router = useRouter();
const [isI18nReady, setIsI18nReady] = useState<boolean>(false);

View File

@@ -19,7 +19,7 @@ import { useRouter } from "next/router";
import React, { useEffect, useState } from "react";
import { generateOTPs, type Code } from "services/code";
import { getAuthCodes } from "services/remote";
import { useAppContext } from "./_app";
import { useAppContext } from "types/context";
const Page: React.FC = () => {
const { logout, showNavBar, showMiniDialog } = useAppContext();

View File

@@ -1,5 +1,5 @@
import Page_ from "@/accounts/pages/change-email";
import { useAppContext } from "./_app";
import { useAppContext } from "types/context";
const Page = () => <Page_ appContext={useAppContext()} />;

View File

@@ -1,5 +1,5 @@
import Page_ from "@/accounts/pages/change-password";
import { useAppContext } from "./_app";
import { useAppContext } from "types/context";
const Page = () => <Page_ appContext={useAppContext()} />;

View File

@@ -1,5 +1,5 @@
import Page_ from "@/accounts/pages/credentials";
import { useAppContext } from "./_app";
import { useAppContext } from "types/context";
const Page = () => <Page_ appContext={useAppContext()} />;

View File

@@ -1,5 +1,5 @@
import Page_ from "@/accounts/pages/generate";
import { useAppContext } from "./_app";
import { useAppContext } from "types/context";
const Page = () => <Page_ appContext={useAppContext()} />;

View File

@@ -1,5 +1,5 @@
import Page_ from "@/accounts/pages/login";
import { useAppContext } from "./_app";
import { useAppContext } from "types/context";
const Page = () => <Page_ appContext={useAppContext()} />;

View File

@@ -1,5 +1,5 @@
import Page_ from "@/accounts/pages/passkeys/finish";
import { useAppContext } from "../_app";
import { useAppContext } from "types/context";
const Page = () => <Page_ appContext={useAppContext()} />;

View File

@@ -1,5 +1,5 @@
import Page_ from "@/accounts/pages/two-factor/recover";
import { useAppContext } from "../_app";
import { useAppContext } from "types/context";
const Page = () => (
<Page_ appContext={useAppContext()} twoFactorType="passkey" />

View File

@@ -1,5 +1,5 @@
import Page_ from "@/accounts/pages/recover";
import { useAppContext } from "./_app";
import { useAppContext } from "types/context";
const Page = () => <Page_ appContext={useAppContext()} />;

View File

@@ -1,5 +1,5 @@
import Page_ from "@/accounts/pages/signup";
import { useAppContext } from "./_app";
import { useAppContext } from "types/context";
const Page = () => <Page_ appContext={useAppContext()} />;

View File

@@ -1,5 +1,5 @@
import Page_ from "@/accounts/pages/two-factor/recover";
import { useAppContext } from "../_app";
import { useAppContext } from "types/context";
const Page = () => <Page_ appContext={useAppContext()} twoFactorType="totp" />;

View File

@@ -1,5 +1,5 @@
import Page_ from "@/accounts/pages/two-factor/setup";
import { useAppContext } from "../_app";
import { useAppContext } from "types/context";
const Page = () => <Page_ appContext={useAppContext()} />;

View File

@@ -1,5 +1,5 @@
import Page_ from "@/accounts/pages/two-factor/verify";
import { useAppContext } from "../_app";
import { useAppContext } from "types/context";
const Page = () => <Page_ appContext={useAppContext()} />;

View File

@@ -1,5 +1,5 @@
import Page_ from "@/accounts/pages/verify";
import { useAppContext } from "./_app";
import { useAppContext } from "types/context";
const Page = () => <Page_ appContext={useAppContext()} />;

View File

@@ -0,0 +1,17 @@
import type { AccountsContextT } from "@/accounts/types/context";
import { THEME_COLOR } from "@ente/shared/themes/constants";
import { createContext, useContext } from "react";
/**
* Properties available via {@link AppContext} to the Auth app's React tree.
*/
type AppContextT = AccountsContextT & {
themeColor: THEME_COLOR;
setThemeColor: (themeColor: THEME_COLOR) => void;
};
/** 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 = () => useContext(AppContext)!;

View File

@@ -35,8 +35,7 @@ export type AppContextT = AccountsContextT & {
export const AppContext = createContext<AppContextT | undefined>(undefined);
/**
* Utility hook to get the photos {@link AppContextT}, throwing an exception if
* it is not defined.
* Utility hook to get the photos {@link AppContextT}.
*
* This context is provided at the top level _app component for the photos app,
* and thus is available to all React components in the Photos app's React tree.