π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
[photos][web] Keep collection sort hook in its existing component
AswinAsok56d183d1d910
diff --git a/web/apps/photos/src/components/Collections/GalleryBarAndListHeader.tsx b/web/apps/photos/src/components/Collections/GalleryBarAndListHeader.tsxindex 3400e4e7be..af982b2233 100644--- a/web/apps/photos/src/components/Collections/GalleryBarAndListHeader.tsx+++ b/web/apps/photos/src/components/Collections/GalleryBarAndListHeader.tsx@@ -25,11 +25,14 @@ import {GalleryItemsSummary,} from "ente-new/photos/components/gallery/ListHeader";import {+ collectionsSortBy,PseudoCollectionID,sortCollectionSummaries,+ type CollectionsSortBy,type CollectionSummaries,} from "ente-new/photos/services/collection-summary";import type { Person } from "ente-new/photos/services/ml/people";+import { includes } from "ente-utils/type-guards";import React, { useCallback, useEffect, useMemo, useState } from "react";import { AlbumCastDialog } from "./AlbumCastDialog";import {@@ -41,9 +44,12 @@ export type GalleryBarAndListHeaderProps = Omit<GalleryBarImplProps,| "collectionSummaries"| "onSelectCollectionID"+ | "collectionsSortBy"+ | "onChangeCollectionsSortBy"| "onShowAllAlbums"| "onShowAllPeople"> & {+ onCollectionsSortByChange: (by: CollectionsSortBy) => void;shouldHide: boolean;barCollectionSummaries: CollectionSummaries;allPeople: Person[];@@ -84,8 +90,7 @@ export const GalleryBarAndListHeader: React.FC<people,peopleSortBy,onChangePeopleSortBy,- collectionsSortBy,- onChangeCollectionsSortBy,+ onCollectionsSortByChange,albumFilter,albumSearchQuery,onAlbumSearchQueryChange,@@ -133,6 +138,13 @@ export const GalleryBarAndListHeader: React.FC<collectionShareVisibilityProps.onClose();}, [collectionShareVisibilityProps]);+ const [collectionsSortBy, setCollectionsSortBy] =+ useCollectionsSortByLocalState("updation-time-desc");++ useEffect(() => {+ onCollectionsSortByChange(collectionsSortBy);+ }, [collectionsSortBy, onCollectionsSortByChange]);+const sortedCollectionSummaries = useMemo(() =>sortCollectionSummaries(@@ -275,7 +287,7 @@ export const GalleryBarAndListHeader: React.FC<}}onSelectCollectionID={selectCollection}onSelectPerson={selectPerson}- onChangeCollectionsSortBy={onChangeCollectionsSortBy}+ onChangeCollectionsSortBy={setCollectionsSortBy}onChangePeopleSortBy={onChangePeopleSortBy}onShowAllAlbums={showAllAlbums}onShowAllPeople={showAllPeople}@@ -299,7 +311,7 @@ export const GalleryBarAndListHeader: React.FC<(cs) => !cs.attributes.has("system"),)}onSelectCollectionID={selectCollection}- onChangeCollectionsSortBy={onChangeCollectionsSortBy}+ onChangeCollectionsSortBy={setCollectionsSortBy}collectionsSortBy={collectionsSortBy}isInHiddenSection={mode == "hidden-albums"}isInArchiveSection={mode == "archive-albums"}@@ -341,3 +353,21 @@ export const GalleryBarAndListHeader: React.FC<</>);};++const useCollectionsSortByLocalState = (initialValue: CollectionsSortBy) => {+ const key = "collectionsSortBy";++ const [value, setValue] = useState(initialValue);++ useEffect(() => {+ const value = localStorage.getItem(key);+ if (value && includes(collectionsSortBy, value)) setValue(value);+ }, []);++ const setter = (value: CollectionsSortBy) => {+ localStorage.setItem(key, value);+ setValue(value);+ };++ return [value, setter] as const;+};diff --git a/web/apps/photos/src/pages/gallery.tsx b/web/apps/photos/src/pages/gallery.tsxindex 0bfdbed9d0..6740cdc06b 100644--- a/web/apps/photos/src/pages/gallery.tsx+++ b/web/apps/photos/src/pages/gallery.tsx@@ -66,7 +66,6 @@ import {type AlbumFilter,} from "@/utils/album-filters";import type { PeopleSortBy } from "@/utils/people-sort";-import { useCollectionsSortByLocalState } from "@/utils/use-collections-sort";import CheckCircleIcon from "@mui/icons-material/CheckCircle";import { Link, Typography } from "@mui/material";import { sessionExpiredDialogAttributes } from "ente-accounts/components/utils/dialog";@@ -132,6 +131,7 @@ import {haveOnlySystemCollections,PseudoCollectionID,sortCollectionSummaries,+ type CollectionsSortBy,} from "ente-new/photos/services/collection-summary";import {updateFilesLocation,@@ -225,7 +225,7 @@ const Page: React.FC = () => {const [albumFilter, setAlbumFilter] = useState<AlbumFilter>("ente");const [albumSearchQuery, setAlbumSearchQuery] = useState("");const [collectionsSortBy, setCollectionsSortBy] =- useCollectionsSortByLocalState("updation-time-desc");+ useState<CollectionsSortBy>("updation-time-desc");const createForAlbumOverview = useRef(false);const [blockingLoad, setBlockingLoad] = useState(false);const [peopleSortBy, setPeopleSortBy] =@@ -2126,8 +2126,7 @@ const Page: React.FC = () => {albumSearchQuery,onAlbumSearchQueryChange: setAlbumSearchQuery,onShowAlbumOverview: handleShowAlbumOverview,- collectionsSortBy,- onChangeCollectionsSortBy: setCollectionsSortBy,+ onCollectionsSortByChange: setCollectionsSortBy,peopleSortBy,onChangePeopleSortBy: setPeopleSortBy,setFileListHeader,diff --git a/web/apps/photos/src/utils/use-collections-sort.ts b/web/apps/photos/src/utils/use-collections-sort.tsdeleted file mode 100644index fb0d2bac3e..0000000000--- a/web/apps/photos/src/utils/use-collections-sort.ts+++ /dev/null@@ -1,26 +0,0 @@-import {- collectionsSortBy,- type CollectionsSortBy,-} from "ente-new/photos/services/collection-summary";-import { includes } from "ente-utils/type-guards";-import { useEffect, useState } from "react";--export const useCollectionsSortByLocalState = (- initialValue: CollectionsSortBy,-) => {- const key = "collectionsSortBy";-- const [value, setValue] = useState(initialValue);-- useEffect(() => {- const value = localStorage.getItem(key);- if (value && includes(collectionsSortBy, value)) setValue(value);- }, []);-- const setter = (value: CollectionsSortBy) => {- localStorage.setItem(key, value);- setValue(value);- };-- return [value, setter] as const;-};