diff --git a/components/page-actions.js b/components/page-actions.js index a0fd001..d811804 100644 --- a/components/page-actions.js +++ b/components/page-actions.js @@ -122,18 +122,36 @@ export class PageActions extends HTMLElement { } return } + const sKeyOld = 'settings/page:' + this.path + const sKeyNew = 'settings/page:' + newPath + const settingsJson = localStorage.getItem(sKeyOld) + if (settingsJson ?? true === true) { + localStorage.setItem(sKeyNew, settingsJson) + localStorage.removeItem(sKeyOld) + let settingsData + try { + settingsData = JSON.parse(settingsJson) + } catch (err) { + settingsData = {} + } + if (settingsData?.connections) { + for (const dir of ['outbound', 'inbound']) { + const otherDir = ( + dir === 'outbound' ? 'inbound' : 'outbound' + ) + this.applyInverseRename( + settingsData, dir, otherDir, this.path, newPath + ) + } + } + } else { + localStorage.removeItem(sKeyNew) + } localStorage.setItem( newPath, localStorage.getItem(this.path) ) - localStorage.setItem( - 'settings/page:' + newPath, - localStorage.getItem(this.path) - ) localStorage.removeItem(this.path) - localStorage.removeItem( - 'settings/page:' + newPath, - ) dialog.close() location.hash = newPath }) @@ -285,6 +303,36 @@ export class PageActions extends HTMLElement { } } + applyInverseRename( + settingsData, dir, otherDir, oldPath, newPath + ) { + const selfEntries = Object.entries( + settingsData.connections[dir] ?? {} + ) + for (const [path, access] of selfEntries) { + const key = 'settings/page:' + path + let val = localStorage.getItem(key) + try { + if (val !== null) { + val = JSON.parse(val) + } + } catch (err) { + // ignore + } + const data = val ?? {} + data.connections = data.connections ?? {} + data.connections[otherDir] = ( + data.connections[otherDir] ?? {} + ) + const accessValue = data.connections[otherDir][oldPath] + data.connections[otherDir][newPath] = accessValue + data.connections[otherDir][oldPath] = undefined + localStorage.setItem( + key, JSON.stringify(data) + ) + } + } + get language() { return this._language }