Skip to content

armgit / ente

Public Imported from GitHub
0

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

H

Manav Rathiea417bd46a92
diff --git a/web/apps/accounts/src/pages/_app.tsx b/web/apps/accounts/src/pages/_app.tsx
index 65ead78130..f828ecab03 100644
--- a/web/apps/accounts/src/pages/_app.tsx
+++ b/web/apps/accounts/src/pages/_app.tsx
@@ -4,8 +4,8 @@ import { LoadingOverlay } from "@/base/components/LoadingOverlay";
import { AttributedMiniDialog } from "@/base/components/MiniDialog";
import { AppNavbar } from "@/base/components/Navbar";
import { useAttributedMiniDialog } from "@/base/components/utils/dialog";
+import { useSetupI18n } from "@/base/components/utils/hooks-i18n";
import { getTheme, THEME_COLOR } from "@/base/components/utils/theme";
-import { setupI18n } from "@/base/i18n";
import { disableDiskLogs } from "@/base/log";
import { logUnhandledErrorsAndRejections } from "@/base/log-web";
import { CssBaseline } from "@mui/material";
@@ -19,13 +19,13 @@ import "@fontsource-variable/inter";
import "styles/global.css";
const App: React.FC<AppProps> = ({ Component, pageProps }) => {
- const [isI18nReady, setIsI18nReady] = useState<boolean>(false);
const [showNavbar, setShowNavbar] = useState(false);
+
+ const isI18nReady = useSetupI18n();
const { showMiniDialog, miniDialogProps } = useAttributedMiniDialog();
useEffect(() => {
disableDiskLogs();
- void setupI18n().finally(() => setIsI18nReady(true));
logUnhandledErrorsAndRejections(true);
return () => logUnhandledErrorsAndRejections(false);
}, []);
diff --git a/web/apps/auth/src/pages/_app.tsx b/web/apps/auth/src/pages/_app.tsx
index 70cc79bfcf..67b72c3b82 100644
--- a/web/apps/auth/src/pages/_app.tsx
+++ b/web/apps/auth/src/pages/_app.tsx
@@ -5,8 +5,8 @@ import { LoadingOverlay } from "@/base/components/LoadingOverlay";
import { AttributedMiniDialog } from "@/base/components/MiniDialog";
import { AppNavbar } from "@/base/components/Navbar";
import { useAttributedMiniDialog } from "@/base/components/utils/dialog";
+import { useSetupI18n } from "@/base/components/utils/hooks-i18n";
import { THEME_COLOR, getTheme } from "@/base/components/utils/theme";
-import { setupI18n } from "@/base/i18n";
import {
logStartupBanner,
logUnhandledErrorsAndRejections,
@@ -32,10 +32,10 @@ import "styles/global.css";
const App: React.FC<AppProps> = ({ Component, pageProps }) => {
const router = useRouter();
- const [isI18nReady, setIsI18nReady] = useState<boolean>(false);
const [loading, setLoading] = useState(false);
const [showNavbar, setShowNavBar] = useState(false);
+ const isI18nReady = useSetupI18n();
const { showMiniDialog, miniDialogProps } = useAttributedMiniDialog();
const [themeColor, setThemeColor] = useLocalState(
LS_KEYS.THEME,
@@ -43,7 +43,6 @@ const App: React.FC<AppProps> = ({ Component, pageProps }) => {
);
useEffect(() => {
- void setupI18n().finally(() => setIsI18nReady(true));
const user = getData(LS_KEYS.USER) as User | undefined | null;
void migrateKVToken(user);
logStartupBanner(user?.id);
diff --git a/web/apps/photos/src/pages/_app.tsx b/web/apps/photos/src/pages/_app.tsx
index c08fd8b0dc..d1908fe8db 100644
--- a/web/apps/photos/src/pages/_app.tsx
+++ b/web/apps/photos/src/pages/_app.tsx
@@ -7,8 +7,8 @@ import {
genericErrorDialogAttributes,
useAttributedMiniDialog,
} from "@/base/components/utils/dialog";
+import { useSetupI18n } from "@/base/components/utils/hooks-i18n";
import { THEME_COLOR, getTheme } from "@/base/components/utils/theme";
-import { setupI18n } from "@/base/i18n";
import log from "@/base/log";
import {
logStartupBanner,
@@ -53,7 +53,6 @@ import "styles/global.css";
export default function App({ Component, pageProps }: AppProps) {
const router = useRouter();
- const [isI18nReady, setIsI18nReady] = useState<boolean>(false);
const [loading, setLoading] = useState(false);
const [showNavbar, setShowNavBar] = useState(false);
const [watchFolderView, setWatchFolderView] = useState(false);
@@ -64,6 +63,7 @@ export default function App({ Component, pageProps }: AppProps) {
useState<NotificationAttributes>(null);
const isOffline = useIsOffline();
+ const isI18nReady = useSetupI18n();
const { showMiniDialog, miniDialogProps } = useAttributedMiniDialog();
const { loadingBarRef, showLoadingBar, hideLoadingBar } = useLoadingBar();
const [themeColor, setThemeColor] = useLocalState(
@@ -72,7 +72,6 @@ export default function App({ Component, pageProps }: AppProps) {
);
useEffect(() => {
- void setupI18n().finally(() => setIsI18nReady(true));
const user = getData(LS_KEYS.USER) as User | undefined | null;
void migrateKVToken(user);
logStartupBanner(user?.id);
diff --git a/web/packages/base/components/utils/hooks-i18n.ts b/web/packages/base/components/utils/hooks-i18n.ts
new file mode 100644
index 0000000000..1f7accce96
--- /dev/null
+++ b/web/packages/base/components/utils/hooks-i18n.ts
@@ -0,0 +1,21 @@
+import { setupI18n } from "@/base/i18n";
+import { useEffect, useState } from "react";
+
+/**
+ * A hook that initializes the localization library that we use.
+ *
+ * This is only meant to be called from the top level `_app.tsx`, as this
+ * initialization is expected to only happen once for the lifetime of the page.
+ *
+ * @returns a boolean which will be set to true when the localized strings have
+ * been loaded.
+ */
+export const useSetupI18n = () => {
+ const [isI18nReady, setIsI18nReady] = useState(false);
+
+ useEffect(() => {
+ void setupI18n().finally(() => setIsI18nReady(true));
+ }, []);
+
+ return isI18nReady;
+};