π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
feat(photos):show-ml-consent-before-opening-people
Aswin Asok34e177555f2b
diff --git a/web/apps/photos/src/components/gallery/index.tsx b/web/apps/photos/src/components/gallery/index.tsxindex f240f77975..35386e6319 100644--- a/web/apps/photos/src/components/gallery/index.tsx+++ b/web/apps/photos/src/components/gallery/index.tsx@@ -1,22 +1,30 @@// TODO: Move this code back into gallery.tsx.-import {- EnableML,- FaceConsent,-} from "@/components/sidebar/preferences/MLSettings";+import { FaceConsent } from "@/components/sidebar/preferences/MLSettings";import { useWrapAsyncOperation } from "@/components/utils/use-wrap-async";import CheckIcon from "@mui/icons-material/Check";+import CloseIcon from "@mui/icons-material/Close";import SortIcon from "@mui/icons-material/Sort";import {+ Dialog,+ DialogContent,+ DialogTitle,IconButton,Menu,- Paper,Stack,Tooltip,Typography,} from "@mui/material";import { CenteredFill, SpacedRow } from "ente-base/components/containers";+import { FocusVisibleButton } from "ente-base/components/mui/FocusVisibleButton";import { OverflowMenuOption } from "ente-base/components/OverflowMenu";+import {+ v2CloseButtonSx,+ v2HeaderRowSx,+ v2PaperSx,+ v2TitleSx,+} from "ente-base/components/SingleInput.styles";+import type { ModalVisibilityProps } from "ente-base/components/utils/modal";import { useModalVisibility } from "ente-base/components/utils/modal";import {GalleryItemsHeaderAdapter,@@ -186,12 +194,20 @@ const SearchSortOrderMenu: React.FC<SearchSortOrderMenuProps> = ({);};-export const PeopleEmptyState: React.FC = () => {+export const PeopleEmptyState: React.FC<{ onEnableML: () => void }> = ({+ onEnableML,+}) => {const mlStatus = useMLStatusSnapshot();switch (mlStatus?.phase) {case "disabled":- return <PeopleEmptyStateDisabled />;+ return (+ <CenteredFill>+ <FocusVisibleButton color="accent" onClick={onEnableML}>+ {t("enable")}+ </FocusVisibleButton>+ </CenteredFill>+ );case "done":return (<PeopleEmptyStateMessage>@@ -224,33 +240,64 @@ const PeopleEmptyStateMessage: React.FC<React.PropsWithChildren> = ({</CenteredFill>);-const PeopleEmptyStateDisabled: React.FC = () => {- const [showConsent, setShowConsent] = useState(false);+export const PeopleConsentDialog: React.FC<+ ModalVisibilityProps & { onEnabled: () => void }+> = ({ open, onClose, onEnabled }) => {+ const submittingRef = useRef(false);+ const [submitting, setSubmitting] = useState(false);++ const handleClose = () => {+ if (!submittingRef.current) onClose();+ };const handleConsent = useWrapAsyncOperation(async () => {- await enableML();+ if (submittingRef.current) return;+ submittingRef.current = true;+ setSubmitting(true);+ try {+ await enableML();+ onClose();+ onEnabled();+ } finally {+ submittingRef.current = false;+ setSubmitting(false);+ }});return (- <Stack sx={{ alignItems: "center", flex: 1, overflow: "auto" }}>- <Paper- sx={{- maxWidth: "390px",- padding: "4px",- // Prevent the card shadow from clipping.- mt: 1,- mb: "2rem",- }}- >- {!showConsent ? (- <EnableML onEnable={() => setShowConsent(true)} />- ) : (+ <Dialog+ open={open}+ onClose={handleClose}+ maxWidth={false}+ slotProps={{ paper: { sx: v2PaperSx } }}+ aria-labelledby="people-consent-title"+ >+ <Stack sx={{ p: "20px", gap: "20px" }}>+ <Stack direction="row" sx={v2HeaderRowSx}>+ <DialogTitle+ id="people-consent-title"+ sx={{ ...v2TitleSx, "&&": { p: 0 } }}+ >+ {t("ml_search")}+ </DialogTitle>+ <IconButton+ aria-label={t("close")}+ onClick={handleClose}+ disabled={submitting}+ sx={v2CloseButtonSx}+ >+ <CloseIcon sx={{ fontSize: 18 }} />+ </IconButton>+ </Stack>+ <DialogContent sx={{ "&&": { p: 0 } }}><FaceConsentonConsent={handleConsent}- onCancel={() => setShowConsent(false)}+ onCancel={handleClose}+ submitting={submitting}+ variant="dialog"/>- )}- </Paper>- </Stack>+ </DialogContent>+ </Stack>+ </Dialog>);};diff --git a/web/apps/photos/src/components/sidebar/preferences/MLSettings.tsx b/web/apps/photos/src/components/sidebar/preferences/MLSettings.tsxindex 39b410ba1f..e387966020 100644--- a/web/apps/photos/src/components/sidebar/preferences/MLSettings.tsx+++ b/web/apps/photos/src/components/sidebar/preferences/MLSettings.tsx@@ -16,6 +16,10 @@ import {TitledNestedSidebarDrawer,type NestedSidebarDrawerVisibilityProps,} from "ente-base/components/mui/SidebarDrawer";+import {+ v2CancelButtonSx,+ v2SubmitButtonSx,+} from "ente-base/components/SingleInput.styles";import { RowCard } from "ente-base/components/v2/RowCard";import { useBaseContext } from "ente-base/context";import { useMLStatusSnapshot } from "ente-new/photos/components/utils/use-snapshot";@@ -154,11 +158,15 @@ const FaceConsentDrawer: React.FC<FaceConsentDrawerProps> = ({interface FaceConsentProps {onConsent: () => void;onCancel: () => void;+ submitting?: boolean;+ variant?: "dialog";}export const FaceConsent: React.FC<FaceConsentProps> = ({onConsent,onCancel,+ submitting = false,+ variant,}) => {const [acceptTerms, setAcceptTerms] = useState(false);@@ -176,8 +184,25 @@ export const FaceConsent: React.FC<FaceConsentProps> = ({);return (- <Stack sx={{ gap: 3, py: 1, px: 2 }}>- <Typography component="div" sx={{ color: "text.muted", px: "8px" }}>+ <Stack+ sx={+ variant == "dialog" ? { gap: "20px" } : { gap: 3, py: 1, px: 2 }+ }+ >+ <Typography+ component="div"+ sx={{+ color: "text.muted",+ ...(variant == "dialog"+ ? {+ fontSize: 14,+ lineHeight: "20px",+ "& p:first-of-type": { mt: 0 },+ "& p:last-of-type": { mb: 0 },+ }+ : { px: "8px" }),+ }}+ ><Transi18nKey={"ml_consent_description"}components={{ a: privacyPolicyLink }}@@ -186,10 +211,21 @@ export const FaceConsent: React.FC<FaceConsentProps> = ({<FormGroup sx={{ width: "100%" }}><FormControlLabelsx={{ color: "text.muted", ml: 0 }}+ slotProps={+ variant == "dialog"+ ? {+ typography: {+ sx: { fontSize: 14, lineHeight: "20px" },+ },+ }+ : undefined+ }control={<Checkboxsize="small"+ sx={variant == "dialog" ? { pl: 0 } : undefined}checked={acceptTerms}+ disabled={submitting}onChange={(e) => setAcceptTerms(e.target.checked)}/>}@@ -201,14 +237,26 @@ export const FaceConsent: React.FC<FaceConsentProps> = ({fullWidthcolor="accent"disabled={!acceptTerms}+ loading={submitting}onClick={onConsent}+ sx={+ variant == "dialog"+ ? [v2SubmitButtonSx, { flex: "none" }]+ : undefined+ }>{t("ml_consent")}</FocusVisibleButton><FocusVisibleButtonfullWidthcolor="secondary"+ disabled={submitting}onClick={onCancel}+ sx={+ variant == "dialog"+ ? [v2CancelButtonSx, { flex: "none" }]+ : undefined+ }>{t("cancel")}</FocusVisibleButton>diff --git a/web/apps/photos/src/pages/gallery.tsx b/web/apps/photos/src/pages/gallery.tsxindex 6943fe5ddb..25c1b3fbf5 100644--- a/web/apps/photos/src/pages/gallery.tsx+++ b/web/apps/photos/src/pages/gallery.tsx@@ -30,6 +30,7 @@ import { Upload } from "@/components/Upload";import { WhatsNew } from "@/components/WhatsNew";import {GalleryEmptyState,+ PeopleConsentDialog,PeopleEmptyState,SearchResultsHeader,type RemotePullOpts,@@ -285,6 +286,8 @@ const Page: React.FC = () => {const { show: showSidebar, props: sidebarVisibilityProps } =useModalVisibility();+ const { show: showPeopleConsent, props: peopleConsentVisibilityProps } =+ useModalVisibility();const { show: showPlanSelector, props: planSelectorVisibilityProps } =useModalVisibility();const {@@ -1480,9 +1483,22 @@ const Page: React.FC = () => {[showCollectionSummary],);+ const handleShowPeople = () => {+ if (!isMLEnabled()) {+ showPeopleConsent();+ return;+ }+ setCleanupView(undefined);+ dispatch({ type: "showPeople" });+ };+const handleChangeBarMode = (mode: GalleryBarMode) => {+ if (mode == "people") {+ handleShowPeople();+ return;+ }setCleanupView(undefined);- dispatch({ type: mode == "people" ? "showPeople" : "showAlbums" });+ dispatch({ type: "showAlbums" });};const handleFileViewerToggleFavorite = useCallback(@@ -1993,10 +2009,7 @@ const Page: React.FC = () => {handleShowCollectionSummaryWithID(PseudoCollectionID.all)}onSelectSearchOption={handleSelectSearchOption}- onSelectPeople={() => {- setCleanupView(undefined);- dispatch({ type: "showPeople" });- }}+ onSelectPeople={handleShowPeople}onSelectPerson={handleSelectPerson}galleryBarProps={isCleanupViewOpen@@ -2102,7 +2115,7 @@ const Page: React.FC = () => {!isFirstLoad &&state.view?.type == "people" &&!state.view.activePerson ? (- <PeopleEmptyState />+ <PeopleEmptyState onEnableML={showPeopleConsent} />) : (<FileListWithViewermode={barMode}@@ -2212,6 +2225,10 @@ const Page: React.FC = () => {{sidebarVisibilityProps.open && subscriptionDialogs}</Sidebar><WhatsNew {...whatsNewVisibilityProps} />+ <PeopleConsentDialog+ {...peopleConsentVisibilityProps}+ onEnabled={handleShowPeople}+ /><AssignPersonDialog{...contextMenuAssignPersonProps}people={namedPeople}