소스 검색

search-bar component added

daviddeepan 1 년 전
부모
커밋
4ed194f397
1개의 변경된 파일33개의 추가작업 그리고 5개의 파일을 삭제
  1. 33 5
      web/apps/photos/src/components/Collections/CollectionSelector/index.tsx

+ 33 - 5
web/apps/photos/src/components/Collections/CollectionSelector/index.tsx

@@ -39,6 +39,7 @@ interface Props {
     collections: Collection[];
     collections: Collection[];
     collectionSummaries: CollectionSummaries;
     collectionSummaries: CollectionSummaries;
 }
 }
+
 function CollectionSelector({
 function CollectionSelector({
     attributes,
     attributes,
     collectionSummaries,
     collectionSummaries,
@@ -46,7 +47,7 @@ function CollectionSelector({
     ...props
     ...props
 }: Props) {
 }: Props) {
     const appContext = useContext(AppContext);
     const appContext = useContext(AppContext);
-
+    const [searchQuery, setSearchQuery] = useState("");
     const [collectionsToShow, setCollectionsToShow] = useState<
     const [collectionsToShow, setCollectionsToShow] = useState<
         CollectionSummary[]
         CollectionSummary[]
     >([]);
     >([]);
@@ -81,6 +82,7 @@ function CollectionSelector({
                         return isMoveToAllowedCollection(type);
                         return isMoveToAllowedCollection(type);
                     }
                     }
                 })
                 })
+
                 .sort((a, b) => {
                 .sort((a, b) => {
                     return a.name.localeCompare(b.name);
                     return a.name.localeCompare(b.name);
                 })
                 })
@@ -89,15 +91,24 @@ function CollectionSelector({
                         COLLECTION_SORT_ORDER.get(a.type) -
                         COLLECTION_SORT_ORDER.get(a.type) -
                         COLLECTION_SORT_ORDER.get(b.type)
                         COLLECTION_SORT_ORDER.get(b.type)
                     );
                     );
-                });
+                })
+                .filter((collection) =>
+                    collection.name
+                        .toLowerCase()
+                        .includes(searchQuery.toLowerCase()),
+                );
             if (collectionsToShow.length === 0) {
             if (collectionsToShow.length === 0) {
-                props.onClose();
-                attributes.showNextModal();
+                if (searchQuery !== "") {
+                    return console.log("No Albums with that name...");
+                } else {
+                    props.onClose();
+                    attributes.showNextModal();
+                }
             }
             }
             setCollectionsToShow(collectionsToShow);
             setCollectionsToShow(collectionsToShow);
         };
         };
         main();
         main();
-    }, [collectionSummaries, attributes, props.open]);
+    }, [collectionSummaries, attributes, props.open, searchQuery]);
 
 
     if (!collectionsToShow?.length) {
     if (!collectionsToShow?.length) {
         return <></>;
         return <></>;
@@ -121,6 +132,12 @@ function CollectionSelector({
         props.onClose();
         props.onClose();
     };
     };
 
 
+    const handleSearchInputChange = (e) => {
+        if (e) {
+            setSearchQuery(e.target.value);
+        } else console.log("No collections to show.....");
+    };
+
     return (
     return (
         <AllCollectionDialog
         <AllCollectionDialog
             onClose={onUserTriggeredClose}
             onClose={onUserTriggeredClose}
@@ -142,6 +159,17 @@ function CollectionSelector({
                             ? t("UNHIDE_TO_COLLECTION")
                             ? t("UNHIDE_TO_COLLECTION")
                             : t("SELECT_COLLECTION")}
                             : t("SELECT_COLLECTION")}
             </DialogTitleWithCloseButton>
             </DialogTitleWithCloseButton>
+            <input
+                style={{
+                    height: "50px",
+                    fontSize: "16px",
+                    borderRadius: "10px",
+                    margin: "10px",
+                }}
+                placeholder="Search Albums..."
+                value={searchQuery}
+                onChange={handleSearchInputChange}
+            />
             <DialogContent sx={{ "&&&": { padding: 0 } }}>
             <DialogContent sx={{ "&&&": { padding: 0 } }}>
                 <FlexWrapper flexWrap="wrap" gap={"4px"} padding={"16px"}>
                 <FlexWrapper flexWrap="wrap" gap={"4px"} padding={"16px"}>
                     <AddCollectionButton
                     <AddCollectionButton