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); evEditableStateChange.fire(state === STATE.READY && !unsyncMode);
stateChange(state); 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) { var setHistoryMode = function (bool, update) {
if (!bool && !update && state !== STATE.READY) { return false; }
cpNfInner.metadataMgr.setHistory(bool); cpNfInner.metadataMgr.setHistory(bool);
toolbar.setHistory(bool); toolbar.setHistory(bool);
setUnsyncMode(bool); setUnsyncMode(bool);
@ -299,17 +307,19 @@ define([
else { else {
setTimeout(cpNfInner.metadataMgr.refresh); setTimeout(cpNfInner.metadataMgr.refresh);
} }
return true;
}; };
var closeSnapshot = function (restore) { var closeSnapshot = function (restore) {
setUnsyncMode(false); if (restore && state !== STATE.READY) { return false; }
if (restore) { setUnsyncMode(false); // Unlock onLocal and onRemote
onLocal(); if (restore) { onLocal(); } // Restore? commit the content
} onRemote(); // Make sure we're back to the realtime content
onRemote(); return true;
}; };
var loadSnapshot = function (hash, data) { var loadSnapshot = function (hash, data) {
setUnsyncMode(true); setUnsyncMode(true);
Snapshots.create(common, { Snapshots.create(common, {
readOnly: readOnly,
$toolbar: $(toolbarContainer), $toolbar: $(toolbarContainer),
hash: hash, hash: hash,
data: data, data: data,
@ -436,9 +446,7 @@ define([
evOnDefaultContentNeeded.fire(); evOnDefaultContentNeeded.fire();
} }
}).nThen(function () { }).nThen(function () {
if (!unsyncMode) { stateChange(STATE.READY);
stateChange(STATE.READY);
}
firstConnection = false; firstConnection = false;
oldContent = undefined; oldContent = undefined;

@ -2,11 +2,12 @@ define([
'jquery', 'jquery',
'/common/common-interface.js', '/common/common-interface.js',
'/common/hyperscript.js', '/common/hyperscript.js',
'/customize/messages.js',
'/bower_components/nthen/index.js', '/bower_components/nthen/index.js',
//'/bower_components/chainpad-json-validator/json-ot.js', //'/bower_components/chainpad-json-validator/json-ot.js',
'/bower_components/chainpad/chainpad.dist.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 ChainPad = window.ChainPad;
var History = {}; var History = {};
@ -93,17 +94,23 @@ define([
console.error(e); 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 () { 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.onLocal();
config.onRemote(); config.onRemote();
return true;
}; };
config.setHistory(true); config.setHistory(true);
var Messages = common.Messages;
var realtime; var realtime;
var states = []; var states = [];
@ -372,15 +379,17 @@ define([
// Close & restore buttons // Close & restore buttons
$close.click(function () { $close.click(function () {
states = []; states = [];
close();
onClose(); onClose();
close();
}); });
$rev.click(function () { $rev.click(function () {
UI.confirm(Messages.history_restorePrompt, function (yes) { UI.confirm(Messages.history_restorePrompt, function (yes) {
if (!yes) { return; } if (!yes) { return; }
close(); var done = onRevert();
onRevert(); if (done) {
UI.log(Messages.history_restoreDone); close();
UI.log(Messages.history_restoreDone);
}
}); });
}); });

Loading…
Cancel
Save