Skip to content

Commit

Permalink
FIx search in examples
Browse files Browse the repository at this point in the history
  • Loading branch information
yashovardhan committed Dec 2, 2024
1 parent 136f5cc commit a8ef837
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 22 deletions.
18 changes: 7 additions & 11 deletions src/components/Examples/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,7 @@ export default function Examples(props: {
useEffect(() => {
function filterByTags() {
let examples;
if (searchInput.length === 0) {
examples = sortedExamples;
} else {
examples = searchFilteredExampleMap;
}
examples = sortedExamples;
examples = examples.filter((item) => {
const prodFil =
productFilter.length === 0 || productFilter.some((tag) => item.tags.includes(tag));
Expand All @@ -65,7 +61,7 @@ export default function Examples(props: {
const blockFil =
blockchainFilter.length === 0 || blockchainFilter.some((tag) => item.tags.includes(tag));

return [prodFil, platFil, blockFil].every((result) => result === true);
return [prodFil, platFil, blockFil].some((result) => result === true);
});
setTagFilteredExampleMap(examples);
}
Expand Down Expand Up @@ -119,14 +115,14 @@ export default function Examples(props: {
function onChangeSearch(input) {
setSearchInput(input);

const inputKeywords = input.trim().split(" ");
const inputKeywords = input.trim().split(" ").filter(Boolean);

function searchFilter(item) {
return (
inputKeywords.every((key) => item.title.toLowerCase().includes(key.toLowerCase())) ||
inputKeywords.every((key) => item.description.toLowerCase().includes(key.toLowerCase())) ||
inputKeywords.every((key) =>
item.tags.map((tag) => tag.includes(key.toLowerCase())).includes(true),
inputKeywords.some((key) => item.title.toLowerCase().includes(key.toLowerCase())) ||
inputKeywords.some((key) => item.description.toLowerCase().includes(key.toLowerCase())) ||
inputKeywords.some((key) =>
item.tags.map((tag) => tag.toLowerCase().includes(key.toLowerCase())),
)
);
}
Expand Down
18 changes: 7 additions & 11 deletions src/pages/guides/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,7 @@ export default function Guides({ content }: GuidesInterface) {
useEffect(() => {
function filterByTags() {
let guides;
if (searchInput.length === 0) {
guides = completeGuides;
} else {
guides = searchFilteredGuides;
}
guides = completeGuides;
console.log("productFilter", productFilter);
console.log("platformFilter", platformFilter);
console.log("tags", tags);
Expand All @@ -57,7 +53,7 @@ export default function Guides({ content }: GuidesInterface) {
const platFil =
platformFilter.length === 0 || platformFilter.some((tag) => item.tags.includes(tag));

return [prodFil, platFil].every((result) => result === true);
return [prodFil, platFil].some((result) => result === true);
});

setTagFilteredGuides(guides.sort((a: any, b: any) => a.order - b.order));
Expand Down Expand Up @@ -106,14 +102,14 @@ export default function Guides({ content }: GuidesInterface) {
function onChangeSearch(input) {
setSearchInput(input);

const inputKeywords = input.trim().split(" ");
const inputKeywords = input.trim().split(" ").filter(Boolean);

function searchFilter(item) {
return (
inputKeywords.every((key) => item.title.toLowerCase().includes(key.toLowerCase())) ||
inputKeywords.every((key) => item.description.toLowerCase().includes(key.toLowerCase())) ||
inputKeywords.every((key) =>
item.tags.map((tag) => tag.includes(key.toLowerCase())).includes(true),
inputKeywords.some((key) => item.title.toLowerCase().includes(key.toLowerCase())) ||
inputKeywords.some((key) => item.description.toLowerCase().includes(key.toLowerCase())) ||
inputKeywords.some((key) =>
item.tags.some((tag) => tag.toLowerCase().includes(key.toLowerCase())),
)
);
}
Expand Down

0 comments on commit a8ef837

Please sign in to comment.