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

View file

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