π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
wip: checkpoint
Manav Rathi6a489ad5209d
diff --git a/web/apps/photos/src/components/Collections/CollectionListBar.tsx b/web/apps/photos/src/components/Collections/CollectionListBar.tsxindex 85de3ec5e8..0a68d5410e 100644--- a/web/apps/photos/src/components/Collections/CollectionListBar.tsx+++ b/web/apps/photos/src/components/Collections/CollectionListBar.tsx@@ -27,6 +27,7 @@ import AutoSizer from "react-virtualized-auto-sizer";import { FixedSizeList, ListChildComponentProps, areEqual } from "react-window";import { CollectionSummary, CollectionSummaryType } from "types/collection";import { ALL_SECTION, COLLECTION_LIST_SORT_BY } from "utils/collection";+import type { GalleryBarMode } from ".";import CollectionCard from "./CollectionCard";import CollectionListSortBy from "./CollectionListSortBy";@@ -34,7 +35,11 @@ export interface CollectionListBarProps {/*** What are we displaying currently.*/- mode: "albums" | "hidden-albums" | "people";+ mode: GalleryBarMode;+ /**+ * Called when the user switches to a different view.+ */+ setMode: (mode: GalleryBarMode) => void;/*** Massaged data about the collections that should be shown in the bar.*/@@ -70,9 +75,9 @@ export interface CollectionListBarProps {*/activePerson: Person | undefined;/**- * Called when the user changes the active person.+ * Called when the user selects the given person in the bar.*/- setActivePerson: (id: Person | undefined) => void;+ onSelectPerson: (person: Person) => void;}export const CollectionListBar: React.FC<CollectionListBarProps> = ({@@ -85,7 +90,7 @@ export const CollectionListBar: React.FC<CollectionListBarProps> = ({setCollectionListSortBy,// people,// activePerson,- // setActivePerson+ // onSelectPerson}) => {const windowSize = useWindowSize();const isMobile = useIsMobileWidth();@@ -259,6 +264,25 @@ const CollectionListBarWrapper = styled(Box)`border-bottom: 1px solid ${({ theme }) => theme.palette.divider};`;+// // TODO-Cluster+// const PeopleHeaderButton = styled("button")(+// ({ theme }) => `+// /* Reset some button defaults that are affecting us */+// background: transparent;+// border: 0;+// padding: 0;+// font: inherit;+// /* Button should do this for us, but it isn't working inside the select */+// cursor: pointer;+// /* The color for the chevron */+// color: ${theme.colors.stroke.muted};+// /* Hover indication */+// && :hover {+// color: ${theme.colors.stroke.base};+// }+// `,+// );+interface ItemData {collectionSummaries: CollectionSummary[];activeCollectionID?: number;diff --git a/web/apps/photos/src/components/Collections/index.tsx b/web/apps/photos/src/components/Collections/index.tsxindex f050152335..50d635a37a 100644--- a/web/apps/photos/src/components/Collections/index.tsx+++ b/web/apps/photos/src/components/Collections/index.tsx@@ -4,10 +4,7 @@ import { useLocalState } from "@ente/shared/hooks/useLocalState";import { LS_KEYS } from "@ente/shared/storage/localStorage";import AllCollections from "components/Collections/AllCollections";import CollectionInfoWithOptions from "components/Collections/CollectionInfoWithOptions";-import {- CollectionListBar,- type CollectionListBarProps,-} from "components/Collections/CollectionListBar";+import { CollectionListBar } from "components/Collections/CollectionListBar";import { SetCollectionNamerAttributes } from "components/Collections/CollectionNamer";import CollectionShare from "components/Collections/CollectionShare";import { ITEM_TYPE, TimeStampListItem } from "components/PhotoList";@@ -29,8 +26,17 @@ import {} from "../FilesDownloadProgress";import AlbumCastDialog from "./CollectionOptions/AlbumCastDialog";+/**+ * Specifies what the bar is displaying currently.+ */+export type GalleryBarMode = "albums" | "hidden-albums" | "people";+interface CollectionsProps {- mode: CollectionListBarProps["mode"] | "search";+ /** `true` if the bar should be hidden altogether. */+ shouldHide: boolean;+ /** otherwise show stuff that belongs to this mode. */+ mode: GalleryBarMode;+ setMode: (mode: GalleryBarMode) => void;collectionSummaries: CollectionSummaries;activeCollection: Collection;activeCollectionID?: number;@@ -38,7 +44,7 @@ interface CollectionsProps {hiddenCollectionSummaries: CollectionSummaries;people: Person[];activePerson: Person | undefined;- setActivePerson: (id: Person | undefined) => void;+ onSelectPerson: (person: Person) => void;setCollectionNamerAttributes: SetCollectionNamerAttributes;setPhotoListHeader: (value: TimeStampListItem) => void;filesDownloadProgressAttributesList: FilesDownloadProgressAttributes[];@@ -46,7 +52,9 @@ interface CollectionsProps {}export const Collections: React.FC<CollectionsProps> = ({+ shouldHide,mode,+ setMode,collectionSummaries,activeCollection,activeCollectionID,@@ -54,7 +62,7 @@ export const Collections: React.FC<CollectionsProps> = ({hiddenCollectionSummaries,people,activePerson,- setActivePerson,+ onSelectPerson,setCollectionNamerAttributes,setPhotoListHeader,filesDownloadProgressAttributesList,@@ -82,10 +90,10 @@ export const Collections: React.FC<CollectionsProps> = ({const shouldBeHidden = useMemo(() =>- mode == "search" ||+ shouldHide ||(!hasNonSystemCollections(toShowCollectionSummaries) &&activeCollectionID === ALL_SECTION),- [mode, toShowCollectionSummaries, activeCollectionID],+ [shouldHide, toShowCollectionSummaries, activeCollectionID],);const sortedCollectionSummaries = useMemo(@@ -109,7 +117,7 @@ export const Collections: React.FC<CollectionsProps> = ({}, [activeCollectionID, filesDownloadProgressAttributesList]);useEffect(() => {- if (mode == "search") return;+ if (shouldHide) return;setPhotoListHeader({item: (@@ -136,13 +144,12 @@ export const Collections: React.FC<CollectionsProps> = ({height: 68,});}, [- mode,+ shouldHide,toShowCollectionSummaries,activeCollectionID,isActiveCollectionDownloadInProgress,]);- if (mode == "search") return <></>;if (shouldBeHidden) {return <></>;}@@ -157,11 +164,12 @@ export const Collections: React.FC<CollectionsProps> = ({<CollectionListBar{...{mode,+ setMode,activeCollectionID,setActiveCollectionID,people,activePerson,- setActivePerson,+ onSelectPerson,collectionListSortBy,setCollectionListSortBy,}}diff --git a/web/apps/photos/src/components/PhotoViewer/FileInfo/index.tsx b/web/apps/photos/src/components/PhotoViewer/FileInfo/index.tsxindex d996b72020..bdcb2a7c1d 100644--- a/web/apps/photos/src/components/PhotoViewer/FileInfo/index.tsx+++ b/web/apps/photos/src/components/PhotoViewer/FileInfo/index.tsx@@ -115,8 +115,7 @@ export const FileInfo: React.FC<FileInfoProps> = ({}const onCollectionChipClick = (collectionID) => {- galleryContext.setActiveCollectionID(collectionID);- galleryContext.setIsInSearchMode(false);+ galleryContext.onShowCollection(collectionID);closePhotoViewer();};diff --git a/web/apps/photos/src/pages/gallery.tsx b/web/apps/photos/src/pages/gallery.tsxindex 9ecab8363a..932ed55334 100644--- a/web/apps/photos/src/pages/gallery.tsx+++ b/web/apps/photos/src/pages/gallery.tsx@@ -54,7 +54,7 @@ import MenuIcon from "@mui/icons-material/Menu";import type { ButtonProps, IconButtonProps } from "@mui/material";import { Box, Button, IconButton, Typography, styled } from "@mui/material";import AuthenticateUserModal from "components/AuthenticateUserModal";-import { Collections } from "components/Collections";+import { Collections, type GalleryBarMode } from "components/Collections";import { CollectionInfo } from "components/Collections/CollectionInfo";import CollectionNamer, {CollectionNamerAttributes,@@ -160,9 +160,9 @@ export const DeadCenter = styled("div")`const defaultGalleryContext: GalleryContextType = {showPlanSelectorModal: () => null,setActiveCollectionID: () => null,+ onShowCollection: () => null,syncWithRemote: () => null,setBlockingLoad: () => null,- setIsInSearchMode: () => null,photoListHeader: null,openExportModal: () => null,authenticateUser: () => null,@@ -247,12 +247,6 @@ export default function Gallery() {accept: ".zip",});- // If we're in "search mode". See: [Note: "search mode"].- const [isInSearchMode, setIsInSearchMode] = useState(false);- // The option selected by the user selected from the search bar dropdown.- const [selectedSearchOption, setSelectedSearchOption] = useState<- SearchOption | undefined- >();const syncInProgress = useRef(true);const syncInterval = useRef<NodeJS.Timeout>();const resync = useRef<{ force: boolean; silent: boolean }>();@@ -316,17 +310,18 @@ export default function Gallery() {const closeAuthenticateUserModal = () =>setAuthenticateUserModalView(false);- // `true` if we're displaying the hidden section.- //- // - The search bar is replaced by a navbar with a back button.- // - The collections bar shows only the hidden collections.- // - The gallery itself shows hidden items.- const [isInHiddenSection, setIsInHiddenSection] = useState(false);-- // If set, then display files belonging to this person.- //- // - The collections bar is replaced with a people bar.- // - The gallery itself shows files which contain this person.+ // True if we're in "search mode". See: [Note: "search mode"].+ const [isInSearchMode, setIsInSearchMode] = useState(false);++ // The option selected by the user selected from the search bar dropdown.+ const [selectedSearchOption, setSelectedSearchOption] = useState<+ SearchOption | undefined+ >();++ // If visible, what should the gallery bar show.+ const [barMode, setBarMode] = useState<GalleryBarMode>("albums");++ // The currently selected person in the gallery bar (if any).const [activePerson, setActivePerson] = useState<Person | undefined>();const people = useSyncExternalStore(peopleSubscribe, peopleSnapshot);@@ -547,13 +542,17 @@ export default function Gallery() {const pfSet = new Set(activePerson.fileIDs);filteredFiles = files.filter((f) => pfSet.has(f.id));} else {+ const baseFiles = barMode == "hidden-albums" ? hiddenFiles : files;filteredFiles = getUniqueFiles(- (isInHiddenSection ? hiddenFiles : files).filter((item) => {+ baseFiles.filter((item) => {if (tempDeletedFileIds?.has(item.id)) {return false;}- if (!isInHiddenSection && tempHiddenFileIds?.has(item.id)) {+ if (+ barMode != "hidden-albums" &&+ tempHiddenFileIds?.has(item.id)+ ) {return false;}@@ -612,6 +611,7 @@ export default function Gallery() {return filteredFiles;}}, [+ barMode,files,trashedFiles,hiddenFiles,@@ -1009,46 +1009,47 @@ export default function Gallery() {setExportModalView(false);};+ const handleShowCollection = (collectionID: number) => {+ setBarMode("albums");+ setActiveCollectionID(collectionID);+ setIsInSearchMode(false);+ };++ const handleShowSearchInput = () => setIsInSearchMode(true);+const openHiddenSection: GalleryContextType["openHiddenSection"] = (callback,) => {authenticateUser(() => {- setIsInHiddenSection(true);+ setBarMode("hidden-albums");setActiveCollectionID(HIDDEN_ITEMS_SECTION);callback?.();});};const exitHiddenSection = () => {- setIsInHiddenSection(false);+ setBarMode("albums");setActiveCollectionID(ALL_SECTION);};- const handleSelectPeople = () => {- console.log("onSelectPeople");+ const handleSelectPerson = (person: Person) => {+ setActivePerson(person);+ setBarMode("people");};if (activePerson) {log.debug(() => ["person", activePerson]);}- const collectionBarMode = isInSearchMode- ? "search"- : isInHiddenSection- ? "hidden-albums"- : activePerson- ? "people"- : "albums";-return (<GalleryContext.Providervalue={{...defaultGalleryContext,showPlanSelectorModal,setActiveCollectionID,+ onShowCollection: handleShowCollection,syncWithRemote,setBlockingLoad,- setIsInSearchMode,photoListHeader,openExportModal,authenticateUser,@@ -1111,7 +1112,7 @@ export default function Gallery() {<NavbarBasesx={{ background: "transparent", position: "absolute" }}>- {isInHiddenSection ? (+ {barMode == "hidden-albums" ? (<HiddenSectionNavbarContentsonBack={exitHiddenSection}/>@@ -1120,16 +1121,17 @@ export default function Gallery() {openSidebar={openSidebar}openUploader={openUploader}isInSearchMode={isInSearchMode}- setIsInSearchMode={setIsInSearchMode}+ onShowSearchInput={handleShowSearchInput}onSelectSearchOption={handleSelectSearchOption}- onSelectPeople={handleSelectPeople}- onSelectPerson={setActivePerson}+ onSelectPerson={handleSelectPerson}/>)}</NavbarBase><Collections- mode={collectionBarMode}+ shouldHide={isInSearchMode}+ mode={barMode}+ setMode={setBarMode}{...{collectionSummaries,activeCollection,@@ -1138,7 +1140,7 @@ export default function Gallery() {hiddenCollectionSummaries,people,activePerson,- setActivePerson,+ onSelectPerson: handleSelectPerson,setCollectionNamerAttributes,setPhotoListHeader,setFilesDownloadProgressAttributesCreator,@@ -1218,7 +1220,7 @@ export default function Gallery() {showAppDownloadBanner={files.length < 30 && !isInSearchMode}- isInHiddenSection={isInHiddenSection}+ isInHiddenSection={barMode == "hidden-albums"}setFilesDownloadProgressAttributesCreator={setFilesDownloadProgressAttributesCreator}@@ -1262,7 +1264,7 @@ export default function Gallery() {CollectionSummaryType.incomingShareViewer}isInSearchMode={isInSearchMode}- isInHiddenSection={isInHiddenSection}+ isInHiddenSection={barMode == "hidden-albums"}/>)}<ExportModaldiff --git a/web/apps/photos/src/types/gallery/index.ts b/web/apps/photos/src/types/gallery/index.tsindex ce789d31a0..2c37533708 100644--- a/web/apps/photos/src/types/gallery/index.ts+++ b/web/apps/photos/src/types/gallery/index.ts@@ -42,9 +42,10 @@ export type MergedSourceURL = {export type GalleryContextType = {showPlanSelectorModal: () => void;setActiveCollectionID: (collectionID: number) => void;+ /** Newer and almost equivalent alternative to setActiveCollectionID. */+ onShowCollection: (collectionID: number) => void;syncWithRemote: (force?: boolean, silent?: boolean) => Promise<void>;setBlockingLoad: (value: boolean) => void;- setIsInSearchMode: (value: boolean) => void;photoListHeader: TimeStampListItem;openExportModal: () => void;authenticateUser: (callback: () => void) => void;diff --git a/web/packages/new/photos/components/SearchBar.tsx b/web/packages/new/photos/components/SearchBar.tsxindex e46b4d3cc0..524a9d5f37 100644--- a/web/packages/new/photos/components/SearchBar.tsx+++ b/web/packages/new/photos/components/SearchBar.tsx@@ -61,17 +61,17 @@ export interface SearchBarProps {*/isInSearchMode: boolean;/**- * Enter or exit "search mode".+ * Invoked when the user wants to enter "search mode".+ *+ * This scenario only arises when the search bar is in the mobile device+ * sized configuration, where the user needs to tap the search icon to enter+ * the search mode.*/- setIsInSearchMode: (b: boolean) => void;+ onShowSearchInput: () => void;/*** Set or clear the selected {@link SearchOption}.*/onSelectSearchOption: (o: SearchOption | undefined) => void;- /**- * Select a option to view details about all people.- */- onSelectPeople: () => void;/*** Select a person.*/@@ -94,18 +94,16 @@ export interface SearchBarProps {* list of files that match that suggestion.*/export const SearchBar: React.FC<SearchBarProps> = ({- setIsInSearchMode,isInSearchMode,+ onShowSearchInput,...rest}) => {const isMobileWidth = useIsMobileWidth();- const showSearchInput = () => setIsInSearchMode(true);-return (<Box sx={{ flex: 1, px: ["4px", "24px"] }}>{isMobileWidth && !isInSearchMode ? (- <MobileSearchArea onSearch={showSearchInput} />+ <MobileSearchArea onSearch={onShowSearchInput} />) : (<SearchInput {...{ isInSearchMode }} {...rest} />)}@@ -126,10 +124,9 @@ const MobileSearchArea: React.FC<MobileSearchAreaProps> = ({ onSearch }) => (</Box>);-const SearchInput: React.FC<Omit<SearchBarProps, "setIsInSearchMode">> = ({+const SearchInput: React.FC<Omit<SearchBarProps, "onShowSearchInput">> = ({isInSearchMode,onSelectSearchOption,- onSelectPeople,onSelectPerson,}) => {// A ref to the top level Select.@@ -187,11 +184,6 @@ const SearchInput: React.FC<Omit<SearchBarProps, "setIsInSearchMode">> = ({onSelectSearchOption(undefined);};- const handleSelectPeople = () => {- resetSearch();- onSelectPeople();- };-const handleSelectPerson = (person: Person) => {resetSearch();onSelectPerson(person);@@ -226,10 +218,7 @@ const SearchInput: React.FC<Omit<SearchBarProps, "setIsInSearchMode">> = ({placeholder={t("search_hint")}noOptionsMessage={({ inputValue }) =>shouldShowEmptyState(inputValue) ? (- <EmptyState- onSelectPeople={handleSelectPeople}- onSelectPerson={handleSelectPerson}- />+ <EmptyState onSelectPerson={handleSelectPerson} />) : null}/>@@ -380,13 +369,7 @@ const shouldShowEmptyState = (inputValue: string) => {};interface EmptyStateProps {- /**- * Called when the user selects the people banner in the empty state view.- */- onSelectPeople: () => void;- /**- * Called when the user selects a particular person shown in the empty state- * view. */+ /** Called when the user selects a person shown in the empty state view. */onSelectPerson: (person: Person) => void;}@@ -394,10 +377,7 @@ interface EmptyStateProps {* The view shown in the menu area when the user has not typed anything in the* search box.*/-const EmptyState: React.FC<EmptyStateProps> = ({- onSelectPeople,- onSelectPerson,-}) => {+const EmptyState: React.FC<EmptyStateProps> = ({ onSelectPerson }) => {const mlStatus = useSyncExternalStore(mlStatusSubscribe, mlStatusSnapshot);const people = useSyncExternalStore(peopleSubscribe, peopleSnapshot);@@ -431,7 +411,7 @@ const EmptyState: React.FC<EmptyStateProps> = ({<Box sx={{ textAlign: "left" }}>{people && people.length > 0 && (<>- <PeopleHeader onClick={onSelectPeople} />+ <PeopleHeader /><SearchPeopleList {...{ people, onSelectPerson }} /></>)}@@ -442,37 +422,13 @@ const EmptyState: React.FC<EmptyStateProps> = ({);};-interface PeopleHeaderProps {- onClick: () => void;-}--const PeopleHeader: React.FC<PeopleHeaderProps> = ({ onClick }) => (- <PeopleHeaderButton {...{ onClick }}>- <Stack direction="row" color="text.muted">- <Typography color="text.base" variant="large">- {t("people")}- </Typography>- <ChevronRightIcon />- </Stack>- </PeopleHeaderButton>-);--const PeopleHeaderButton = styled("button")(- ({ theme }) => `- /* Reset some button defaults that are affecting us */- background: transparent;- border: 0;- padding: 0;- font: inherit;- /* Button should do this for us, but it isn't working inside the select */- cursor: pointer;- /* The color for the chevron */- color: ${theme.colors.stroke.muted};- /* Hover indication */- && :hover {- color: ${theme.colors.stroke.base};- }-`,+const PeopleHeader: React.FC = () => (+ <Stack direction="row" color="text.muted">+ <Typography color="text.base" variant="large">+ {t("people")}+ </Typography>+ <ChevronRightIcon />+ </Stack>);const Option: React.FC<OptionProps<SearchOption, false>> = (props) => (