From f699f2a3f7ed28180c14569e0015f5efcd292101 Mon Sep 17 00:00:00 2001 From: bat Date: Sun, 2 Apr 2023 00:59:49 +0000 Subject: [PATCH] Subir archivos a 'components' --- components/header.js | 38 ++++++++++++++++++-------------------- 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/components/header.js b/components/header.js index 78e6d67..05ea93c 100644 --- a/components/header.js +++ b/components/header.js @@ -227,21 +227,26 @@ export class Header extends HTMLElement { const confirmBtn = document.createElement('button') confirmBtn.innerText = this.text.rename confirmBtn.style.marginLeft = '3px' + let errorEl confirmBtn.addEventListener('click', () => { const newPath = input.value - const exists = localStorage.getItem(newPath) - if (exists ?? true === true) { + const v = localStorage.getItem(newPath) + if (v !== null || newPath === this.path) { + if (!errorEl) { + errorEl = document.createElement('p') + errorEl.style.color = 'red' + errorEl.innerText = this.text.alreadyExists + dialog.bodyEl.appendChild(errorEl) + } return } - if (newPath !== this.path) { - localStorage.setItem( - newPath, - localStorage.getItem(this.path) - ) - localStorage.removeItem(this.path) - dialog.close() - vlocation.hash = newPath - } + localStorage.setItem( + newPath, + localStorage.getItem(this.path) + ) + localStorage.removeItem(this.path) + dialog.close() + location.hash = newPath }) dialog.footerEl.replaceChildren( cancelBtn, confirmBtn @@ -266,7 +271,7 @@ export class Header extends HTMLElement { confirmBtn.style.marginLeft = '3px' confirmBtn.addEventListener('click', () => { localStorage.removeItem(this.path) - vlocation.hash = '/' + location.hash = '/' dialog.close() }) dialog.footerEl.replaceChildren( @@ -330,15 +335,8 @@ export class Header extends HTMLElement { confirmBtn.style.marginLeft = '3px' confirmBtn.addEventListener('click', () => { const newPath = this.encodePath(input.value) - const exists = localStorage.getItem(newPath) - if (exists ?? true === true) { - return - } - if (newPath !== this.path) { - localStorage.setItem(newPath, '') - } + location.hash = newPath dialog.close() - vlocation.hash = newPath }) dialog.footerEl.replaceChildren( cancelBtn, confirmBtn