Skip to content

armgit / ente

Public Imported from GitHub
0

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

wip: checkpoint

Manav Rathi627a53428a5b
diff --git a/web/apps/photos/src/components/Collections/AllCollections/index.tsx b/web/apps/photos/src/components/Collections/AllCollections/index.tsx
index 89aeb46568..363960db03 100644
--- a/web/apps/photos/src/components/Collections/AllCollections/index.tsx
+++ b/web/apps/photos/src/components/Collections/AllCollections/index.tsx
@@ -1,5 +1,5 @@
import type { CollectionSummary } from "@/new/photos/types/collection";
-import { CollectionListSortOrder } from "@/new/photos/types/collection";
+import { CollectionsSortBy } from "@/new/photos/types/collection";
import { Divider, useMediaQuery } from "@mui/material";
import {
AllCollectionDialog,
@@ -13,8 +13,8 @@ interface Iprops {
onClose: () => void;
collectionSummaries: CollectionSummary[];
setActiveCollectionID: (id?: number) => void;
- collectionListSortBy: CollectionListSortOrder;
- setCollectionListSortBy: (v: CollectionListSortOrder) => void;
+ collectionListSortBy: CollectionsSortBy;
+ setCollectionListSortBy: (v: CollectionsSortBy) => void;
isInHiddenSection: boolean;
}
diff --git a/web/apps/photos/src/components/Collections/CollectionListBar.tsx b/web/apps/photos/src/components/Collections/CollectionListBar.tsx
index 6ae04206d3..33fc85cd6a 100644
--- a/web/apps/photos/src/components/Collections/CollectionListBar.tsx
+++ b/web/apps/photos/src/components/Collections/CollectionListBar.tsx
@@ -2,9 +2,9 @@ import { useIsMobileWidth } from "@/base/hooks";
import { BarItemTile, ItemCard } from "@/new/photos/components/ItemCards";
import type { Person } from "@/new/photos/services/ml/cgroups";
import type {
- CollectionListSortOrder,
CollectionSummary,
CollectionSummaryType,
+ CollectionsSortBy,
} from "@/new/photos/types/collection";
import { ensure } from "@/utils/ensure";
import { IconButtonWithBG, Overlay } from "@ente/shared/components/Container";
@@ -65,11 +65,11 @@ export interface CollectionListBarProps {
* The sort order that should be used for showing the collections in the
* bar.
*/
- collectionListSortBy: CollectionListSortOrder;
+ collectionListSortBy: CollectionsSortBy;
/**
* Called when the user changes the sort order.
*/
- setCollectionListSortBy: (order: CollectionListSortOrder) => void;
+ setCollectionListSortBy: (order: CollectionsSortBy) => void;
/**
* The list of people that should be shown in the bar.
*/
diff --git a/web/apps/photos/src/components/Collections/CollectionListSortOptions.tsx b/web/apps/photos/src/components/Collections/CollectionListSortOptions.tsx
index 87062d4e1f..4479bcfde5 100644
--- a/web/apps/photos/src/components/Collections/CollectionListSortOptions.tsx
+++ b/web/apps/photos/src/components/Collections/CollectionListSortOptions.tsx
@@ -1,4 +1,4 @@
-import type { CollectionListSortOrder } from "@/new/photos/types/collection";
+import type { CollectionsSortBy } from "@/new/photos/types/collection";
import OverflowMenu from "@ente/shared/components/OverflowMenu/menu";
import { OverflowMenuOption } from "@ente/shared/components/OverflowMenu/option";
import TickIcon from "@mui/icons-material/Done";
@@ -7,8 +7,8 @@ import SvgIcon from "@mui/material/SvgIcon";
import { t } from "i18next";
interface CollectionListSortOptionsProps {
- setSortBy: (order: CollectionListSortOrder) => void;
- activeSortBy: CollectionListSortOrder;
+ setSortBy: (order: CollectionsSortBy) => void;
+ activeSortBy: CollectionsSortBy;
nestedInDialog?: boolean;
disableBG?: boolean;
}
@@ -49,7 +49,7 @@ export const CollectionListSortOptions: React.FC<
const SortByOptionCreator =
({ setSortBy, activeSortBy }: CollectionListSortOptionsProps) =>
- (props: { sortBy: CollectionListSortOrder; children: any }) => {
+ (props: { sortBy: CollectionsSortBy; children: any }) => {
const handleClick = () => {
setSortBy(props.sortBy);
};
diff --git a/web/apps/photos/src/components/Collections/index.tsx b/web/apps/photos/src/components/Collections/index.tsx
index ff77ff9d7d..17e012d58c 100644
--- a/web/apps/photos/src/components/Collections/index.tsx
+++ b/web/apps/photos/src/components/Collections/index.tsx
@@ -1,12 +1,11 @@
import type { Collection } from "@/media/collection";
import type { Person } from "@/new/photos/services/ml/cgroups";
import {
- collectionsSortOrders,
- type CollectionListSortOrder,
+ collectionsSortBy,
+ type CollectionsSortBy,
type CollectionSummaries,
} from "@/new/photos/types/collection";
import { includes } from "@/utils/type-guards";
-import { useLocalState } from "@ente/shared/hooks/useLocalState";
import {
getData,
LS_KEYS,
@@ -82,11 +81,8 @@ export const Collections: React.FC<CollectionsProps> = ({
useState(false);
const [openAlbumCastDialog, setOpenAlbumCastDialog] = useState(false);
- const [collectionListSortBy, setCollectionListSortBy] =
- useLocalState<CollectionListSortOrder>(
- LS_KEYS.COLLECTION_SORT_BY,
- "updation-time-desc",
- );
+ const [collectionsSortBy, setCollectionsSortBy] =
+ useCollectionsSortByLocalState("updation-time-desc");
const toShowCollectionSummaries = useMemo(
() =>
@@ -108,9 +104,9 @@ export const Collections: React.FC<CollectionsProps> = ({
() =>
sortCollectionSummaries(
[...toShowCollectionSummaries.values()],
- collectionListSortBy,
+ collectionsSortBy,
),
- [collectionListSortBy, toShowCollectionSummaries],
+ [collectionsSortBy, toShowCollectionSummaries],
);
const isActiveCollectionDownloadInProgress = useCallback(() => {
@@ -176,8 +172,8 @@ export const Collections: React.FC<CollectionsProps> = ({
people,
activePerson,
onSelectPerson,
- collectionListSortBy,
- setCollectionListSortBy,
+ collectionListSortBy: collectionsSortBy,
+ setCollectionListSortBy: setCollectionsSortBy,
}}
onShowAllCollections={() => setOpenAllCollectionDialog(true)}
collectionSummaries={sortedCollectionSummaries.filter((x) =>
@@ -192,8 +188,8 @@ export const Collections: React.FC<CollectionsProps> = ({
(x) => !isSystemCollection(x.type),
)}
setActiveCollectionID={setActiveCollectionID}
- setCollectionListSortBy={setCollectionListSortBy}
- collectionListSortBy={collectionListSortBy}
+ setCollectionListSortBy={setCollectionsSortBy}
+ collectionListSortBy={collectionsSortBy}
isInHiddenSection={mode == "hidden-albums"}
/>
<CollectionShare
@@ -217,28 +213,24 @@ export const Collections: React.FC<CollectionsProps> = ({
* A hook that maintains the collections sort order both as in-memory and local
* storage state.
*/
-const useCollectionsSortOrderLocalState = (
- initialValue: CollectionListSortOrder,
-) => {
- const key = "collectionsSortOrder";
+const useCollectionsSortByLocalState = (initialValue: CollectionsSortBy) => {
+ const key = "collectionsSortBy";
const [value, setValue] = useState(initialValue);
useEffect(() => {
- const sortOrder = localStorage.getItem(key);
- if (sortOrder) {
- if (includes(collectionsSortOrders, sortOrder)) {
- setValue(sortOrder);
- }
+ const value = localStorage.getItem(key);
+ if (value) {
+ if (includes(collectionsSortBy, value)) setValue(value);
} else {
- // Older versions of this code used to store in a different place.
- // Migrate it from there if it is found there.
+ // Older versions of this code used to store the value in a
+ // different place and format. Migrate if needed.
//
// This migration added Sep 2024, can be removed after a bit (esp
// since it effectively runs on each app start). (tag: Migration).
const oldData = getData(LS_KEYS.COLLECTION_SORT_BY);
if (oldData) {
- let newValue: CollectionListSortOrder | undefined;
+ let newValue: CollectionsSortBy | undefined;
switch (oldData.value) {
case 0:
newValue = "name";
@@ -259,7 +251,7 @@ const useCollectionsSortOrderLocalState = (
}
}, []);
- const setter = (value: CollectionListSortOrder) => {
+ const setter = (value: CollectionsSortBy) => {
localStorage.setItem(key, value);
setValue(value);
};
diff --git a/web/apps/photos/src/services/collectionService.ts b/web/apps/photos/src/services/collectionService.ts
index 7fd48e48d9..f5a8ba4785 100644
--- a/web/apps/photos/src/services/collectionService.ts
+++ b/web/apps/photos/src/services/collectionService.ts
@@ -25,7 +25,7 @@ import type {
CollectionSummary,
CollectionSummaryType,
} from "@/new/photos/types/collection";
-import { CollectionListSortOrder } from "@/new/photos/types/collection";
+import { CollectionsSortBy } from "@/new/photos/types/collection";
import { EnteFile } from "@/new/photos/types/file";
import {
EncryptedMagicMetadata,
@@ -1070,7 +1070,7 @@ export const getFavCollection = async () => {
export function sortCollectionSummaries(
collectionSummaries: CollectionSummary[],
- sortBy: CollectionListSortOrder,
+ sortBy: CollectionsSortBy,
) {
return collectionSummaries
.sort((a, b) => {
diff --git a/web/packages/new/photos/types/collection.ts b/web/packages/new/photos/types/collection.ts
index 83fddc265d..df061f5e6b 100644
--- a/web/packages/new/photos/types/collection.ts
+++ b/web/packages/new/photos/types/collection.ts
@@ -36,19 +36,19 @@ export interface CollectionSummary {
export type CollectionSummaries = Map<number, CollectionSummary>;
/**
- * The sort orders that can be used when we're showing list of collections (e.g.
- * in the collection bar).
+ * The sort schemes that can be used when we're showing list of collections
+ * (e.g. in the collection bar).
*
- * This is the list of all possible values, see {@link CollectionListSortOrder}
- * for the type.
+ * This is the list of all possible values, see {@link CollectionsSortBy} for
+ * the type.
*/
-export const collectionsSortOrders = [
+export const collectionsSortBy = [
"name",
"creation-time-asc",
"updation-time-desc",
] as const;
/**
- * Type of individual {@link collectionsSortOrders} values.
+ * Type of individual {@link collectionsSortBy} values.
*/
-export type CollectionListSortOrder = (typeof collectionsSortOrders)[number];
+export type CollectionsSortBy = (typeof collectionsSortBy)[number];
diff --git a/web/packages/shared/storage/localStorage/index.ts b/web/packages/shared/storage/localStorage/index.ts
index 156f466261..a90c1d838b 100644
--- a/web/packages/shared/storage/localStorage/index.ts
+++ b/web/packages/shared/storage/localStorage/index.ts
@@ -13,6 +13,7 @@ export enum LS_KEYS {
EXPORT = "export",
// LOGS = "logs",
USER_DETAILS = "userDetails",
+ // Migrated to (and only used by) useCollectionsSortByLocalState.
COLLECTION_SORT_BY = "collectionSortBy",
THEME = "theme",
// Moved to the new wrapper @/base/local-storage