diff --git a/components/header.js b/components/header.js index 8b3d6fa..93ebe1e 100644 --- a/components/header.js +++ b/components/header.js @@ -230,21 +230,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) - window.location.hash = newPath - dialog.close() - } + localStorage.setItem( + newPath, + localStorage.getItem(this.path) + ) + localStorage.removeItem(this.path) + dialog.close() + location.hash = newPath }) dialog.footerEl.replaceChildren( cancelBtn, confirmBtn @@ -269,7 +274,7 @@ export class Header extends HTMLElement { confirmBtn.style.marginLeft = '3px' confirmBtn.addEventListener('click', () => { localStorage.removeItem(this.path) - window.location.hash = '/' + location.hash = '/' dialog.close() }) dialog.footerEl.replaceChildren( @@ -333,17 +338,7 @@ 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, - '' - ) - } - window.location.hash = newPath + location.hash = newPath dialog.close() }) dialog.footerEl.replaceChildren( diff --git a/sw.js b/sw.js index 66b682c..e95294d 100644 --- a/sw.js +++ b/sw.js @@ -10,7 +10,7 @@ async function initCache() { '/components/nav-menu.js', '/components/page-menu.js', '/components/dialog.js', - ]) //5 + ]) //6 } self.addEventListener("install", event => {