π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Doc and move
Manav Rathi12793858d032
diff --git a/web/apps/photos/src/components/DeleteAccountModal.tsx b/web/apps/photos/src/components/DeleteAccountModal.tsxindex bea832ebe0..6d20f405cd 100644--- a/web/apps/photos/src/components/DeleteAccountModal.tsx+++ b/web/apps/photos/src/components/DeleteAccountModal.tsx@@ -3,6 +3,10 @@ import { TitledMiniDialog } from "@/base/components/MiniDialog";import { FocusVisibleButton } from "@/base/components/mui/FocusVisibleButton";import { LoadingButton } from "@/base/components/mui/LoadingButton";import { sharedCryptoWorker } from "@/base/crypto";+import {+ DropdownInput,+ type DropdownOption,+} from "@/new/photos/components/DropdownInput";import { AppContext } from "@/new/photos/types/context";import { initiateEmail } from "@/new/photos/utils/web";import { getData, LS_KEYS } from "@ente/shared/storage/localStorage";@@ -23,7 +27,6 @@ import React, { useContext, useRef, useState } from "react";import { Trans } from "react-i18next";import { deleteAccount, getAccountDeleteChallenge } from "services/userService";import * as Yup from "yup";-import { DropdownInput_, DropdownOption } from "./DropdownInput";interface Iprops {onClose: () => void;@@ -157,13 +160,13 @@ const DeleteAccountModal = ({ open, onClose }: Iprops) => {<Typography>{t("delete_account_reason_label")}</Typography>- <DropdownInput_+ <DropdownInputoptions={deleteReasonOptions()}placeholder={t("delete_account_reason_placeholder",)}selected={values.reason}- setSelected={handleChange("reason")}+ onSelect={handleChange("reason")}/>{errors.reason && (<Typographydiff --git a/web/apps/photos/src/components/Sidebar/Preferences.tsx b/web/apps/photos/src/components/Sidebar/Preferences.tsxindex 6291a28c46..d5bde7d5be 100644--- a/web/apps/photos/src/components/Sidebar/Preferences.tsx+++ b/web/apps/photos/src/components/Sidebar/Preferences.tsx@@ -12,6 +12,7 @@ import {supportedLocales,type SupportedLocale,} from "@/base/i18n";+import { DropdownInput } from "@/new/photos/components/DropdownInput";import { MLSettings } from "@/new/photos/components/sidebar/MLSettings";import {confirmDisableMapsDialogAttributes,@@ -29,7 +30,6 @@ import { useAppContext } from "@/new/photos/types/context";import { EnteMenuItem } from "@ente/shared/components/Menu/EnteMenuItem";import ChevronRightIcon from "@mui/icons-material/ChevronRight";import { Divider, Stack, Typography, useColorScheme } from "@mui/material";-import { DropdownInput_ } from "components/DropdownInput";import { t } from "i18next";import React, { useCallback, useEffect } from "react";@@ -125,10 +125,10 @@ const LanguageSelector = () => {<Typography variant="small" sx={{ px: 1, color: "text.muted" }}>{t("language")}</Typography>- <DropdownInput_+ <DropdownInputoptions={options}selected={locale}- setSelected={updateCurrentLocale}+ onSelect={updateCurrentLocale}/></Stack>);@@ -182,14 +182,14 @@ const ThemeSelector = () => {<Typography variant="small" sx={{ px: 1, color: "text.muted" }}>{pt("Theme")}</Typography>- <DropdownInput_+ <DropdownInputoptions={[{ label: pt("System"), value: "system" },{ label: pt("Light"), value: "light" },{ label: pt("Dark"), value: "dark" },]}selected={mode}- setSelected={setMode}+ onSelect={setMode}/></Stack>);diff --git a/web/apps/photos/src/components/DropdownInput.tsx b/web/packages/new/photos/components/DropdownInput.tsxsimilarity index 63%rename from web/apps/photos/src/components/DropdownInput.tsxrename to web/packages/new/photos/components/DropdownInput.tsxindex 93375e4328..e6a5e1c101 100644--- a/web/apps/photos/src/components/DropdownInput.tsx+++ b/web/packages/new/photos/components/DropdownInput.tsx@@ -1,82 +1,53 @@-import { isSxArray } from "@/base/components/utils/sx";import ExpandMoreIcon from "@mui/icons-material/ExpandMore";import {Box,MenuItem,Select,- SelectChangeEvent,- Stack,+ type SelectChangeEvent,Typography,- type TypographyProps,} from "@mui/material";+/**+ * A label, and the associated value, shown in the {@link DropdownInput}.+ */export interface DropdownOption<T> {label: string;value: T;}-interface Iprops<T> {- label: string;- labelSxProps?: TypographyProps["sx"];- options: DropdownOption<T>[];- message?: string;- messageSxProps?: TypographyProps["sx"];- selected: T;- setSelected: (selectedValue: T) => void;- placeholder?: string;-}--export default function DropdownInput<T extends string>({- label,- labelSxProps,- options,- message,- selected,- placeholder,- setSelected,- messageSxProps,-}: Iprops<T>) {- return (- <Stack spacing={"4px"}>- <Typography sx={labelSxProps ?? {}}>{label}</Typography>- <DropdownInput_- {...{- options,- selected,- setSelected,- placeholder,- }}- />- {message && (- <Typography- variant="small"- sx={[- { px: "8px", color: "text.muted" },- ...(isSxArray(messageSxProps)- ? messageSxProps- : [messageSxProps]),- ]}- >- {message}- </Typography>- )}- </Stack>- );-}--interface DropdownInputProps_<T> {+interface DropdownInputProps<T> {+ /**+ * The dropdown options.+ */options: DropdownOption<T>[];- selected: T;- setSelected: (selectedValue: T) => void;+ /**+ * The currently selected value, if any.+ */+ selected: T | undefined;+ /**+ * Callback invoked when the user changes the selected value.+ */+ onSelect: (selectedValue: T) => void;+ /**+ * An optional placeholder shown when there is no selected value.+ */placeholder?: string;}-export const DropdownInput_ = <T extends string>({+/**+ * A custom MUI {@link Select} with a look as per our designs, and with an+ * narrower interface focused on picking from a static list of options.+ *+ * This behaves as a controlled component - the caller is expected to set the+ * {@link selected} prop. The caller will then be notified of changes by calls+ * to the {@link onSelect} function.+ */+export const DropdownInput = <T extends string>({options,selected,- setSelected,+ onSelect,placeholder,-}: DropdownInputProps_<T>) => (+}: DropdownInputProps<T>) => (<SelectIconComponent={ExpandMoreIcon}displayEmpty@@ -128,15 +99,18 @@ export const DropdownInput_ = <T extends string>({},}}renderValue={(selected) => {+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-conditionreturn !selected?.length ? (<Box sx={{ color: "text.muted" }}>{placeholder ?? ""}</Box>) : (+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment+ // @ts-ignoreoptions.find((o) => o.value === selected).label);}}value={selected}onChange={(event: SelectChangeEvent) => {- setSelected(event.target.value as T);+ onSelect(event.target.value as T);}}>{options.map((option, index) => (