Skip to content

armgit / ente

Public Imported from GitHub
0

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

fix(gallery):use-onExited

Aswin Asok69a3381f75fc
diff --git a/web/apps/photos/src/pages/gallery.tsx b/web/apps/photos/src/pages/gallery.tsx
index 7d94f300a6..e6b64a041d 100644
--- a/web/apps/photos/src/pages/gallery.tsx
+++ b/web/apps/photos/src/pages/gallery.tsx
@@ -1906,6 +1906,10 @@ const Page: React.FC = () => {
() => setOpenCollectionSelector(false),
[],
);
+ const handleCollectionSelectorExited = useCallback(
+ () => setCollectionSelectorAttributes(undefined),
+ [],
+ );
/**
* Handles adding a single file to a collection by opening a collection selector dialog.
@@ -2019,6 +2023,7 @@ const Page: React.FC = () => {
<CollectionSelector
open={openCollectionSelector}
onClose={handleCloseCollectionSelector}
+ onExited={handleCollectionSelectorExited}
attributes={collectionSelectorAttributes}
collectionSummaries={
collectionSelectorAttributes?.showHiddenCollections
diff --git a/web/packages/new/photos/components/CollectionSelector.tsx b/web/packages/new/photos/components/CollectionSelector.tsx
index 1f2d1a6932..da8d193d87 100644
--- a/web/packages/new/photos/components/CollectionSelector.tsx
+++ b/web/packages/new/photos/components/CollectionSelector.tsx
@@ -37,7 +37,13 @@ import {
} from "ente-new/photos/services/collection-summary";
import { includes } from "ente-utils/type-guards";
import { t } from "i18next";
-import React, { useEffect, useMemo, useRef, useState } from "react";
+import React, {
+ useCallback,
+ useEffect,
+ useMemo,
+ useRef,
+ useState,
+} from "react";
export type CollectionSelectorAction =
| "upload"
@@ -91,6 +97,8 @@ export interface CollectionSelectorAttributes {
}
type CollectionSelectorProps = ModalVisibilityProps & {
+ /** Callback fired after the selector has finished closing. */
+ onExited?: () => void;
/**
* The same {@link CollectionSelector} can be used for different
* purposes by customizing the {@link attributes} prop before opening it.
@@ -134,6 +142,7 @@ type CollectionSelectorProps = ModalVisibilityProps & {
export const CollectionSelector: React.FC<CollectionSelectorProps> = ({
open,
onClose,
+ onExited,
attributes,
collectionSummaries,
collectionForCollectionSummaryID,
@@ -149,9 +158,10 @@ export const CollectionSelector: React.FC<CollectionSelectorProps> = ({
CollectionSummary[]
>([]);
- const handleExited = () => {
+ const handleExited = useCallback(() => {
setSearchTerm("");
- };
+ onExited?.();
+ }, [onExited]);
useEffect(() => {
if (!attributes || !open) {
@@ -201,10 +211,11 @@ export const CollectionSelector: React.FC<CollectionSelectorProps> = ({
if (collections.length === 0) {
onClose();
attributes.onCreateCollection();
+ handleExited();
}
setFilteredCollections(collections);
- }, [collectionSummaries, attributes, open, onClose, sortBy]);
+ }, [collectionSummaries, attributes, open, onClose, sortBy, handleExited]);
const searchFilteredCollections = useMemo(() => {
if (!searchTerm.trim()) {