From 871e85da35cd5947306161f9cc711be89bfa3611 Mon Sep 17 00:00:00 2001 From: bat Date: Sat, 1 Apr 2023 09:23:21 +0000 Subject: [PATCH] Only allow rename to make new pages and make new go to page for now --- components/header.js | 41 ++++++++++++++++++----------------------- 1 file changed, 18 insertions(+), 23 deletions(-) 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(