From 05acd44e98ebc905c981531bc10357007741781f Mon Sep 17 00:00:00 2001 From: Alice Gaudon Date: Tue, 14 Jul 2020 10:01:34 +0200 Subject: [PATCH] Fix service navigation button sorted in wrong order when editing service --- frontend/ts/index.ts | 12 ++++++++---- frontend/ts/service-settings.ts | 2 +- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/frontend/ts/index.ts b/frontend/ts/index.ts index 6f70f70..61cee8d 100644 --- a/frontend/ts/index.ts +++ b/frontend/ts/index.ts @@ -212,13 +212,15 @@ ipcRenderer.on('data', (event, appData, iconSets, actualSelectedService, emptyUr document.documentElement.style.setProperty('--nav-width', config.bigNavBar ? '64px' : '48px'); }); -function removeServiceFeatures(id: number): HTMLElement | null { +function removeServiceFeatures(id: number): Element | null { // Remove nav const nav = document.querySelector('#service-selector'); let oldNavButton: HTMLElement | null = null; + let nextSibling: Element | null = null; if (nav) { oldNavButton = nav.querySelector('li:nth-of-type(' + (id + 1) + ')'); if (oldNavButton) { + nextSibling = oldNavButton.nextElementSibling; nav.removeChild(oldNavButton); } } @@ -228,19 +230,21 @@ function removeServiceFeatures(id: number): HTMLElement | null { document.querySelector('#services')?.removeChild(services[id].view); } - return oldNavButton; + return nextSibling; } ipcRenderer.on('updateService', (e, id, data) => { if (id === null) { + console.log('Adding new service'); services.push(data); createService(services.length - 1); } else { - const oldNavButton = removeServiceFeatures(id); + console.log('Updating existing service', id); + const nextSibling = removeServiceFeatures(id); // Create new service services[id] = data; - createService(id, oldNavButton ? oldNavButton.nextElementSibling : null); + createService(id, nextSibling); if (parseInt(selectedService) === id) { setActiveService(id); } diff --git a/frontend/ts/service-settings.ts b/frontend/ts/service-settings.ts index 8419476..179f0f8 100644 --- a/frontend/ts/service-settings.ts +++ b/frontend/ts/service-settings.ts @@ -206,7 +206,7 @@ function save() { ipcRenderer.send('saveService', serviceId, service); remote.getCurrentWindow().close(); -}; +} function isValid() { if (typeof service.name !== 'string' || service.name.length === 0) {