Fix service navigation button sorted in wrong order when editing service

This commit is contained in:
Alice Gaudon 2020-07-14 10:01:34 +02:00
parent 03f275e6e8
commit 05acd44e98
2 changed files with 9 additions and 5 deletions

View File

@ -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);
}

View File

@ -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) {