Refactor prepare/redraw for consistency

b89d41a70145bcf1ca6dc47d3dd00a21667b3ffe

Wolfsblvt <wolfsblvt@gmail.com>

1 files changed, +12 -10Ignore whitespace
public/scripts/extensions/quick-reply/src/ui/SettingsUi.js+12 -10
@@ -317,15 +317,7 @@ export class SettingsUi {
317317 this.currentQrSet.name = newName;
318318 await this.currentQrSet.save();
319319
320320 // Update the optionit in allboth selectset dropdownslists
321- /** @type {NodeListOf<HTMLOptionElement>} */
322- const options = this.dom.querySelectorAll(`#qr--set option[value="${oldName}"], select.qr--set option[value="${oldName}"]`);
323- options.forEach(option => {
324- option.value = newName;
325- option.textContent = newName;
326- });
327-
328- // Update in in both set lists
329321 this.settings.config.setList.forEach(set => {
330322 if (set.set.name === oldName) {
331323 set.set.name = newName;
@@ -336,9 +328,19 @@ export class SettingsUi {
336328 set.set.name = newName;
337329 }
338330 });
339-
340331 this.settings.save();
332+
333+ // Update the option in the current selected QR dropdown. All others will be refreshed via the prepare calls below.
334+ /** @type {HTMLOptionElement} */
335+ const option = this.currentSet.querySelector(`#qr--set option[value="${oldName}"]`);
336+ option.value = newName;
337+ option.textContent = newName;
338+
341339 this.currentSet.value = newName;
340+ this.onQrSetChange();
341+ this.prepareGlobalSetList();
342+ this.prepareChatSetList();
343+
342344 console.info(`Quick Reply Set renamed from ""${oldName}" to "${newName}".`);
343345 }
344346 }