From 97537e3e16ee03f667326362bbec53e785145148 Mon Sep 17 00:00:00 2001 From: Maaz Syed Adeeb Date: Sun, 6 Nov 2016 16:04:41 +0530 Subject: [PATCH] [WIP] Making the Clear Browsing Data dialog stateful --- js/actions/appActions.js | 7 ++++ js/components/clearBrowsingDataPanel.js | 45 +++++++++++++++++++------ js/components/main.js | 3 +- js/constants/appConstants.js | 3 +- js/stores/appStore.js | 3 ++ 5 files changed, 49 insertions(+), 12 deletions(-) diff --git a/js/actions/appActions.js b/js/actions/appActions.js index 0121a2d2826..46ef3d66b89 100644 --- a/js/actions/appActions.js +++ b/js/actions/appActions.js @@ -579,6 +579,13 @@ const appActions = { AppDispatcher.dispatch({ actionType: AppConstants.APP_DEFAULT_BROWSER_CHECK_COMPLETE }) + }, + + setClearBrowserDataDefaults: function (defaultValues) { + AppDispatcher.dispatch({ + actionType: AppConstants.APP_UPDATE_CLEAR_BROWSER_DATA_DEFAULTS, + defaultValues + }) } } diff --git a/js/components/clearBrowsingDataPanel.js b/js/components/clearBrowsingDataPanel.js index 515e29d1544..ef02c3f082f 100644 --- a/js/components/clearBrowsingDataPanel.js +++ b/js/components/clearBrowsingDataPanel.js @@ -3,6 +3,7 @@ * You can obtain one at http://mozilla.org/MPL/2.0/. */ const React = require('react') +const Immutable = require('immutable') const ImmutableComponent = require('./immutableComponent') const Dialog = require('./dialog') const Button = require('./button') @@ -24,14 +25,38 @@ class ClearBrowsingDataPanel extends ImmutableComponent { this.onToggleAutofillData = this.onToggleSetting.bind(this, 'autofillData') this.onToggleSavedSiteSettings = this.onToggleSetting.bind(this, 'savedSiteSettings') this.onClear = this.onClear.bind(this) + this.getIsChecked = this.getIsChecked.bind(this) + this.getNewDefaultValues = this.getNewDefaultValues.bind(this) + } + getIsChecked (setting) { + const currentValue = this.props.clearBrowsingDataDetail.get(setting) + if (this.props.defaultValues && currentValue === undefined) { + return this.props.defaultValues.get(setting) + } else { + return currentValue + } + } + getNewDefaultValues () { + let newDefaultValues = new Immutable.Map() + let settings = ['browserHistory', 'downloadHistory', 'cachedImagesAndFiles', 'savedPasswords', 'allSiteCookies', 'autocompleteData', 'autofillData', 'savedSiteSettings'] + // TODO: Optimize this to send back only defined settings + settings.forEach(function (setting) { + const currentValue = this.props.clearBrowsingDataDetail.get(setting) + newDefaultValues = newDefaultValues.set(setting, currentValue !== undefined ? currentValue : this.props.defaultValues.get(setting)) + }.bind(this)) + return newDefaultValues } onToggleSetting (setting, e) { windowActions.setClearBrowsingDataDetail(this.props.clearBrowsingDataDetail.set(setting, e.target.value)) } onClear () { - appActions.clearAppData(this.props.clearBrowsingDataDetail) - this.props.onHide() let detail = this.props.clearBrowsingDataDetail + if (this.props.defaultValues) { + detail = this.getNewDefaultValues() + } + appActions.setClearBrowserDataDefaults(detail) + appActions.clearAppData(detail) + this.props.onHide() if (detail.get('allSiteCookies') && detail.get('browserHistory') && detail.get('cachedImagesAndFiles')) { ipc.send(messages.PREFS_RESTART) @@ -42,14 +67,14 @@ class ClearBrowsingDataPanel extends ImmutableComponent {
e.stopPropagation()}>
- - - - - - - - + + + + + + + +