Refactor prepare/redraw for consistency

b89d41a70145bcf1ca6dc47d3dd00a21667b3ffe

Wolfsblvt <wolfsblvt@gmail.com>

1 files changed, +12 -10Showing whitespace changes
public/scripts/extensions/quick-reply/src/ui/SettingsUi.js+12 -10
@@ -317,15 +317,7 @@ export class SettingsUi {
317 this.currentQrSet.name = newName;317 this.currentQrSet.name = newName;
318 await this.currentQrSet.save();318 await this.currentQrSet.save();
319319
320 // Update the option in all select dropdowns320 // Update it in both set lists
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
329 this.settings.config.setList.forEach(set => {321 this.settings.config.setList.forEach(set => {
330 if (set.set.name === oldName) {322 if (set.set.name === oldName) {
331 set.set.name = newName;323 set.set.name = newName;
@@ -336,9 +328,19 @@ export class SettingsUi {
336 set.set.name = newName;328 set.set.name = newName;
337 }329 }
338 });330 });
339
340 this.settings.save();331 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
341 this.currentSet.value = newName;339 this.currentSet.value = newName;
340 this.onQrSetChange();
341 this.prepareGlobalSetList();
342 this.prepareChatSetList();
343
342 console.info(`Quick Reply Set renamed from ""${oldName}" to "${newName}".`);344 console.info(`Quick Reply Set renamed from ""${oldName}" to "${newName}".`);
343 }345 }
344 }346 }