Skip to content

armgit / ente

Public Imported from GitHub
0

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

Remove old state

Manav Rathi882d66ee52f8
diff --git a/web/apps/accounts/src/pages/_app.tsx b/web/apps/accounts/src/pages/_app.tsx
index 2683bc9cb9..cf7de8eee5 100644
--- a/web/apps/accounts/src/pages/_app.tsx
+++ b/web/apps/accounts/src/pages/_app.tsx
@@ -4,7 +4,7 @@ import { LoadingOverlay } from "@/base/components/loaders";
import { AttributedMiniDialog } from "@/base/components/MiniDialog";
import { useAttributedMiniDialog } from "@/base/components/utils/dialog";
import { useSetupI18n, useSetupLogs } from "@/base/components/utils/hooks-app";
-import { getTheme, THEME_COLOR } from "@/base/components/utils/theme";
+import { getTheme } from "@/base/components/utils/theme";
import "@fontsource-variable/inter";
import { CssBaseline } from "@mui/material";
import { ThemeProvider } from "@mui/material/styles";
@@ -27,7 +27,7 @@ const App: React.FC<AppProps> = ({ Component, pageProps }) => {
<>
<CustomHead {...{ title }} />
- <ThemeProvider theme={getTheme(THEME_COLOR.DARK, "photos")}>
+ <ThemeProvider theme={getTheme("photos")}>
<CssBaseline enableColorScheme />
<AttributedMiniDialog {...miniDialogProps} />
diff --git a/web/apps/auth/src/pages/_app.tsx b/web/apps/auth/src/pages/_app.tsx
index e1094d83d7..eb683c2675 100644
--- a/web/apps/auth/src/pages/_app.tsx
+++ b/web/apps/auth/src/pages/_app.tsx
@@ -5,9 +5,8 @@ import { LoadingOverlay } from "@/base/components/loaders";
import { AttributedMiniDialog } from "@/base/components/MiniDialog";
import { useAttributedMiniDialog } from "@/base/components/utils/dialog";
import { useSetupI18n, useSetupLogs } from "@/base/components/utils/hooks-app";
-import { THEME_COLOR, getTheme } from "@/base/components/utils/theme";
+import { getTheme } from "@/base/components/utils/theme";
import { logStartupBanner } from "@/base/log-web";
-import { useLocalState } from "@ente/shared/hooks/useLocalState";
import HTTPService from "@ente/shared/network/HTTPService";
import {
LS_KEYS,
@@ -32,10 +31,6 @@ const App: React.FC<AppProps> = ({ Component, pageProps }) => {
const isI18nReady = useSetupI18n();
const { showMiniDialog, miniDialogProps } = useAttributedMiniDialog();
- const [themeColor, setThemeColor] = useLocalState(
- LS_KEYS.THEME,
- THEME_COLOR.DARK,
- );
useEffect(() => {
const user = getData(LS_KEYS.USER) as User | undefined | null;
@@ -65,10 +60,8 @@ const App: React.FC<AppProps> = ({ Component, pageProps }) => {
() => ({
logout,
showMiniDialog,
- themeColor,
- setThemeColor,
}),
- [logout, showMiniDialog, themeColor, setThemeColor],
+ [logout, showMiniDialog],
);
const title = isI18nReady ? t("title_auth") : staticAppTitle;
@@ -77,7 +70,7 @@ const App: React.FC<AppProps> = ({ Component, pageProps }) => {
<>
<CustomHead {...{ title }} />
- <ThemeProvider theme={getTheme(themeColor, "auth")}>
+ <ThemeProvider theme={getTheme("auth")}>
<CssBaseline enableColorScheme />
<AttributedMiniDialog {...miniDialogProps} />
diff --git a/web/apps/auth/src/types/context.ts b/web/apps/auth/src/types/context.ts
index 7e58b45465..e4cb892adf 100644
--- a/web/apps/auth/src/types/context.ts
+++ b/web/apps/auth/src/types/context.ts
@@ -1,14 +1,10 @@
import type { AccountsContextT } from "@/accounts/types/context";
-import { THEME_COLOR } from "@/base/components/utils/theme";
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;
-};
+type AppContextT = AccountsContextT;
/** The React {@link Context} available to all pages. */
export const AppContext = createContext<AppContextT | undefined>(undefined);
diff --git a/web/apps/cast/src/pages/_app.tsx b/web/apps/cast/src/pages/_app.tsx
index a3905828e2..b6e866de8d 100644
--- a/web/apps/cast/src/pages/_app.tsx
+++ b/web/apps/cast/src/pages/_app.tsx
@@ -1,7 +1,7 @@
import { staticAppTitle } from "@/base/app";
import { CustomHead } from "@/base/components/Head";
import { useSetupLogs } from "@/base/components/utils/hooks-app";
-import { getTheme, THEME_COLOR } from "@/base/components/utils/theme";
+import { getTheme } from "@/base/components/utils/theme";
import "@fontsource-variable/inter";
import { CssBaseline, ThemeProvider } from "@mui/material";
import type { AppProps } from "next/app";
@@ -14,7 +14,7 @@ const App: React.FC<AppProps> = ({ Component, pageProps }) => {
<>
<CustomHead title={staticAppTitle} />
- <ThemeProvider theme={getTheme(THEME_COLOR.DARK, "photos")}>
+ <ThemeProvider theme={getTheme("photos")}>
<CssBaseline enableColorScheme />
<Component {...pageProps} />
</ThemeProvider>
diff --git a/web/apps/photos/src/components/Sidebar/Preferences.tsx b/web/apps/photos/src/components/Sidebar/Preferences.tsx
index bae38530ba..69dddb406c 100644
--- a/web/apps/photos/src/components/Sidebar/Preferences.tsx
+++ b/web/apps/photos/src/components/Sidebar/Preferences.tsx
@@ -13,6 +13,7 @@ import {
type SupportedLocale,
} from "@/base/i18n";
import { MLSettings } from "@/new/photos/components/sidebar/MLSettings";
+import { isInternalUser } from "@/new/photos/services/settings";
import {
confirmDisableMapsDialogAttributes,
confirmEnableMapsDialogAttributes,
@@ -65,7 +66,7 @@ export const Preferences: React.FC<NestedSidebarDrawerVisibilityProps> = ({
/>
<Stack sx={{ px: "16px", py: "8px", gap: "24px" }}>
<LanguageSelector />
- <ThemeSelector />
+ {isInternalUser() && <ThemeSelector />}
<Divider sx={{ my: "2px", opacity: 0.1 }} />
{isMLSupported && (
<MenuItemGroup>
@@ -172,6 +173,7 @@ const ThemeSelector = () => {
// During SSR, mode is always undefined.
if (!mode) return null;
+ // TODO: Use translations, also remove unused t("CHOSE_THEME")
return (
<DropdownInput
options={[
@@ -179,7 +181,7 @@ const ThemeSelector = () => {
{ label: pt("Light"), value: "light" },
{ label: pt("Dark"), value: "dark" },
]}
- label={pt("Theme")} /* TODO: remove Choose theem */
+ label={pt("Theme")}
labelSxProps={{ color: "text.muted" }}
selected={mode}
setSelected={setMode}
diff --git a/web/apps/photos/src/components/Sidebar/index.tsx b/web/apps/photos/src/components/Sidebar/index.tsx
index 444e3dfc84..7d4205614f 100644
--- a/web/apps/photos/src/components/Sidebar/index.tsx
+++ b/web/apps/photos/src/components/Sidebar/index.tsx
@@ -7,7 +7,6 @@ import { ActivityIndicator } from "@/base/components/mui/ActivityIndicator";
import { SidebarDrawer } from "@/base/components/mui/SidebarDrawer";
import { useIsSmallWidth } from "@/base/components/utils/hooks";
import { useModalVisibility } from "@/base/components/utils/modal";
-import { THEME_COLOR } from "@/base/components/utils/theme";
import log from "@/base/log";
import { savedLogs } from "@/base/log-web";
import { customAPIHost } from "@/base/origins";
@@ -51,9 +50,7 @@ import { PHOTOS_PAGES as PAGES } from "@ente/shared/constants/pages";
import ArchiveOutlinedIcon from "@mui/icons-material/ArchiveOutlined";
import CategoryIcon from "@mui/icons-material/Category";
import CloseIcon from "@mui/icons-material/Close";
-import DarkModeIcon from "@mui/icons-material/DarkMode";
import DeleteOutlineIcon from "@mui/icons-material/DeleteOutline";
-import LightModeIcon from "@mui/icons-material/LightMode";
import LockOutlinedIcon from "@mui/icons-material/LockOutlined";
import VisibilityOffIcon from "@mui/icons-material/VisibilityOff";
import {
@@ -66,8 +63,6 @@ import {
Skeleton,
Stack,
styled,
- ToggleButton,
- ToggleButtonGroup,
} from "@mui/material";
import Typography from "@mui/material/Typography";
import DeleteAccountModal from "components/DeleteAccountModal";
@@ -480,13 +475,8 @@ interface UtilitySectionProps {
const UtilitySection: React.FC<UtilitySectionProps> = ({ closeSidebar }) => {
const router = useRouter();
- const {
- watchFolderView,
- setWatchFolderView,
- themeColor,
- setThemeColor,
- showMiniDialog,
- } = useAppContext();
+ const { watchFolderView, setWatchFolderView, showMiniDialog } =
+ useAppContext();
const { show: showRecoveryKey, props: recoveryKeyVisibilityProps } =
useModalVisibility();
@@ -512,13 +502,6 @@ const UtilitySection: React.FC<UtilitySectionProps> = ({ closeSidebar }) => {
const handleDeduplicate = () => router.push("/duplicates");
- const toggleTheme = () =>
- setThemeColor(
- themeColor === THEME_COLOR.DARK
- ? THEME_COLOR.LIGHT
- : THEME_COLOR.DARK,
- );
-
return (
<>
{isDesktop && (
@@ -533,19 +516,6 @@ const UtilitySection: React.FC<UtilitySectionProps> = ({ closeSidebar }) => {
onClick={showRecoveryKey}
label={t("recovery_key")}
/>
- {isInternalUser() && (
- <EnteMenuItem
- onClick={toggleTheme}
- variant="secondary"
- label={t("CHOSE_THEME")}
- endIcon={
- <ThemeSwitcher
- themeColor={themeColor}
- setThemeColor={setThemeColor}
- />
- }
- />
- )}
<EnteMenuItem
variant="secondary"
onClick={showTwoFactor}
@@ -556,7 +526,6 @@ const UtilitySection: React.FC<UtilitySectionProps> = ({ closeSidebar }) => {
onClick={redirectToAccountsPage}
label={t("passkeys")}
/>
-
<EnteMenuItem
variant="secondary"
onClick={redirectToChangePasswordPage}
@@ -600,38 +569,6 @@ const UtilitySection: React.FC<UtilitySectionProps> = ({ closeSidebar }) => {
);
};
-interface ThemeSwitcherProps {
- themeColor: THEME_COLOR;
- setThemeColor: (themeColor: THEME_COLOR) => void;
-}
-
-const ThemeSwitcher: React.FC<ThemeSwitcherProps> = ({
- themeColor,
- setThemeColor,
-}) => {
- const handleChange = (event, themeColor: THEME_COLOR) => {
- if (themeColor !== null) {
- setThemeColor(themeColor);
- }
- };
-
- return (
- <ToggleButtonGroup
- size="small"
- value={themeColor}
- exclusive
- onChange={handleChange}
- >
- <ToggleButton value={THEME_COLOR.LIGHT}>
- <LightModeIcon />
- </ToggleButton>
- <ToggleButton value={THEME_COLOR.DARK}>
- <DarkModeIcon />
- </ToggleButton>
- </ToggleButtonGroup>
- );
-};
-
const HelpSection: React.FC = () => {
const { showMiniDialog } = useContext(AppContext);
const { openExportModal } = useContext(GalleryContext);
diff --git a/web/apps/photos/src/pages/_app.tsx b/web/apps/photos/src/pages/_app.tsx
index 238cf02dcc..f61b1fadd0 100644
--- a/web/apps/photos/src/pages/_app.tsx
+++ b/web/apps/photos/src/pages/_app.tsx
@@ -7,7 +7,7 @@ import {
useAttributedMiniDialog,
} from "@/base/components/utils/dialog";
import { useSetupI18n, useSetupLogs } from "@/base/components/utils/hooks-app";
-import { THEME_COLOR, getTheme } from "@/base/components/utils/theme";
+import { getTheme } from "@/base/components/utils/theme";
import log from "@/base/log";
import { logStartupBanner } from "@/base/log-web";
import { AppUpdate } from "@/base/types/ipc";
@@ -22,7 +22,6 @@ import { runMigrations } from "@/new/photos/services/migration";
import { initML, isMLSupported } from "@/new/photos/services/ml";
import { getFamilyPortalRedirectURL } from "@/new/photos/services/user-details";
import { AppContext } from "@/new/photos/types/context";
-import { useLocalState } from "@ente/shared/hooks/useLocalState";
import HTTPService from "@ente/shared/network/HTTPService";
import {
LS_KEYS,
@@ -54,10 +53,6 @@ const App: React.FC<AppProps> = ({ Component, pageProps }) => {
const { showMiniDialog, miniDialogProps } = useAttributedMiniDialog();
const { showNotification, notificationProps } = useNotification();
const { loadingBarRef, showLoadingBar, hideLoadingBar } = useLoadingBar();
- const [themeColor, setThemeColor] = useLocalState(
- LS_KEYS.THEME,
- THEME_COLOR.DARK,
- );
const [loading, setLoading] = useState(false);
const [watchFolderView, setWatchFolderView] = useState(false);
@@ -164,8 +159,6 @@ const App: React.FC<AppProps> = ({ Component, pageProps }) => {
hideLoadingBar,
watchFolderView,
setWatchFolderView,
- themeColor,
- setThemeColor,
showMiniDialog,
showNotification,
onGenericError,
@@ -175,7 +168,6 @@ const App: React.FC<AppProps> = ({ Component, pageProps }) => {
showLoadingBar,
hideLoadingBar,
watchFolderView,
- themeColor,
showMiniDialog,
showNotification,
onGenericError,
@@ -189,7 +181,7 @@ const App: React.FC<AppProps> = ({ Component, pageProps }) => {
<>
<CustomHead {...{ title }} />
- <ThemeProvider theme={getTheme(themeColor, "photos")}>
+ <ThemeProvider theme={getTheme("photos")}>
<CssBaseline enableColorScheme />
<LoadingBar color="#51cd7c" ref={loadingBarRef} />
diff --git a/web/packages/base/components/utils/theme.ts b/web/packages/base/components/utils/theme.ts
index 76ff4c108f..53234ebfaa 100644
--- a/web/packages/base/components/utils/theme.ts
+++ b/web/packages/base/components/utils/theme.ts
@@ -12,17 +12,14 @@ import { createTheme } from "@mui/material";
import type { Components } from "@mui/material/styles/components";
import type { TypographyOptions } from "@mui/material/styles/createTypography";
-export enum THEME_COLOR {
+enum THEME_COLOR {
LIGHT = "light",
DARK = "dark",
}
-export const getTheme = (
- themeColor: THEME_COLOR,
- colorAccentType: ColorAccentType,
-) => {
- const colors = getColors(themeColor, colorAccentType);
- const palette = getPallette(themeColor, colors);
+export const getTheme = (colorAccentType: ColorAccentType) => {
+ const colors = getColors(THEME_COLOR.DARK, colorAccentType);
+ const palette = getPallette(THEME_COLOR.DARK, colors);
const components = getComponents(colors, palette, typography);
return createTheme({
cssVariables: true,
diff --git a/web/packages/new/photos/services/migration.ts b/web/packages/new/photos/services/migration.ts
index 6598ee67cb..0d319e9688 100644
--- a/web/packages/new/photos/services/migration.ts
+++ b/web/packages/new/photos/services/migration.ts
@@ -110,3 +110,12 @@ const m4 = () => {
localStorage.removeItem("subscription");
localStorage.removeItem("familyData");
};
+
+// Future cleanup. Prunable so far.
+/*
+const m5 = () => {
+ // MUI now persists the color scheme (also in local storage). This was
+ // anyway never released, was only ever an internal user flag.
+ localStorage.removeItem("theme");
+};
+*/
diff --git a/web/packages/new/photos/types/context.ts b/web/packages/new/photos/types/context.ts
index 5a9e21816d..28d6ce7aa5 100644
--- a/web/packages/new/photos/types/context.ts
+++ b/web/packages/new/photos/types/context.ts
@@ -1,5 +1,4 @@
import type { AccountsContextT } from "@/accounts/types/context";
-import { THEME_COLOR } from "@/base/components/utils/theme";
import { type NotificationAttributes } from "@/new/photos/components/Notification";
import { createContext, useContext } from "react";
@@ -27,8 +26,6 @@ export type AppContextT = AccountsContextT & {
onGenericError: (error: unknown) => void;
watchFolderView: boolean;
setWatchFolderView: (isOpen: boolean) => void;
- themeColor: THEME_COLOR;
- setThemeColor: (themeColor: THEME_COLOR) => void;
};
/**
diff --git a/web/packages/shared/hooks/useLocalState.tsx b/web/packages/shared/hooks/useLocalState.tsx
deleted file mode 100644
index f1fad09bc1..0000000000
--- a/web/packages/shared/hooks/useLocalState.tsx
+++ /dev/null
@@ -1,24 +0,0 @@
-import { LS_KEYS, getData, setData } from "@ente/shared/storage/localStorage";
-import { useEffect, useState } from "react";
-
-export function useLocalState<T>(
- key: LS_KEYS,
- initialValue: T,
-): [T, (newValue: T) => void] {
- const [value, setValue] = useState<T>(initialValue);
-
- useEffect(() => {
- const { value } = getData(key) ?? {};
- if (typeof value !== "undefined") {
- setValue(value);
- }
- }, []);
-
- useEffect(() => {
- if (typeof value !== "undefined") {
- setData(key, { value });
- }
- }, [value]);
-
- return [value, setValue];
-}
diff --git a/web/packages/shared/storage/localStorage/index.ts b/web/packages/shared/storage/localStorage/index.ts
index 83c3379930..c11f3d2d60 100644
--- a/web/packages/shared/storage/localStorage/index.ts
+++ b/web/packages/shared/storage/localStorage/index.ts
@@ -12,7 +12,6 @@ export enum LS_KEYS {
// LOGS = "logs",
// Migrated to (and only used by) useCollectionsSortByLocalState.
COLLECTION_SORT_BY = "collectionSortBy",
- THEME = "theme",
// Moved to the new wrapper @/base/local-storage
// LOCALE = 'locale',
SRP_SETUP_ATTRIBUTES = "srpSetupAttributes",