Skip to content

armgit / ente

Public Imported from GitHub
0

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

wip refactor

Manav Rathi3b951f237f78
diff --git a/web/packages/new/photos/components/MLSettings.tsx b/web/packages/new/photos/components/MLSettings.tsx
index a74fe48460..33c7367cdf 100644
--- a/web/packages/new/photos/components/MLSettings.tsx
+++ b/web/packages/new/photos/components/MLSettings.tsx
@@ -3,13 +3,14 @@ import {
disableML,
enableML,
getIsMLEnabledRemote,
- isMLEnabled,
pauseML,
} from "@/new/photos/services/ml";
import { EnteDrawer } from "@/new/shared/components/EnteDrawer";
import { MenuItemGroup } from "@/new/shared/components/Menu";
import { Titlebar } from "@/new/shared/components/Titlebar";
+import { pt } from "@/next/i18n";
import log from "@/next/log";
+import EnteSpinner from "@ente/shared/components/EnteSpinner";
import { EnteMenuItem } from "@ente/shared/components/Menu/EnteMenuItem";
import {
Box,
@@ -51,6 +52,21 @@ export const MLSettings: React.FC<MLSettingsProps> = ({
finishLoading,
} = appContext;
+ /**
+ * The state of our component.
+ *
+ * To avoid confusion with useState, we call it status instead. */
+ // TODO: This Status is not automatically synced with the lower layers that
+ // hold the actual state.
+ type Status =
+ | "loading" /* fetching the data we need from the lower layers */
+ | "notEligible" /* user is not in the beta program */
+ | "disabled" /* eligible, but ML is currently disabled */
+ | "enabled" /* ML is enabled */
+ | "paused"; /* ML is disabled locally, but is otherwise enabled */
+
+ const [status, setStatus] = useState<Status>("loading");
+
const [enableFaceSearchView, setEnableFaceSearchView] = useState(false);
const handleRootClose = () => {
@@ -185,6 +201,25 @@ export const MLSettings: React.FC<MLSettingsProps> = ({
</Box>
)*/
+ const components: Record<Status, React.ReactNode> = {
+ loading: <Loading />,
+ disabled: (
+ <EnableML
+ onClose={onClose}
+ onEnable={enableMlSearch}
+ onRootClose={handleRootClose}
+ />
+ ),
+ enabled: (
+ <ManageMLSearch
+ onClose={onClose}
+ disableMlSearch={disableMlSearch}
+ handleDisableFaceSearch={confirmDisableFaceSearch}
+ onRootClose={handleRootClose}
+ />
+ ),
+ };
+
return (
<Box>
<EnteDrawer
@@ -196,20 +231,14 @@ export const MLSettings: React.FC<MLSettingsProps> = ({
sx: { "&&&": { backgroundColor: "transparent" } },
}}
>
- {isMLEnabled() ? (
- <ManageMLSearch
- onClose={onClose}
- disableMlSearch={disableMlSearch}
- handleDisableFaceSearch={confirmDisableFaceSearch}
- onRootClose={handleRootClose}
- />
- ) : (
- <EnableMLSearch
+ <Stack spacing={"4px"} py={"12px"}>
+ <Titlebar
onClose={onClose}
- enableMlSearch={enableMlSearch}
- onRootClose={handleRootClose}
+ title={pt("ML search")}
+ onRootClose={onRootClose}
/>
- )}
+ {components[status] ?? <Loading />}
+ </Stack>
</EnteDrawer>
<EnableFaceSearch
@@ -222,6 +251,73 @@ export const MLSettings: React.FC<MLSettingsProps> = ({
);
};
+const Loading: React.FC = () => {
+ return (
+ <Box textAlign="center" pt={4}>
+ <EnteSpinner />
+ </Box>
+ );
+};
+type EnableMLProps = Omit<MLSettingsProps, "open" | "appContext"> & {
+ /** Called when the user enables ML */
+ onEnable: () => void;
+};
+
+const EnableML: React.FC<EnableMLProps> = ({
+ onClose,
+ enableMlSearch,
+ onRootClose,
+}) => {
+ // const showDetails = () =>
+ // openLink("https://ente.io/blog/desktop-ml-beta", true);
+
+ const [canEnable, setCanEnable] = useState(false);
+
+ useEffect(() => {
+ canEnableML().then((v) => setCanEnable(v));
+ }, []);
+
+ return (
+ <Stack spacing={"4px"} py={"12px"}>
+ <Titlebar
+ onClose={onClose}
+ title={pt("ML search")}
+ onRootClose={onRootClose}
+ />
+ <Stack py={"20px"} px={"8px"} spacing={"32px"}>
+ {canEnable ? (
+ <Stack px={"8px"} spacing={"8px"}>
+ <Button
+ color={"accent"}
+ size="large"
+ onClick={enableMlSearch}
+ >
+ {t("ENABLE")}
+ </Button>
+ {/*
+ <Button
+ color="secondary"
+ size="large"
+ onClick={showDetails}
+ >
+ {t("ML_MORE_DETAILS")}
+ </Button>
+ */}
+ </Stack>
+ ) : (
+ <Box px={"8px"}>
+ {" "}
+ <Typography color="text.muted">
+ {/* <Trans i18nKey={"ENABLE_ML_SEARCH_DESCRIPTION"} /> */}
+ We're putting finishing touches, coming back soon!
+ </Typography>
+ </Box>
+ )}
+ </Stack>
+ </Stack>
+ );
+};
+
function EnableFaceSearch({ open, onClose, enableFaceSearch, onRootClose }) {
const [acceptTerms, setAcceptTerms] = useState(false);
@@ -317,57 +413,6 @@ function EnableFaceSearch({ open, onClose, enableFaceSearch, onRootClose }) {
);
}
-function EnableMLSearch({ onClose, enableMlSearch, onRootClose }) {
- // const showDetails = () =>
- // openLink("https://ente.io/blog/desktop-ml-beta", true);
-
- const [canEnable, setCanEnable] = useState(false);
-
- useEffect(() => {
- canEnableML().then((v) => setCanEnable(v));
- }, []);
-
- return (
- <Stack spacing={"4px"} py={"12px"}>
- <Titlebar
- onClose={onClose}
- title={t("ML_SEARCH")}
- onRootClose={onRootClose}
- />
- <Stack py={"20px"} px={"8px"} spacing={"32px"}>
- {canEnable ? (
- <Stack px={"8px"} spacing={"8px"}>
- <Button
- color={"accent"}
- size="large"
- onClick={enableMlSearch}
- >
- {t("ENABLE")}
- </Button>
- {/*
- <Button
- color="secondary"
- size="large"
- onClick={showDetails}
- >
- {t("ML_MORE_DETAILS")}
- </Button>
- */}
- </Stack>
- ) : (
- <Box px={"8px"}>
- {" "}
- <Typography color="text.muted">
- {/* <Trans i18nKey={"ENABLE_ML_SEARCH_DESCRIPTION"} /> */}
- We're putting finishing touches, coming back soon!
- </Typography>
- </Box>
- )}
- </Stack>
- </Stack>
- );
-}
-
function ManageMLSearch({
onClose,
disableMlSearch,