From 356be25a685345840f795b5f042535c588188435 Mon Sep 17 00:00:00 2001 From: jatingodnani Date: Thu, 16 Nov 2023 00:47:30 +0530 Subject: [PATCH] change --- pages/search.js | 66 ++++++++++++++++++++++++------------------------- 1 file changed, 32 insertions(+), 34 deletions(-) diff --git a/pages/search.js b/pages/search.js index a4bf8f2804b..6d0d7a37fa1 100755 --- a/pages/search.js +++ b/pages/search.js @@ -18,7 +18,6 @@ import { import { PROJECT_NAME } from "@constants/index"; async function fetchUsersByKeyword(keyword) { - const res = await fetch( `${process.env.NEXT_PUBLIC_BASE_URL}/api/search?${new URLSearchParams({ slug: keyword, @@ -77,7 +76,9 @@ export default function Search({ const { username, keyword, userSearchParam } = router.query; const [notFound, setNotFound] = useState(); const [loading, setLoading] = useState(false); - const [users, setUsers] = useState(keyword ? filteredUsers : recentlyUpdatedUsers); + const [users, setUsers] = useState( + keyword ? filteredUsers : recentlyUpdatedUsers, + ); const [inputValue, setInputValue] = useState( username || keyword || userSearchParam || "", ); @@ -119,7 +120,7 @@ export default function Search({ if (keyword && inputValue === keyword) { return; } - + setLoading(true); const timer = setTimeout(() => { @@ -134,13 +135,11 @@ export default function Search({ fetchUsers(inputValue); }, 500); console.log(inputValue); - return () => {clearTimeout(timer) - + return () => { + clearTimeout(timer); }; - }, [inputValue]); async function fetchUsers(value) { - try { setLoading(true); const res = await fetch( @@ -159,7 +158,7 @@ export default function Search({ } catch (err) { setNotFound(err.message); setUsers([]); - }finally { + } finally { setLoading(false); } } @@ -204,7 +203,6 @@ export default function Search({ const indexOfFirstUser = indexOfLastUser - usersPerPage; const visibleUsers = users.slice(indexOfFirstUser, indexOfLastUser); - const paginate = useCallback((pageNumber) => { setCurrentPage(pageNumber); window.scrollTo({ top: 150, behavior: "smooth" }); @@ -249,39 +247,39 @@ export default function Search({ /> - {!inputValue &&

Recently updated profiles

} + {!inputValue && ( +

+ Recently updated profiles +

+ )} {notFound && } - { - loading &&( -
- -
-
- ) - } + {loading && ( +
+
+
+ )} {users.length > usersPerPage && (