Skip to content
This repository has been archived by the owner on Aug 7, 2024. It is now read-only.

Commit

Permalink
feat: clear all tags in one click button on search page (#10032)
Browse files Browse the repository at this point in the history
* feat: search page clear all tags button added

* fix : clear button to remove complete search text

* fix : replace function in handleClearFunction executes only when user have searched something

* fix: replaced our button component :D
  • Loading branch information
futoid authored Jun 8, 2024
1 parent c127e2f commit 70d0a3c
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion pages/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,6 @@ export default function Search({
if (!userSearchParam) {
params.set("query", tagName);
}

if (userSearchParam) {
if (searchTagNameInInput(userSearchParam, tagName)) {
const terms = userSearchParam.split(",");
Expand All @@ -203,6 +202,24 @@ export default function Search({
);
};

const handleClearFilter = () => {
const params = new URLSearchParams({ query: searchTerm });
params.forEach((userSearchQueries) => {
if (userSearchQueries !== "undefined") {
replace(
{
pathname,
query: {
userSearchParam: {},
},
},
undefined,
{ shallow: true },
);
}
});
};

const usersPerPage = 21;
const indexOfLastUser = currentPage * usersPerPage;
const indexOfFirstUser = indexOfLastUser - usersPerPage;
Expand Down Expand Up @@ -237,6 +254,16 @@ export default function Search({
onClick={() => handleSearchTag(tag.name)}
/>
))}

<Button
overrideClassNames={true}
className="
flex flex-row p-1 m-2 rounded-lg text-sm text-black font-mono border-2 border-tertiary-medium
bg-tertiary-medium cursor-pointer shadow-none"
onClick={handleClearFilter}
>
clear
</Button>
</div>

<Badge
Expand Down

0 comments on commit 70d0a3c

Please sign in to comment.