From 86341e3ece2f63c3b337699a1c7272db172c3f5a Mon Sep 17 00:00:00 2001 From: Jonatan Nilsson Date: Wed, 2 Oct 2019 01:13:15 +0000 Subject: [PATCH] Fix admin edit page --- app/admin/editpage.js | 43 +++++++++++++++++++++++++++++-------------- 1 file changed, 29 insertions(+), 14 deletions(-) diff --git a/app/admin/editpage.js b/app/admin/editpage.js index 8b9c1b9..a8f5510 100644 --- a/app/admin/editpage.js +++ b/app/admin/editpage.js @@ -25,8 +25,33 @@ const EditPage = { }, oninit: function(vnode) { - this.loading = m.route.param('key') !== 'add' - this.creating = m.route.param('key') === 'add' + this.froala = null + this.loadedFroala = Froala.loadedFroala + + if (!this.loadedFroala) { + Froala.createFroalaScript() + .then(function() { + vnode.state.loadedFroala = true + m.redraw() + }) + } + + this.fetchPage(vnode) + }, + + onupdate: function(vnode) { + if (this.lastid !== m.route.param('id')) { + this.fetchPage(vnode) + if (this.lastid === 'add') { + m.redraw() + } + } + }, + + fetchPage: function(vnode) { + this.lastid = m.route.param('id') + this.loading = this.lastid !== 'add' + this.creating = this.lastid === 'add' this.error = '' this.page = { name: '', @@ -35,11 +60,9 @@ const EditPage = { media: null, } this.editedPath = false - this.froala = null - this.loadedFroala = Froala.loadedFroala - if (m.route.param('key') !== 'add') { - Page.getPage(m.route.param('key')) + if (this.lastid !== 'add') { + Page.getPage(this.lastid) .then(function(result) { vnode.state.editedPath = true vnode.state.page = result @@ -55,14 +78,6 @@ const EditPage = { } else { document.title = 'Create Page - Admin NFP Moe' } - - if (!this.loadedFroala) { - Froala.createFroalaScript() - .then(function() { - vnode.state.loadedFroala = true - m.redraw() - }) - } }, updateValue: function(name, e) {