(de-) select all

This commit is contained in:
Simon
2026-02-08 17:14:20 +00:00
parent 88997a7527
commit 1dc6048d9c
2 changed files with 96 additions and 5 deletions

View File

@@ -636,12 +636,20 @@ function renderFilters(container, session) {
const wrapper = document.createElement('div');
wrapper.className = 'setting-item';
const labelRow = document.createElement('div');
labelRow.className = 'setting-label-row';
const label = document.createElement('label');
label.textContent = optionGroup.title || optionGroup.id;
labelRow.appendChild(label);
const options = optionGroup.options || [];
const currentSelection = session.options ? session.options[optionGroup.id] : null;
if (optionGroup.multiSelect) {
const actionBtn = document.createElement('button');
actionBtn.type = 'button';
actionBtn.className = 'btn-link';
const list = document.createElement('div');
list.className = 'multi-select';
@@ -651,6 +659,14 @@ function renderFilters(container, session) {
: []
);
const updateActionLabel = () => {
const allChecked = options.length > 0 &&
Array.from(list.querySelectorAll('input[type="checkbox"]'))
.every((cb) => cb.checked);
actionBtn.textContent = allChecked ? 'Deselect all' : 'Select all';
actionBtn.disabled = options.length === 0;
};
options.forEach((opt) => {
const item = document.createElement('label');
item.className = 'multi-select-item';
@@ -677,6 +693,7 @@ function renderFilters(container, session) {
setSession(nextSession);
savePreference(nextSession);
resetAndReload();
updateActionLabel();
};
item.appendChild(checkbox);
@@ -684,7 +701,30 @@ function renderFilters(container, session) {
list.appendChild(item);
});
wrapper.appendChild(label);
updateActionLabel();
actionBtn.onclick = () => {
const checkboxes = Array.from(list.querySelectorAll('input[type="checkbox"]'));
const allChecked = checkboxes.length > 0 && checkboxes.every((cb) => cb.checked);
checkboxes.forEach((cb) => {
cb.checked = !allChecked;
});
const nextSession = getSession();
if (!nextSession || !nextSession.channel) return;
const selected = [];
if (!allChecked) {
options.forEach((opt) => selected.push(opt));
}
nextSession.options[optionGroup.id] = selected;
setSession(nextSession);
savePreference(nextSession);
resetAndReload();
updateActionLabel();
};
labelRow.appendChild(actionBtn);
wrapper.appendChild(labelRow);
wrapper.appendChild(list);
container.appendChild(wrapper);
return;
@@ -715,7 +755,7 @@ function renderFilters(container, session) {
resetAndReload();
};
wrapper.appendChild(label);
wrapper.appendChild(labelRow);
wrapper.appendChild(select);
container.appendChild(wrapper);
});