Only allow rename to make new pages and make new go to page for now

file-group-page
bat 3 years ago
parent db089c3a0c
commit 871e85da35

@ -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(

Loading…
Cancel
Save