Refactor newly-added ClearDataView in settings_view.js

This commit is contained in:
Scott Nonnenberg 2018-03-08 10:00:20 -08:00 committed by Scott Nonnenberg
parent ef041b29d0
commit 256b87aa7a
No known key found for this signature in database
GPG key ID: 5F82280C35134661
2 changed files with 72 additions and 59 deletions

View file

@ -23,6 +23,7 @@ test/views/*.js
!js/views/debug_log_view.js !js/views/debug_log_view.js
!js/views/file_input_view.js !js/views/file_input_view.js
!js/views/inbox_view.js !js/views/inbox_view.js
!js/views/settings_view.js
!js/database.js !js/database.js
!main.js !main.js
!prepare_build.js !prepare_build.js

View file

@ -1,10 +1,15 @@
/* /* global storage: false */
* vim: ts=4:sw=4:expandtab /* global textsecure: false */
*/ /* global i18n: false */
/* global Whisper: false */
/* eslint-disable */
(function () { (function () {
'use strict'; 'use strict';
window.Whisper = window.Whisper || {}; window.Whisper = window.Whisper || {};
const { OS } = window.Signal; const { Database } = window.Whisper;
const { OS, Logs } = window.Signal;
const { Settings } = window.Signal.Types; const { Settings } = window.Signal.Types;
var CheckboxView = Whisper.View.extend({ var CheckboxView = Whisper.View.extend({
@ -119,51 +124,55 @@
}, },
}); });
var CLEAR_DATA_STEPS = { /* jshint ignore:start */
/* eslint-enable */
const CLEAR_DATA_STEPS = {
CHOICE: 1, CHOICE: 1,
DELETING: 2, DELETING: 2,
}; };
var ClearDataView = Whisper.View.extend({ const ClearDataView = Whisper.View.extend({
templateName: 'clear-data', templateName: 'clear-data',
className: 'full-screen-flow overlay', className: 'full-screen-flow overlay',
events: { events: {
'click .cancel': 'onCancel', 'click .cancel': 'onCancel',
'click .delete-all-data': 'onDeleteAllData', 'click .delete-all-data': 'onDeleteAllData',
}, },
initialize: function() { initialize() {
this.step = CLEAR_DATA_STEPS.CHOICE; this.step = CLEAR_DATA_STEPS.CHOICE;
}, },
onCancel: function() { onCancel() {
this.remove(); this.remove();
}, },
onDeleteAllData: function() { async onDeleteAllData() {
console.log('Deleting everything!'); console.log('Deleting everything!');
this.step = CLEAR_DATA_STEPS.DELETING; this.step = CLEAR_DATA_STEPS.DELETING;
this.render(); this.render();
Whisper.Database.close().then(function() { try {
await Database.close();
console.log('All database connections closed. Starting delete.'); console.log('All database connections closed. Starting delete.');
this.clearAllData(); } catch (error) {
}.bind(this), function(error) {
console.log('Something went wrong closing all database connections.'); console.log('Something went wrong closing all database connections.');
}
this.clearAllData(); this.clearAllData();
}.bind(this));
}, },
clearAllData: function() { async clearAllData() {
Promise.all([ try {
Signal.Logs.deleteAll(), await Promise.all([
Whisper.Database.drop(), Logs.deleteAll(),
]).then(function() { Database.drop(),
window.restart(); ]);
}, function(error) { } catch (error) {
console.log( console.log(
'Something went wrong deleting all data:', 'Something went wrong deleting all data:',
error && error.stack ? error.stack : error error && error.stack ? error.stack : error
); );
}
window.restart(); window.restart();
});
}, },
render_attributes: function() { render_attributes() {
return { return {
isStep1: this.step === CLEAR_DATA_STEPS.CHOICE, isStep1: this.step === CLEAR_DATA_STEPS.CHOICE,
header: i18n('deleteAllDataHeader'), header: i18n('deleteAllDataHeader'),
@ -174,9 +183,12 @@
isStep2: this.step === CLEAR_DATA_STEPS.DELETING, isStep2: this.step === CLEAR_DATA_STEPS.DELETING,
deleting: i18n('deleteAllDataProgress'), deleting: i18n('deleteAllDataProgress'),
}; };
} },
}); });
/* eslint-disable */
/* jshint ignore:end */
var SyncView = Whisper.View.extend({ var SyncView = Whisper.View.extend({
templateName: 'syncSettings', templateName: 'syncSettings',
className: 'syncSettings', className: 'syncSettings',