Skip to content

Commit

Permalink
Fix search after update
Browse files Browse the repository at this point in the history
  • Loading branch information
devgg committed Apr 5, 2024
1 parent 8a4229c commit 45aa8a4
Showing 1 changed file with 4 additions and 19 deletions.
23 changes: 4 additions & 19 deletions src/js/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,35 +22,20 @@ function initSearch() {
const query = $search.get(0).value;
const result = fuse.search(query);

const map = new Map(result.map((obj, idx) => [obj.item.ix, idx]));

let $childrenToShow = $right.children();
if (query !== '') {
$childrenToShow.css('display', 'none');
$childrenToShow = $right.children().filter((index, element) => {
return (
result.indexOf(
$(element)
.data('ix')
.toString(),
) !== -1
);
return map.has($(element).data('ix'));
});
$childrenToShow.css('display', 'flex');

if ($childrenToShow.length > 0) {
tinysort($childrenToShow, {
sortFunction: (a, b) => {
return (
result.indexOf(
$(a.elm)
.data('ix')
.toString(),
) -
result.indexOf(
$(b.elm)
.data('ix')
.toString(),
)
);
return map.get($(a.elem).data('ix')) - map.get($(b.elem).data('ix'));
},
});
}
Expand Down

0 comments on commit 45aa8a4

Please sign in to comment.