Skip to content

armgit / ente

Public Imported from GitHub
0

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

Omit middleman

Manav Rathi3b4897b86a6f
diff --git a/web/apps/photos/src/components/PhotoViewer/FileInfo/index.tsx b/web/apps/photos/src/components/PhotoViewer/FileInfo/index.tsx
index 6fab590737..5db9e8d40a 100644
--- a/web/apps/photos/src/components/PhotoViewer/FileInfo/index.tsx
+++ b/web/apps/photos/src/components/PhotoViewer/FileInfo/index.tsx
@@ -1,3 +1,4 @@
+import { isMLEnabled } from "@/new/photos/services/ml";
import { EnteFile } from "@/new/photos/types/file";
import CopyButton from "@ente/shared/components/CodeBlock/CopyButton";
import { FlexWrapper } from "@ente/shared/components/Container";
@@ -328,7 +329,7 @@ export function FileInfo({
</InfoItem>
)}
- {appContext.mlSearchEnabled && (
+ {isMLEnabled() && (
<>
{/* <PhotoPeopleList file={file} /> */}
<UnidentifiedFaces file={file} />
diff --git a/web/apps/photos/src/components/Search/SearchBar/searchInput/MenuWithPeople.tsx b/web/apps/photos/src/components/Search/SearchBar/searchInput/MenuWithPeople.tsx
index fd073af643..6242090dfe 100644
--- a/web/apps/photos/src/components/Search/SearchBar/searchInput/MenuWithPeople.tsx
+++ b/web/apps/photos/src/components/Search/SearchBar/searchInput/MenuWithPeople.tsx
@@ -1,9 +1,8 @@
+import { isMLEnabled } from "@/new/photos/services/ml";
import { Row } from "@ente/shared/components/Container";
import { Box, styled } from "@mui/material";
import { PeopleList } from "components/ml/PeopleList";
import { t } from "i18next";
-import { AppContext } from "pages/_app";
-import { useContext } from "react";
import { components } from "react-select";
import { Suggestion, SuggestionType } from "types/search";
@@ -23,7 +22,6 @@ const Caption = styled("span")`
`;
const MenuWithPeople = (props) => {
- const appContext = useContext(AppContext);
// log.info("props.selectProps.options: ", selectRef);
const peopleSuggestions = props.selectProps.options.filter(
(o) => o.type === SuggestionType.PERSON,
@@ -38,13 +36,13 @@ const MenuWithPeople = (props) => {
return (
<Menu {...props}>
<Box my={1}>
- {((appContext.mlSearchEnabled && indexStatus) ||
+ {((isMLEnabled() && indexStatus) ||
(people && people.length > 0)) && (
<Box>
<Legend>{t("PEOPLE")}</Legend>
</Box>
)}
- {appContext.mlSearchEnabled && indexStatus && (
+ {isMLEnabled() && indexStatus && (
<Box>
<Caption>{indexStatusSuggestion.label}</Caption>
</Box>
diff --git a/web/apps/photos/src/components/Search/SearchBar/searchInput/index.tsx b/web/apps/photos/src/components/Search/SearchBar/searchInput/index.tsx
index 185121d344..0f21564877 100644
--- a/web/apps/photos/src/components/Search/SearchBar/searchInput/index.tsx
+++ b/web/apps/photos/src/components/Search/SearchBar/searchInput/index.tsx
@@ -1,4 +1,5 @@
import { FILE_TYPE } from "@/media/file-type";
+import { isMLEnabled } from "@/new/photos/services/ml";
import type { Person } from "@/new/photos/services/ml/people";
import { EnteFile } from "@/new/photos/types/file";
import CloseIcon from "@mui/icons-material/Close";
@@ -200,9 +201,7 @@ export default function SearchInput(props: Iprops) {
onInputChange={handleInputChange}
escapeClearsValue
styles={SelectStyles}
- defaultOptions={
- appContext.mlSearchEnabled ? defaultOptions : null
- }
+ defaultOptions={isMLEnabled() ? defaultOptions : null}
noOptionsMessage={() => null}
/>
diff --git a/web/apps/photos/src/components/ml/MLSearchSettings.tsx b/web/apps/photos/src/components/ml/MLSearchSettings.tsx
index a2523ba962..118684dccc 100644
--- a/web/apps/photos/src/components/ml/MLSearchSettings.tsx
+++ b/web/apps/photos/src/components/ml/MLSearchSettings.tsx
@@ -1,4 +1,9 @@
-import { canEnableFaceIndexing } from "@/new/photos/services/ml";
+import {
+ canEnableFaceIndexing,
+ disableML,
+ enableML,
+ isMLEnabled,
+} from "@/new/photos/services/ml";
import log from "@/next/log";
import { EnteMenuItem } from "@ente/shared/components/Menu/EnteMenuItem";
import {
@@ -26,8 +31,6 @@ import {
export const MLSearchSettings = ({ open, onClose, onRootClose }) => {
const {
- updateMlSearchEnabled,
- mlSearchEnabled,
setDialogMessage,
somethingWentWrong,
startLoading,
@@ -49,7 +52,7 @@ export const MLSearchSettings = ({ open, onClose, onRootClose }) => {
if (!hasEnabledFaceSearch) {
openEnableFaceSearch();
} else {
- updateMlSearchEnabled(true);
+ enableML();
}
} catch (e) {
log.error("Enable ML search failed", e);
@@ -62,7 +65,7 @@ export const MLSearchSettings = ({ open, onClose, onRootClose }) => {
startLoading();
// Update the consent flag.
await updateFaceSearchEnabledStatus(true);
- updateMlSearchEnabled(true);
+ enableML();
closeEnableFaceSearch();
finishLoading();
} catch (e) {
@@ -73,7 +76,7 @@ export const MLSearchSettings = ({ open, onClose, onRootClose }) => {
const disableMlSearch = async () => {
try {
- await updateMlSearchEnabled(false);
+ disableML();
onClose();
} catch (e) {
log.error("Disable ML search failed", e);
@@ -133,7 +136,7 @@ export const MLSearchSettings = ({ open, onClose, onRootClose }) => {
sx: { "&&&": { backgroundColor: "transparent" } },
}}
>
- {mlSearchEnabled ? (
+ {isMLEnabled() ? (
<ManageMLSearch
onClose={onClose}
disableMlSearch={disableMlSearch}
diff --git a/web/apps/photos/src/pages/_app.tsx b/web/apps/photos/src/pages/_app.tsx
index be914720b3..e39ab8fb0e 100644
--- a/web/apps/photos/src/pages/_app.tsx
+++ b/web/apps/photos/src/pages/_app.tsx
@@ -1,11 +1,6 @@
import type { AccountsContextT } from "@/accounts/types/context";
import DownloadManager from "@/new/photos/services/download";
-import {
- disableML,
- enableML,
- initML,
- isMLEnabled,
-} from "@/new/photos/services/ml";
+import { initML } from "@/new/photos/services/ml";
import { clientPackageName, staticAppTitle } from "@/next/app";
import { CustomHead } from "@/next/components/Head";
import { setupI18n } from "@/next/i18n";
@@ -81,9 +76,7 @@ const redirectMap = new Map([
* Properties available via {@link AppContext} to the Photos app's React tree.
*/
type AppContextT = AccountsContextT & {
- mlSearchEnabled: boolean;
mapEnabled: boolean;
- updateMlSearchEnabled: (enabled: boolean) => Promise<void>;
updateMapEnabled: (enabled: boolean) => Promise<void>;
startLoading: () => void;
finishLoading: () => void;
@@ -116,7 +109,6 @@ export default function App({ Component, pageProps }: AppProps) {
);
const [showNavbar, setShowNavBar] = useState(false);
const [redirectName, setRedirectName] = useState<string>(null);
- const [mlSearchEnabled, setMlSearchEnabled] = useState(false);
const [mapEnabled, setMapEnabled] = useState(false);
const isLoadingBarRunning = useRef(false);
const loadingBar = useRef(null);
@@ -183,7 +175,6 @@ export default function App({ Component, pageProps }: AppProps) {
};
initML();
- setMlSearchEnabled(isMLEnabled());
electron.onOpenURL(handleOpenURL);
electron.onAppUpdateAvailable(showUpdateDialog);
@@ -282,14 +273,6 @@ export default function App({ Component, pageProps }: AppProps) {
}, [notificationAttributes]);
const showNavBar = (show: boolean) => setShowNavBar(show);
- const updateMlSearchEnabled = async (enabled: boolean) => {
- try {
- enabled ? enableML() : disableML();
- setMlSearchEnabled(enabled);
- } catch (e) {
- log.error("Error while updating mlSearchEnabled", e);
- }
- };
const updateMapEnabled = async (enabled: boolean) => {
try {
@@ -323,14 +306,11 @@ export default function App({ Component, pageProps }: AppProps) {
});
const logout = () => {
- setMlSearchEnabled(false);
void photosLogout().then(() => router.push(PAGES.ROOT));
};
const appContext = {
showNavBar,
- mlSearchEnabled,
- updateMlSearchEnabled,
startLoading,
finishLoading,
closeMessageDialog,
diff --git a/web/packages/new/photos/services/ml/index.ts b/web/packages/new/photos/services/ml/index.ts
index 8db6aa0134..685a056ecc 100644
--- a/web/packages/new/photos/services/ml/index.ts
+++ b/web/packages/new/photos/services/ml/index.ts
@@ -101,7 +101,9 @@ export const canEnableFaceIndexing = async () =>
* local) storage key, but otherwise this setting now reflects the state of ML
* overall and not just face search.
*/
-export const isMLEnabled = () => _isMLEnabled;
+export const isMLEnabled = () =>
+ // Impl note: Keep it fast, the UI directly calls this multiple times.
+ _isMLEnabled;
/**
* Enable ML.