Skip to content

Commit

Permalink
Remove ts-nocheck from brave://settings files
Browse files Browse the repository at this point in the history
  • Loading branch information
emerick committed Jan 6, 2025
1 parent 5272a71 commit 5e704f0
Show file tree
Hide file tree
Showing 31 changed files with 1,253 additions and 985 deletions.
Original file line number Diff line number Diff line change
@@ -1,39 +1,48 @@
// @ts-nocheck
/* Copyright (c) 2019 The Brave Authors. All rights reserved.
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* you can obtain one at https://mozilla.org/MPL/2.0/. */
* You can obtain one at https://mozilla.org/MPL/2.0/. */

import './brave_clear_browsing_data_on_exit_page.js'

import "./brave_clear_browsing_data_on_exit_page.js"
import {CrButtonElement} from 'chrome://resources/cr_elements/cr_button/cr_button.js'
import {
SettingsBraveClearBrowsingDataOnExitPageElement
} from './brave_clear_browsing_data_on_exit_page.js'

import {loadTimeData} from "../i18n_setup.js"
import {WebUiListenerMixin} from 'chrome://resources/cr_elements/web_ui_listener_mixin.js';
import {SettingsClearBrowsingDataDialogElement} from '../clear_browsing_data_dialog/clear_browsing_data_dialog.js'
import type {SettingsClearBrowsingDataDialogElement as BraveSettingsClearBrowsingDataDialogElement}
from '../clear_browsing_data_dialog/clear_browsing_data_dialog.js'
import {BraveClearBrowsingDataDialogBrowserProxy, BraveClearBrowsingDataDialogBrowserProxyImpl}
from './brave_clear_browsing_data_dialog_proxy.js'
import {loadTimeData} from '../i18n_setup.js'

const BaseElement = WebUiListenerMixin(SettingsClearBrowsingDataDialogElement)
export class BraveSettingsClearBrowsingDataDialogElement extends BaseElement {
braveRewardsEnabled_: Boolean = false;
onClearBraveAdsDataClickHandler_: (() => void) = () => {};
import {
SettingsClearBrowsingDataDialogElement
} from '../clear_browsing_data_dialog/clear_browsing_data_dialog.js'

private clearDataBrowserProxy_ =
BraveClearBrowsingDataDialogBrowserProxyImpl.getInstance();
private onSelectedPageChangedCallback_: (() => void) | null = null;
private updateSaveButtonStateCallback_: (() => void) | null = null;
private saveOnExitSettingsCallback_: (() => void) | null = null;
import {
BraveClearBrowsingDataDialogBrowserProxy,
BraveClearBrowsingDataDialogBrowserProxyImpl
} from './brave_clear_browsing_data_dialog_proxy.js'

export class BraveSettingsClearBrowsingDataDialogElement
extends SettingsClearBrowsingDataDialogElement {
braveRewardsEnabled_: Boolean = false
onClearBraveAdsDataClickHandler_: ((e: Event) => void) = () => {}

private clearDataBrowserProxy_: BraveClearBrowsingDataDialogBrowserProxy =
BraveClearBrowsingDataDialogBrowserProxyImpl.getInstance()

private onSelectedPageChangedCallback_: (() => void) | null = null

private updateSaveButtonStateCallback_: (() => void) | null = null

private saveOnExitSettingsCallback_: (() => void) | null = null

override ready() {
super.ready();
super.ready()

// Append On exit tab to tab selector.
this.tabsNames_.push(loadTimeData.getString('onExitPageTitle'));
;(this as any).tabsNames_.push(loadTimeData.getString('onExitPageTitle'))

this.addWebUiListener(
'update-counter-text', this.updateOnExitCountersText.bind(this))
'update-counter-text', this.updateOnExitCountersText_.bind(this))

this.addWebUiListener(
'brave-rewards-enabled-changed', (enabled: boolean) => {
Expand All @@ -56,9 +65,9 @@ export class BraveSettingsClearBrowsingDataDialogElement extends BaseElement {
this.shadowRoot!.querySelector('#on-exit-tab')!.addEventListener(
'clear-data-on-exit-page-change', this.updateSaveButtonStateCallback_)

this.saveOnExitSettingsCallback_ = this.saveOnExitSettings_.bind(this);
this.shadowRoot.querySelector('#saveOnExitSettingsConfirm').addEventListener(
'click', this.saveOnExitSettingsCallback_);
this.saveOnExitSettingsCallback_ = this.saveOnExitSettings_.bind(this)
this.shadowRoot!.querySelector('#saveOnExitSettingsConfirm')!
.addEventListener('click', this.saveOnExitSettingsCallback_)

this.onClearBraveAdsDataClickHandler_ = this.clearBraveAdsData_.bind(this)
}
Expand All @@ -72,16 +81,17 @@ export class BraveSettingsClearBrowsingDataDialogElement extends BaseElement {
this.onSelectedPageChangedCallback_ = null
}

if (this.saveOnExitSettingsCallback_) {
this.shadowRoot.querySelector('#on-exit-tab').removeEventListener(
'clear-data-on-exit-page-change', this.updateSaveButtonStateCallback_);
this.updateSaveButtonStateCallback_ = null;
if (this.updateSaveButtonStateCallback_) {
this.shadowRoot!.querySelector('#on-exit-tab')!.removeEventListener(
'clear-data-on-exit-page-change', this.updateSaveButtonStateCallback_)
this.updateSaveButtonStateCallback_ = null
}

if (this.saveOnExitSettingsCallback_) {
this.shadowRoot.querySelector('#saveOnExitSettingsConfirm').removeEventListener(
'click', this.saveOnExitSettingsCallback_);
this.saveOnExitSettingsCallback_ = null;
this.shadowRoot!.
querySelector('#saveOnExitSettingsConfirm')!.
removeEventListener('click', this.saveOnExitSettingsCallback_)
this.saveOnExitSettingsCallback_ = null
}

this.onClearBraveAdsDataClickHandler_ = () => {}
Expand All @@ -92,60 +102,67 @@ export class BraveSettingsClearBrowsingDataDialogElement extends BaseElement {
* preference.
* @param {string} prefName Browsing data type deletion preference.
* @param {string} text The text with which to update the counter
* @private
*/
updateOnExitCountersText(prefName, text) {
private updateOnExitCountersText_(prefName: string, text: string) {
// Data type deletion preferences are named "browser.clear_data.<datatype>".
// Strip the common prefix, i.e. use only "<datatype>".
const matches = prefName.match(/^browser\.clear_data\.(\w+)$/);
this.shadowRoot.querySelector('#on-exit-tab').setCounter(matches[1], text);
const matches = prefName.match(/^browser\.clear_data\.(\w+)$/)
if (matches) {
this.shadowRoot!.
querySelector<SettingsBraveClearBrowsingDataOnExitPageElement>(
'#on-exit-tab')!.setCounter(matches[1], text)
}
}

/**
* Updates Clear and Save buttons visibility based on the selected tab.
* @private
*/
onSelectedPageChanged_() {
const page = this.$.pages.selectedItem;
private onSelectedPageChanged_() {
const page = this.$.pages.selectedItem
if (!page) {
return
}
const isOnExitPage = (page.id === 'on-exit-tab');
this.$.clearButton.hidden = isOnExitPage;
this.shadowRoot.querySelector('#saveOnExitSettingsConfirm').hidden = !isOnExitPage;
const isOnExitPage = page.id === 'on-exit-tab'
this.$.clearButton.hidden = isOnExitPage
this.shadowRoot!.querySelector<CrButtonElement>(
'#saveOnExitSettingsConfirm')!.hidden = !isOnExitPage
}

/**
* Updates Save button enabled state based on on-exit-tab's changed state.
* @private
*/
updateSaveButtonState_() {
this.shadowRoot.querySelector('#saveOnExitSettingsConfirm').disabled =
!this.shadowRoot.querySelector('#on-exit-tab').isModified;
private updateSaveButtonState_() {
const saveButton = this.shadowRoot!.
querySelector<CrButtonElement>('#saveOnExitSettingsConfirm')
if (saveButton) {
saveButton.disabled = !this.shadowRoot!.
querySelector<SettingsBraveClearBrowsingDataOnExitPageElement>(
'#on-exit-tab')!.isModified_
}
}

/**
* Saves on exit settings selections.
* @private
*/
saveOnExitSettings_() {
const changed = this.shadowRoot.querySelector('#on-exit-tab').getChangedSettings();
private saveOnExitSettings_() {
const changed = this.shadowRoot!.
querySelector<SettingsBraveClearBrowsingDataOnExitPageElement>(
'#on-exit-tab')!.getChangedSettings()
changed.forEach((change) => {
this.set('prefs.' + change.key + '.value', change.value)
})
this.updateSaveButtonState_()
if (!this.clearingInProgress_) {
if (!(this as any).clearingInProgress_) {
this.$.clearBrowsingDataDialog.close()
}
}

/**
* Clears Brave Ads data.
* @private
*/
clearBraveAdsData_(e: any) {
e.preventDefault();
this.clearDataBrowserProxy_.clearBraveAdsData();
this.$.clearBrowsingDataDialog.close();
private clearBraveAdsData_(e: Event) {
e.preventDefault()
this.clearDataBrowserProxy_.clearBraveAdsData()
this.$.clearBrowsingDataDialog.close()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,85 +3,115 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
// you can obtain one at https://mozilla.org/MPL/2.0/.

// @ts-nocheck

import {Polymer} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js';
import {loadTimeData} from '../i18n_setup.js';
import '../settings_shared.css.js';
import '../settings_vars.css.js';
import '../controls/settings_checkbox.js';
import {PrefsMixin} from '/shared/settings/prefs/prefs_mixin.js'
import {BaseMixin} from '../base_mixin.js'
import {PolymerElement} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js'
import {loadTimeData} from '../i18n_setup.js'
import '../settings_shared.css.js'
import '../settings_vars.css.js'
import '../controls/settings_checkbox.js'
import {getTemplate} from './brave_clear_browsing_data_on_exit_page.html.js'

Polymer({
is: 'settings-brave-clear-browsing-data-on-exit-page',
export interface SettingsBraveClearBrowsingDataOnExitPageElement {
$: {
checkboxes: HTMLElement,
}
}

_template: getTemplate(),
const SettingsBraveClearBrowsingDataOnExitPageElementBase =
PrefsMixin(BaseMixin(PolymerElement))

properties: {
prefs: {
type: Object,
notify: true,
},
export class SettingsBraveClearBrowsingDataOnExitPageElement
extends SettingsBraveClearBrowsingDataOnExitPageElementBase {
static get is() {
return 'settings-brave-clear-browsing-data-on-exit-page'
}

counters: {
type: Object,
// Will be filled as results are reported.
value: function() {
return {};
}
},
static get template() {
return getTemplate()
}

isModified: {
type: Boolean,
value: false,
},
static getProperties() {
return {
prefs: {
type: Object,
notify: true,
},

counters: {
type: Object,
// Will be filled as results are reported.
value() {
return {}
}
},

isChildAccount_: {
type: Boolean,
value: function() {
return loadTimeData.getBoolean('isChildAccount');
isModified_: {
type: Boolean,
value: false,
},
},

isAIChatAndHistoryAllowed_: {
type: Boolean,
value: function() {
return loadTimeData.getBoolean('isLeoAssistantAllowed')
&& loadTimeData.getBoolean('isLeoAssistantHistoryAllowed');
isChildAccount_: {
type: Boolean,
value() {
return loadTimeData.getBoolean('isChildAccount')
},
},

isAIChatAndHistoryAllowed_: {
type: Boolean,
value() {
return loadTimeData.getBoolean('isLeoAssistantAllowed')
&& loadTimeData.getBoolean('isLeoAssistantHistoryAllowed')
},
}
}
},
}

public isModified_: boolean

private counters: {[k: string]: string} = {}
private isChildAccount_: boolean
private isAIChatAndHistoryAllowed_: boolean

listeners: {'settings-boolean-control-change': 'updateModified_'},
override ready() {
super.ready()
this.addEventListener(
'settings-boolean-control-change', this.updateModified_)
}

setCounter: function (counter: string, text: string) {
this.set('counters.' + counter, text);
},
public setCounter(counter: string, text: string) {
this.set('counters.' + counter, text)
}

getChangedSettings: function () {
let changed: {key: string, value: boolean}[] = [];
const boxes = this.$.checkboxes.querySelectorAll('settings-checkbox');
public getChangedSettings() {
let changed: Array<{key: string, value: boolean}> = []
const boxes = this.$.checkboxes.querySelectorAll('settings-checkbox')
boxes.forEach((checkbox) => {
if (checkbox.checked != this.get(checkbox.pref.key, this.prefs).value) {
changed.push({key:checkbox.pref.key, value:checkbox.checked});
if (checkbox.checked !== this.get(checkbox.pref!.key, this.prefs).value) {
changed.push({key:checkbox.pref!.key, value:checkbox.checked})
}
})
return changed
}

updateModified_: function () {
let modified = false;
const boxes = this.$.checkboxes.querySelectorAll('settings-checkbox');
private updateModified_() {
let modified = false
const boxes = this.$.checkboxes.querySelectorAll('settings-checkbox')
for (let checkbox of boxes) {
if (checkbox.checked != this.get(checkbox.pref.key, this.prefs).value) {
modified = true;
break;
if (checkbox.checked !== this.get(checkbox.pref!.key, this.prefs).value) {
modified = true
break
}
}

if (this.isModified !== modified) {
this.isModified = modified;
this.fire('clear-data-on-exit-page-change');
if (this.isModified_ !== modified) {
this.isModified_ = modified
this.fire('clear-data-on-exit-page-change')
}
},
});
}
}

customElements.define(
SettingsBraveClearBrowsingDataOnExitPageElement.is,
SettingsBraveClearBrowsingDataOnExitPageElement)
Loading

0 comments on commit 5e704f0

Please sign in to comment.