Skip to content

Commit

Permalink
Set active nav item while searching
Browse files Browse the repository at this point in the history
  • Loading branch information
schiehll committed May 26, 2019
1 parent f02b674 commit c0167bf
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/components/layout/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,20 @@ const Layout = () => {

const handleSearch = e => {
const query = e.target.value
let activeId = '__DASHBOARD__'

if (!query) {
setKerbs(allKerbs.current)
} else {
const searchResults = fuse.current.search(query)
setKerbs(allKerbs.current.filter(kerb => searchResults.includes(kerb.id)))

if (searchResults.length === 1) {
activeId = searchResults[0]
}
}

setActiveItem(activeId)
}

useEffect(() => {
Expand All @@ -58,8 +65,6 @@ const Layout = () => {
})
setKerbs(allKerbs.current)
setNavItems(navItems.concat(allKerbs.current))

console.log('allKerbs.current', allKerbs.current)
}

loadKerbs()
Expand Down

0 comments on commit c0167bf

Please sign in to comment.