Skip to content

Commit

Permalink
Added feature to update url when filtering is added. [Closes #6]
Browse files Browse the repository at this point in the history
  • Loading branch information
patcon committed Nov 9, 2024
1 parent 461d33e commit c580993
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,16 @@ if (search) {
search.classList.remove('dn')
const input = search.querySelector('input')

function setSearchParam(searchParam) {
// Update the URL without adding to the search history
const newurl = `${window.location.protocol}//${window.location.host}${window.location.pathname}?q=${encodeURIComponent(searchParam)}`
window.history.replaceState({path: newurl}, '', newurl)
}

// Function to handle search logic
function handleSearch(searchValue) {
setSearchParam(searchValue)

if (searchValue === '') {
cards.forEach((c) => c.classList.remove('dn'))
return
Expand Down

0 comments on commit c580993

Please sign in to comment.