pages/search: enable fuzzy search

This commit is contained in:
He4eT 2024-01-21 00:18:23 +01:00
commit b7de8393a7
2 changed files with 7 additions and 7 deletions

View file

@ -1,4 +1,5 @@
import * as labels from './labels.js'
const fuzzysort = window.fuzzysort
export const init = ({
tabs: browserTabs,
@ -42,17 +43,15 @@ export const init = ({
browserTabs.query({ currentWindow: true, active: false })
.then(shapeTabs)
.then((tabs) => tabs.reverse())
.then((tabs) => {
void (state.tabs = tabs)
void (state.results = tabs)
})
.then((tabs) => void (state.tabs = tabs))
/* */
const updateResults = () => {
state.results = state.query.length === 0
? state.tabs
: []
state.results = fuzzysort.go(state.query, state.tabs, {
keys: ['label', 'title', 'url'],
all: true,
}).map(({obj}) => obj)
}
/* */

View file

@ -31,6 +31,7 @@
</div>
</button>
</main>
<script type="text/javascript" src="./vendor/fuzzysort.js"></script>
<script type='module' src='./search.js'></script>
</body>
</html>