From 684769a485102375647732fde496941ce5d6865a Mon Sep 17 00:00:00 2001 From: Mallepally Lokeshwar Reddy Date: Thu, 22 Aug 2024 20:01:38 +0530 Subject: [PATCH] Add search functionality --- src/App.jsx | 3 +- .../NavBar/new/MainNavbar/index.jsx | 28 +++- .../NavBar/new/MiniNavbar/index.jsx | 19 ++- .../BaseTutorialsComponent/TutorialCard.jsx | 2 +- .../Search/SearchResultsComponent.jsx | 131 ++++++++++++++++-- .../Tutorials/MyTutorials/Search/index.jsx | 5 +- src/helpers/elasticlunr.jsx | 32 ++++- src/routes.jsx | 2 + src/store/actions/index.js | 3 +- src/store/actions/tutorialsActions.js | 20 ++- 10 files changed, 219 insertions(+), 26 deletions(-) diff --git a/src/App.jsx b/src/App.jsx index 4a9c86f6..3d0c1c8a 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -3,7 +3,7 @@ import Routes from "./routes"; import "./App.less"; import { useFirebase, useFirestore } from "react-redux-firebase"; import { useDispatch, useSelector } from "react-redux"; -import { getProfileData } from "./store/actions"; +import { getProfileData, fetchAndIndexTutorials } from "./store/actions"; const App = () => { const firebase = useFirebase(); @@ -19,6 +19,7 @@ const App = () => { useEffect(() => { getProfileData(organizations)(firebase, firestore, dispatch); + fetchAndIndexTutorials()(firebase, firestore, dispatch); }, [organizations, firebase, dispatch]); return ; }; diff --git a/src/components/NavBar/new/MainNavbar/index.jsx b/src/components/NavBar/new/MainNavbar/index.jsx index 9fc3b490..dd2568fa 100644 --- a/src/components/NavBar/new/MainNavbar/index.jsx +++ b/src/components/NavBar/new/MainNavbar/index.jsx @@ -61,6 +61,7 @@ function MainNavbar() { const windowSize = useWindowSize(); const [openDrawer, setOpenDrawer] = useState(false); const [openMenu, setOpen] = useState(false); + const [searchQuery, setSearchQuery] = useState(""); const toggleSlider = () => { setOpen(!openMenu); }; @@ -70,6 +71,16 @@ function MainNavbar() { const notificationCount = notifications?.filter( notification => !notification.isRead ).length; + const handleSearchChange = e => { + setSearchQuery(e.target.value); + }; + const handleSearch = e => { + e.preventDefault(); + if (searchQuery.length > 0) { + history.push(`/search?query=${searchQuery}`); + } + }; + return (