Skip to content

Commit

Permalink
FEATURE: added query param
Browse files Browse the repository at this point in the history
  • Loading branch information
sahsisunny committed Jul 19, 2023
1 parent 5712f66 commit b116d46
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions standup/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,11 +215,24 @@ function setupTable() {
tableContainerElement.appendChild(tableElement);
}

const urlParams = new URLSearchParams(window.location.search);
const initialUsernames = urlParams.get('users')
? urlParams.get('users').split('+')
: [];
searchInput.value = initialUsernames.join(', ');

async function searchButtonHandler() {
const usernames = searchInput.value
.split(',')
.map((username) => username.trim());
const filteredUsernames = [...new Set(usernames)];
const updatedUrlParams = new URLSearchParams();
updatedUrlParams.set('users', filteredUsernames.join('+'));
const newUrl = `${window.location.origin}${
window.location.pathname
}?${updatedUrlParams.toString()}`;
window.history.pushState({ path: newUrl }, '', newUrl);

tableBodyElement.innerHTML = '';

for (const username of filteredUsernames) {
Expand Down Expand Up @@ -258,3 +271,7 @@ document.addEventListener('click', (event) => {
document.body.style.marginRight = '0%';
}
});

if (initialUsernames.length) {
searchButtonHandler();
}

0 comments on commit b116d46

Please sign in to comment.