Improve reconnect when in history or snapshot view

pull/1/head
yflory 4 years ago
parent c8f16d427d
commit ac4322cfab

@ -291,7 +291,15 @@ define([
evEditableStateChange.fire(state === STATE.READY && !unsyncMode);
stateChange(state);
};
// History mode:
// When "bool" is true, we're entering in history mode
// When "bool" is false and "update" is true, it means we're closing the history
// and should update the content
// When "bool" is false and "update" is false, it means we're restoring an old version,
// no need to refresh
var setHistoryMode = function (bool, update) {
if (!bool && !update && state !== STATE.READY) { return false; }
cpNfInner.metadataMgr.setHistory(bool);
toolbar.setHistory(bool);
setUnsyncMode(bool);
@ -299,17 +307,19 @@ define([
else {
setTimeout(cpNfInner.metadataMgr.refresh);
}
return true;
};
var closeSnapshot = function (restore) {
setUnsyncMode(false);
if (restore) {
onLocal();
}
onRemote();
if (restore && state !== STATE.READY) { return false; }
setUnsyncMode(false); // Unlock onLocal and onRemote
if (restore) { onLocal(); } // Restore? commit the content
onRemote(); // Make sure we're back to the realtime content
return true;
};
var loadSnapshot = function (hash, data) {
setUnsyncMode(true);
Snapshots.create(common, {
readOnly: readOnly,
$toolbar: $(toolbarContainer),
hash: hash,
data: data,
@ -436,9 +446,7 @@ define([
evOnDefaultContentNeeded.fire();
}
}).nThen(function () {
if (!unsyncMode) {
stateChange(STATE.READY);
}
stateChange(STATE.READY);
firstConnection = false;
oldContent = undefined;

@ -2,11 +2,12 @@ define([
'jquery',
'/common/common-interface.js',
'/common/hyperscript.js',
'/customize/messages.js',
'/bower_components/nthen/index.js',
//'/bower_components/chainpad-json-validator/json-ot.js',
'/bower_components/chainpad/chainpad.dist.js',
], function ($, UI, h, nThen, ChainPad /* JsonOT */) {
], function ($, UI, h, Messages, nThen, ChainPad /* JsonOT */) {
//var ChainPad = window.ChainPad;
var History = {};
@ -93,17 +94,23 @@ define([
console.error(e);
}
};
var onClose = function () { config.setHistory(false, true); };
var onClose = function () {
config.setHistory(false, true);
};
Messages.history_cantRestore = "Can't restore now. Disconnected."; // XXX
var onRevert = function () {
config.setHistory(false, false);
var closed = config.setHistory(false, false);
if (!closed) {
return void UI.alert(Messages.history_cantRestore);
}
config.onLocal();
config.onRemote();
return true;
};
config.setHistory(true);
var Messages = common.Messages;
var realtime;
var states = [];
@ -372,15 +379,17 @@ define([
// Close & restore buttons
$close.click(function () {
states = [];
close();
onClose();
close();
});
$rev.click(function () {
UI.confirm(Messages.history_restorePrompt, function (yes) {
if (!yes) { return; }
close();
onRevert();
UI.log(Messages.history_restoreDone);
var done = onRevert();
if (done) {
close();
UI.log(Messages.history_restoreDone);
}
});
});

Loading…
Cancel
Save