From b5f48a43e3e63f5a3bd2a906f65d1d88e71aa948 Mon Sep 17 00:00:00 2001 From: yflory Date: Wed, 30 Sep 2020 18:44:04 +0200 Subject: [PATCH] Block snapshot creation while disconnected --- .../src/less2/include/modals-ui-elements.less | 5 ++++- .../src/less2/include/toolbar-history.less | 1 + www/common/common-ui-elements.js | 12 +++++++++--- www/common/sframe-app-framework.js | 4 ++++ www/common/sframe-common-history.js | 2 +- 5 files changed, 19 insertions(+), 5 deletions(-) diff --git a/customize.dist/src/less2/include/modals-ui-elements.less b/customize.dist/src/less2/include/modals-ui-elements.less index 200f39b29..a0b439c45 100644 --- a/customize.dist/src/less2/include/modals-ui-elements.less +++ b/customize.dist/src/less2/include/modals-ui-elements.less @@ -125,8 +125,11 @@ margin-bottom: @snapshot_spacing; max-height: 245px; overflow: auto; - min-height: 100px; outline: none; + .cp-snapshot-spinner { + min-height: 90px; + text-align: center; + } .cp-snapshot-element { display: flex; align-items: center; diff --git a/customize.dist/src/less2/include/toolbar-history.less b/customize.dist/src/less2/include/toolbar-history.less index 10af320ae..7f64f4c72 100644 --- a/customize.dist/src/less2/include/toolbar-history.less +++ b/customize.dist/src/less2/include/toolbar-history.less @@ -197,6 +197,7 @@ right: 1px; top: 1px; bottom: 1px; + cursor: pointer; .cp-history-snapshot { position: absolute; border: 2px solid @cryptpad_text_col; diff --git a/www/common/common-ui-elements.js b/www/common/common-ui-elements.js index 3ae4ffedd..899363b06 100644 --- a/www/common/common-ui-elements.js +++ b/www/common/common-ui-elements.js @@ -3314,6 +3314,7 @@ define([ Messages.snapshots_placeholder = "Snapshot title"; // XXX Messages.snapshots_open = "View"; Messages.snapshots_delete = "Delete"; + Messages.snapshots_cantMake = "Disconnected. Can't create a new snapshot now."; UIElements.openSnapshotsModal = function (common, load, make, remove) { var modal; var readOnly = common.getMetadataMgr().getPrivateData().readOnly; @@ -3406,10 +3407,15 @@ define([ onClick: function () { var val = $input.val(); if (!val) { return true; } - $container.html(''); - UI.spinner($container).get().show(); + $container.html('').append(h('div.cp-snapshot-spinner')); + var to = setTimeout(function () { + UI.spinner($container.find('div')).get().show(); + }); make(val, function (err) { - if (err) { return; } + clearTimeout(to); + if (err) { + return void UI.alert(Messages.snapshots_cantMake); + } refresh(); }); return true; diff --git a/www/common/sframe-app-framework.js b/www/common/sframe-app-framework.js index 4ed047eb8..2df62c73a 100644 --- a/www/common/sframe-app-framework.js +++ b/www/common/sframe-app-framework.js @@ -138,6 +138,9 @@ define([ onLocal(); }; var makeSnapshot = function (title, cb) { + if (state !== STATE.READY) { + return void cb('NOT_READY'); + } var sframeChan = common.getSframeChannel(); sframeChan.query("Q_GET_LAST_HASH", null, function (err, obj) { if (err || (obj && obj.error)) { return void UI.warn(Messages.error); } @@ -357,6 +360,7 @@ define([ }; var setLastMetadata = function (md) { if (!unsyncMode) { return; } + if (state !== STATE.READY) { return; } var newContentStr = cpNfInner.chainpad.getAuthDoc(); var newContent = JSON.parse(newContentStr); if (Array.isArray(newContent)) { diff --git a/www/common/sframe-common-history.js b/www/common/sframe-common-history.js index f2f254336..1ccec88be 100644 --- a/www/common/sframe-common-history.js +++ b/www/common/sframe-common-history.js @@ -396,7 +396,7 @@ define([ time: block.time ? (+new Date(block.time)) : +new Date() }; var sent = config.setLastMetadata(md); - if (!sent) { return void UI.warn(Messages.error); } + if (!sent) { return void UI.alert(Messages.snapshots_cantMake); } refreshBar(); } catch (e) { console.error(e);