Skip to content

armgit / ente

Public Imported from GitHub
0

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

Lints + usecb to prevent unnecessary rerenders after adding onClose as dep

Manav Rathi29ae5bfb09e5
diff --git a/web/apps/photos/src/pages/gallery.tsx b/web/apps/photos/src/pages/gallery.tsx
index b7cf163de6..34b004ce9f 100644
--- a/web/apps/photos/src/pages/gallery.tsx
+++ b/web/apps/photos/src/pages/gallery.tsx
@@ -96,6 +96,7 @@ import { useRouter } from "next/router";
import { AppContext } from "pages/_app";
import {
createContext,
+ useCallback,
useContext,
useEffect,
useMemo,
@@ -1105,17 +1106,23 @@ export default function Gallery() {
setBarMode("people");
};
+ const handleOpenCollectionSelector = useCallback(
+ (attributes: CollectionSelectorAttributes) => {
+ setCollectionSelectorAttributes(attributes);
+ setOpenCollectionSelector(true);
+ },
+ [],
+ );
+
+ const handleCloseCollectionSelector = useCallback(
+ () => setOpenCollectionSelector(false),
+ [],
+ );
+
if (!collectionSummaries || !filteredData) {
return <div></div>;
}
- const handleOpenCollectionSelector = (
- attributes: CollectionSelectorAttributes,
- ) => {
- setCollectionSelectorAttributes(attributes);
- setOpenCollectionSelector(true);
- };
-
// `people` will be undefined only when ML is disabled, otherwise it'll be
// an empty array (even if people are loading).
const showPeopleSectionButton = people !== undefined;
@@ -1174,7 +1181,7 @@ export default function Gallery() {
/>
<CollectionSelector
open={openCollectionSelector}
- onClose={() => setOpenCollectionSelector(false)}
+ onClose={handleCloseCollectionSelector}
attributes={collectionSelectorAttributes}
collectionSummaries={collectionSummaries}
collectionForCollectionID={(id) =>
@@ -1249,9 +1256,7 @@ export default function Gallery() {
false,
)}
onOpenCollectionSelector={handleOpenCollectionSelector}
- onCloseCollectionSelector={() =>
- setOpenCollectionSelector(false)
- }
+ onCloseCollectionSelector={handleCloseCollectionSelector}
setLoading={setBlockingLoad}
setCollectionNamerAttributes={setCollectionNamerAttributes}
setShouldDisableDropzone={setShouldDisableDropzone}
diff --git a/web/packages/new/photos/components/CollectionSelector.tsx b/web/packages/new/photos/components/CollectionSelector.tsx
index 978639011a..757973a771 100644
--- a/web/packages/new/photos/components/CollectionSelector.tsx
+++ b/web/packages/new/photos/components/CollectionSelector.tsx
@@ -1,5 +1,3 @@
-// TODO
-/* eslint-disable @typescript-eslint/no-non-null-assertion */
import type { Collection } from "@/media/collection";
import {
AllCollectionTile,
@@ -14,6 +12,7 @@ import {
type CollectionSummaries,
type CollectionSummary,
} from "@/new/photos/services/collection/ui";
+import { ensure } from "@/utils/ensure";
import { FlexWrapper } from "@ente/shared/components/Container";
import DialogTitleWithCloseButton from "@ente/shared/components/DialogBox/TitleWithCloseButton";
import {
@@ -126,8 +125,8 @@ export const CollectionSelector: React.FC<CollectionSelectorProps> = ({
})
.sort((a, b) => {
return (
- CollectionSummaryOrder.get(a.type)! -
- CollectionSummaryOrder.get(b.type)!
+ ensure(CollectionSummaryOrder.get(a.type)) -
+ ensure(CollectionSummaryOrder.get(b.type))
);
});
@@ -137,8 +136,7 @@ export const CollectionSelector: React.FC<CollectionSelectorProps> = ({
}
setFilteredCollections(collections);
- // eslint-disable-next-line react-hooks/exhaustive-deps
- }, [collectionSummaries, attributes, open]);
+ }, [collectionSummaries, attributes, open, onClose]);
if (!filteredCollections.length) {
return <></>;