소스 검색

feat module 1,2,4 : modified search bar result based on menu at navbar - search bar

master
nadia 4 일 전
부모
커밋
a334300038
3개의 변경된 파일108개의 추가작업 그리고 4개의 파일을 삭제
  1. 5
    3
      src/components/Navbar/Navbar.jsx
  2. 44
    1
      src/components/SearchProduct/SearchProduct.jsx
  3. 59
    0
      src/config/menuCollections.js

+ 5
- 3
src/components/Navbar/Navbar.jsx 파일 보기

29
 
29
 
30
 import ChevronLeftIcon from '@mui/icons-material/ChevronLeft';
30
 import ChevronLeftIcon from '@mui/icons-material/ChevronLeft';
31
 import KeyboardArrowRightIcon from '@mui/icons-material/KeyboardArrowRight';
31
 import KeyboardArrowRightIcon from '@mui/icons-material/KeyboardArrowRight';
32
+import { NAV_MENU_STRUCTURE as SHARED_NAV_MENU_STRUCTURE } from "../../config/menuCollections";
32
 
33
 
33
 function calculateTotalQuantity(cartItems) {
34
 function calculateTotalQuantity(cartItems) {
34
   return cartItems.reduce((total, item) => total + item.quantity, 0);
35
   return cartItems.reduce((total, item) => total + item.quantity, 0);
89
   return normalizeTitle(productType) === "BEAUTY" ? "Essentials" : productType;
90
   return normalizeTitle(productType) === "BEAUTY" ? "Essentials" : productType;
90
 };
91
 };
91
 
92
 
93
+const NAV_MENU_STRUCTURE = SHARED_NAV_MENU_STRUCTURE;
94
+
95
+/*
92
 const NAV_MENU_STRUCTURE = [
96
 const NAV_MENU_STRUCTURE = [
93
   {
97
   {
94
     productType: "Apparel",
98
     productType: "Apparel",
97
       {
101
       {
98
         label: "Casual",
102
         label: "Casual",
99
         children: [
103
         children: [
100
-          // Local Shopify collection title is "DENIM ND X MARII FOR AMBER"; old/reference title: "ND X MARII FOR AMBER".
101
           { label: "ND X Marii for Amber", titles: ["DENIM ND X MARII FOR AMBER", "ND X MARII FOR AMBER"] },
104
           { label: "ND X Marii for Amber", titles: ["DENIM ND X MARII FOR AMBER", "ND X MARII FOR AMBER"] },
102
           { label: "Somewhere Somehow Someone", titles: ["SOMEWHERE SOMEHOW SOMEONE"] },
105
           { label: "Somewhere Somehow Someone", titles: ["SOMEWHERE SOMEHOW SOMEONE"] },
103
           { label: "Flower Power", titles: ["FLOWER POWER"] },
106
           { label: "Flower Power", titles: ["FLOWER POWER"] },
106
       {
109
       {
107
         label: "Traditional",
110
         label: "Traditional",
108
         children: [
111
         children: [
109
-          // label is the display name, titles are the collection names that will be matched to the product collections in shopify
110
           { label: "Eid's Time For Love", titles: ["EID'S TIME FOR LOVE"] },
112
           { label: "Eid's Time For Love", titles: ["EID'S TIME FOR LOVE"] },
111
-          // Local Shopify collection title is "RAYA ROMANTICS"; old/reference title: "RAYA ROMANTICS COLLECTION 2025".
112
           { label: "Raya Romantics", titles: ["RAYA ROMANTICS", "RAYA ROMANTICS COLLECTION 2025"] },
113
           { label: "Raya Romantics", titles: ["RAYA ROMANTICS", "RAYA ROMANTICS COLLECTION 2025"] },
113
           { label: "Atma Sari", titles: ["ATMA SARI"] },
114
           { label: "Atma Sari", titles: ["ATMA SARI"] },
114
           { label: "Oasis abaya", titles: ["OASIS ABAYA COLLECTION", "MIRAGE COLLECTION"] },
115
           { label: "Oasis abaya", titles: ["OASIS ABAYA COLLECTION", "MIRAGE COLLECTION"] },
125
     ],
126
     ],
126
   },
127
   },
127
 ];
128
 ];
129
+*/
128
 
130
 
129
 const sortCollectionsByPriority = (collection = [], productType = "") => {
131
 const sortCollectionsByPriority = (collection = [], productType = "") => {
130
   const typeKey = (productType || "").trim().toLowerCase();
132
   const typeKey = (productType || "").trim().toLowerCase();

+ 44
- 1
src/components/SearchProduct/SearchProduct.jsx 파일 보기

11
   CardMedia,
11
   CardMedia,
12
 } from "@mui/material";
12
 } from "@mui/material";
13
 import { useSelector } from "react-redux";
13
 import { useSelector } from "react-redux";
14
+import { getMenuCollectionTitlesByProductType } from "../../config/menuCollections";
14
 
15
 
15
 function doesSubstringExistInArray(array, substring) {
16
 function doesSubstringExistInArray(array, substring) {
16
     
17
     
22
     return array.some(element => element.toLowerCase().includes(lowerCaseSubstring));
23
     return array.some(element => element.toLowerCase().includes(lowerCaseSubstring));
23
 }
24
 }
24
 
25
 
26
+// Define allowed search collections for each product type
27
+const allowedSearchCollectionsByProductType = getMenuCollectionTitlesByProductType();
28
+
29
+/*
30
+Old standalone search allow-list. Current code uses src/config/menuCollections.js
31
+so search results automatically follow the navbar menu.
32
+
33
+const allowedSearchCollectionsByProductType = {
34
+  Apparel: [
35
+    "DENIM ND X MARII FOR AMBER",
36
+    "ND X MARII FOR AMBER",
37
+    "SOMEWHERE SOMEHOW SOMEONE",
38
+    "FLOWER POWER",
39
+    "EID'S TIME FOR LOVE",
40
+    "RAYA ROMANTICS",
41
+    "RAYA ROMANTICS COLLECTION 2025",
42
+    "ATMA SARI",
43
+    "OASIS ABAYA COLLECTION",
44
+    "MIRAGE COLLECTION",
45
+  ],
46
+  BEAUTY: [
47
+    "COSMETICS",
48
+    "HAND & BODY LOTION",
49
+  ],
50
+};
51
+*/
52
+
53
+const normalizeTitle = (value = "") => value.trim().toUpperCase();
54
+
55
+const isProductAllowedInSearch = (product) => {
56
+  const allowedCollections = allowedSearchCollectionsByProductType[product?.productType];
57
+
58
+  if (!allowedCollections) return false;
59
+
60
+  const allowedCollectionSet = new Set(allowedCollections.map(normalizeTitle));
61
+
62
+  return product?.collections?.some((collection) =>
63
+    allowedCollectionSet.has(normalizeTitle(collection?.title || ""))
64
+  );
65
+}
66
+
25
 const SearchProduct = ({ onClose }) => {
67
 const SearchProduct = ({ onClose }) => {
26
   const products = useSelector((state) => state.products.products.data);
68
   const products = useSelector((state) => state.products.products.data);
27
   const [searchedProducts, setSearchedProducts] = useState([]);
69
   const [searchedProducts, setSearchedProducts] = useState([]);
31
 
73
 
32
     if(searchQuery?.length < 2) return
74
     if(searchQuery?.length < 2) return
33
 
75
 
34
-    let filteredProducts = products.filter((product) => {
76
+      // let filteredProducts = products.filter((product) => {
77
+      let filteredProducts = products.filter(isProductAllowedInSearch).filter((product) => {
35
 
78
 
36
       let title = product?.title?.toLowerCase();
79
       let title = product?.title?.toLowerCase();
37
       let search = searchQuery.toLowerCase();
80
       let search = searchQuery.toLowerCase();

+ 59
- 0
src/config/menuCollections.js 파일 보기

1
+export const NAV_MENU_STRUCTURE = [
2
+  {
3
+    productType: "Apparel",
4
+    label: "APPAREL",
5
+    groups: [
6
+      {
7
+        label: "Casual",
8
+        children: [
9
+          { label: "ND X Marii for Amber", titles: ["DENIM ND X MARII FOR AMBER", "ND X MARII FOR AMBER"] },
10
+          { label: "Somewhere Somehow Someone", titles: ["SOMEWHERE SOMEHOW SOMEONE"] },
11
+          { label: "Flower Power", titles: ["FLOWER POWER"] },
12
+        ],
13
+      },
14
+      {
15
+        label: "Traditional",
16
+        children: [
17
+          // label is the display name, titles are the collection names that will be matched to the product collections in shopify
18
+          { label: "Eid's Time For Love", titles: ["EID'S TIME FOR LOVE"] },
19
+          { label: "Raya Romantics", titles: ["RAYA ROMANTICS", "RAYA ROMANTICS COLLECTION 2025"] },
20
+          { label: "Atma Sari", titles: ["ATMA SARI"] },
21
+          { label: "Oasis abaya", titles: ["OASIS ABAYA COLLECTION", "MIRAGE COLLECTION"] },
22
+        ],
23
+      },
24
+    ],
25
+  },
26
+  {
27
+    productType: "BEAUTY",
28
+    label: "Essentials",
29
+    children: [
30
+      { label: "Cosmetics", titles: ["COSMETICS"] },
31
+      { label: "Hand & Body Lotion", titles: ["HAND & BODY LOTION"] },
32
+    ],
33
+  },
34
+];
35
+
36
+export const getMenuCollectionTitlesByProductType = () => {
37
+  return NAV_MENU_STRUCTURE.reduce((allowedCollections, menu) => {
38
+    const titles = [];
39
+
40
+    if (menu.groups) {
41
+      menu.groups.forEach((group) => {
42
+        group.children.forEach((item) => {
43
+          titles.push(...(item.titles || []));
44
+        });
45
+      });
46
+    }
47
+
48
+    if (menu.children) {
49
+      menu.children.forEach((item) => {
50
+        titles.push(...(item.titles || []));
51
+      });
52
+    }
53
+
54
+    return {
55
+      ...allowedCollections,
56
+      [menu.productType]: titles,
57
+    };
58
+  }, {});
59
+};

Loading…
취소
저장