Merge pull request 'Check filename on create' (#42) from exists into main

Reviewed-on: https://codeberg.org/macchiato/pages/pulls/42
file-group-page
bat 3 years ago
commit f30a558a43

@ -310,13 +310,30 @@ export class Header extends HTMLElement {
input.value = '/'
input.style.minWidth = '300px'
dialog.bodyEl.appendChild(input)
let errorEl
const bGroup = document.createElement(
'm-forms-button-group'
)
bGroup.addPrimary(this.text.createPage, () => {
const newPath = this.encodePath(input.value)
const v = localStorage.getItem(newPath)
if (v !== null || newPath === this.path) {
if (!errorEl) {
errorEl = document.createElement('p')
errorEl.style.color = 'red'
const errText = this.text.alreadyExists
errorEl.innerText = errText
dialog.bodyEl.appendChild(errorEl)
return
}
return
}
localStorage.setItem(newPath, '')
location.hash = newPath
dialog.close()
this.dispatchEvent(new CustomEvent(
'create-page', {bubbles: true}
))
})
bGroup.addCancel(this.text.cancel, () => {
dialog.close()

@ -28,6 +28,9 @@ export class Layout extends HTMLElement {
this.header.addEventListener('click-edit', () => {
this.editing = !this.editing
})
this.header.addEventListener('create-page', () => {
this.editing = true
})
this.shadowRoot.appendChild(this.header)
this.load()
addEventListener('hashchange', () => {

@ -11,7 +11,7 @@ async function initCache() {
'/components/dialog.js',
'/forms/button-group.js',
'/menu/dropdown.js',
]) //3
]) //4
}
self.addEventListener("install", event => {

Loading…
Cancel
Save