summaryrefslogtreecommitdiff
path: root/script.js
diff options
context:
space:
mode:
authorMartin Fischer <martin@push-f.com>2022-07-12 15:55:54 +0200
committerMartin Fischer <martin@push-f.com>2022-07-12 15:59:35 +0200
commit2f8f4a109b739942604bdfb8cf679887d835d86c (patch)
tree1359408781012a44f42cd3f00035fa7a82e7ef62 /script.js
parent263eead8fcd67ee032a4fc6a250bed11f19c5d28 (diff)
add inputs to filter by name and/or author
Diffstat (limited to 'script.js')
-rw-r--r--script.js60
1 files changed, 50 insertions, 10 deletions
diff --git a/script.js b/script.js
index b8edbb4..b10c6c7 100644
--- a/script.js
+++ b/script.js
@@ -9,7 +9,33 @@ function newEl(tagname, content) {
return cell;
}
+const updateUrl = debounce(params => {
+ if (Object.keys(params).length == 0)
+ window.history.pushState({}, '', '/');
+ else
+ window.history.pushState({}, '', '?' + new URLSearchParams(params).toString());
+}, 500);
+
function display(proposals) {
+ const params = {};
+ if (nameInput.value) {
+ proposals = proposals.filter(p => (p.name || p.page_title).toLowerCase().includes(nameInput.value.toLowerCase()));
+ params.q = nameInput.value;
+ }
+
+ if (authorsInput.value) {
+ // The first letter of MediaWiki usernames is case-insensitive.
+ const firstChar = authorsInput.value.charAt(0);
+ const rest = authorsInput.value.slice(1);
+ const lowercase = firstChar.toLowerCase() + rest;
+ const uppercase = firstChar.toUpperCase() + rest;
+ proposals = proposals.filter(p => p.authors && (p.authors.includes(lowercase) || p.authors.includes(uppercase)));
+ params.author = authorsInput.value;
+ }
+
+ updateUrl(params);
+
+ tbody.innerHTML = '';
proposals.forEach(proposal => {
const row = document.createElement('tr');
@@ -36,18 +62,32 @@ function display(proposals) {
});
}
+const nameInput = document.getElementById('name');
+const authorsInput = document.getElementById('authors');
+
+function debounce(callback, wait) {
+ let timeoutId = null;
+ return (...args) => {
+ window.clearTimeout(timeoutId);
+ timeoutId = window.setTimeout(() => {
+ callback.apply(null, args);
+ }, wait);
+ };
+}
+
(async function() {
const proposals = await (await fetch('proposals.json')).json();
- const authorFilter = new URLSearchParams(location.search).get('author');
- if (authorFilter) {
- // The first letter of MediaWiki usernames is case-insensitive.
- const firstChar = authorFilter.charAt(0);
- const rest = authorFilter.slice(1);
- const lowercase = firstChar.toLowerCase() + rest;
- const uppercase = firstChar.toUpperCase() + rest;
- display(proposals.filter(p => p.authors && (p.authors.includes(lowercase) || p.authors.includes(uppercase))));
- } else {
+ const params = new URLSearchParams(location.search);
+ nameInput.value = params.get('q');
+ authorsInput.value = params.get('author');
+
+ display(proposals);
+
+ nameInput.addEventListener('input', debounce(e => {
display(proposals);
- }
+ }, 100));
+ authorsInput.addEventListener('input', debounce(e => {
+ display(proposals);
+ }, 100));
})();