Format components/brave_adblock_ui/ (#32832)

This commit is contained in:
Mikhail
2026-01-12 20:38:42 +04:00
committed by GitHub
parent 9a31b99b40
commit e84619e3d8
12 changed files with 330 additions and 147 deletions
-1
View File
@@ -53,7 +53,6 @@ components/brave_wallet/resources/solana_web3_script.js
/components/brave_news/
/components/web-components/
/components/brave_welcome_ui/
/components/brave_adblock_ui/
/components/brave_ads/
/components/brave_extension/
/components/brave_perf_predictor/
@@ -10,57 +10,60 @@ import { types } from '../constants/adblock_types'
export const enableFilterList = (uuid: string, enabled: boolean) =>
action(types.ADBLOCK_ENABLE_FILTER_LIST, {
uuid,
enabled
enabled,
})
export const getCustomFilters = () => action(types.ADBLOCK_GET_CUSTOM_FILTERS)
export const getRegionalLists = () => action(types.ADBLOCK_GET_REGIONAL_LISTS)
export const getListSubscriptions = () => action(types.ADBLOCK_GET_LIST_SUBSCRIPTIONS)
export const getListSubscriptions = () =>
action(types.ADBLOCK_GET_LIST_SUBSCRIPTIONS)
export const onGetCustomFilters = (customFilters: string) =>
action(types.ADBLOCK_ON_GET_CUSTOM_FILTERS, {
customFilters
customFilters,
})
export const onGetRegionalLists = (regionalLists: AdBlock.FilterList[]) =>
action(types.ADBLOCK_ON_GET_REGIONAL_LISTS, {
regionalLists
regionalLists,
})
export const onGetListSubscriptions = (listSubscriptions: AdBlock.SubscriptionInfo[]) =>
export const onGetListSubscriptions = (
listSubscriptions: AdBlock.SubscriptionInfo[],
) =>
action(types.ADBLOCK_ON_GET_LIST_SUBSCRIPTIONS, {
listSubscriptions
listSubscriptions,
})
export const updateCustomFilters = (customFilters: string) =>
action(types.ADBLOCK_UPDATE_CUSTOM_FILTERS, {
customFilters
customFilters,
})
export const submitNewSubscription = (listUrl: string) =>
action(types.ADBLOCK_SUBMIT_NEW_SUBSCRIPTION, {
listUrl
listUrl,
})
export const setSubscriptionEnabled = (listUrl: string, enabled: boolean) =>
action(types.ADBLOCK_SET_SUBSCRIPTION_ENABLED, {
listUrl,
enabled
enabled,
})
export const deleteSubscription = (listUrl: string) =>
action(types.ADBLOCK_DELETE_SUBSCRIPTION, {
listUrl
listUrl,
})
export const refreshSubscription = (listUrl: string) =>
action(types.ADBLOCK_REFRESH_SUBSCRIPTION, {
listUrl
listUrl,
})
export const viewSubscriptionSource = (listUrl: string) =>
action(types.ADBLOCK_VIEW_SUBSCRIPTION_SOURCE, {
listUrl
listUrl,
})
+10 -9
View File
@@ -14,22 +14,22 @@ import App from './components/app'
import store from './store'
import * as adblockActions from './actions/adblock_actions'
function getCustomFilters () {
function getCustomFilters() {
const actions = bindActionCreators(adblockActions, store.dispatch.bind(store))
actions.getCustomFilters()
}
function getRegionalLists () {
function getRegionalLists() {
const actions = bindActionCreators(adblockActions, store.dispatch.bind(store))
actions.getRegionalLists()
}
function getListSubscriptions () {
function getListSubscriptions() {
const actions = bindActionCreators(adblockActions, store.dispatch.bind(store))
actions.getListSubscriptions()
}
function initialize () {
function initialize() {
getCustomFilters()
getRegionalLists()
getListSubscriptions()
@@ -37,20 +37,21 @@ function initialize () {
<Provider store={store}>
<App />
</Provider>,
document.getElementById('root'))
document.getElementById('root'),
)
}
function onGetCustomFilters (customFilters: string) {
function onGetCustomFilters(customFilters: string) {
const actions = bindActionCreators(adblockActions, store.dispatch.bind(store))
actions.onGetCustomFilters(customFilters)
}
function onGetRegionalLists (regionalLists: AdBlock.FilterList[]) {
function onGetRegionalLists(regionalLists: AdBlock.FilterList[]) {
const actions = bindActionCreators(adblockActions, store.dispatch.bind(store))
actions.onGetRegionalLists(regionalLists)
}
function onGetListSubscriptions (listSubscriptions: AdBlock.SubscriptionInfo[]) {
function onGetListSubscriptions(listSubscriptions: AdBlock.SubscriptionInfo[]) {
const actions = bindActionCreators(adblockActions, store.dispatch.bind(store))
actions.onGetListSubscriptions(listSubscriptions)
}
@@ -61,7 +62,7 @@ function onGetListSubscriptions (listSubscriptions: AdBlock.SubscriptionInfo[])
window.brave_adblock = {
onGetCustomFilters,
onGetRegionalLists,
onGetListSubscriptions
onGetListSubscriptions,
}
document.addEventListener('DOMContentLoaded', initialize)
@@ -10,15 +10,18 @@ interface Props {
}
export class AdBlockItem extends React.Component<Props, {}> {
constructor (props: Props) {
constructor(props: Props) {
super(props)
}
onChange = (event: React.ChangeEvent<HTMLInputElement>) => {
this.props.actions.enableFilterList(this.props.resource.uuid, event.target.checked)
this.props.actions.enableFilterList(
this.props.resource.uuid,
event.target.checked,
)
}
render () {
render() {
return (
<div>
<label>
@@ -14,33 +14,27 @@ interface Props {
}
export class AdBlockItemList extends React.Component<Props, {}> {
constructor (props: Props) {
constructor(props: Props) {
super(props)
}
render () {
render() {
const regionalLists = this.props.resources.map((resource) => (
<AdBlockItem
actions={this.props.actions}
key={resource.uuid}
resource={resource}
/>)
)
/>
))
return (
<div>
<div
style={{ fontSize: '18px', marginTop: '20px' }}
>
<div style={{ fontSize: '18px', marginTop: '20px' }}>
{getLocale('additionalFiltersTitle')}
</div>
<div
style={{ fontWeight: 'bold' }}
>
<div style={{ fontWeight: 'bold' }}>
{getLocale('additionalFiltersWarning')}
</div>
<div style={{ marginTop: '10px' }} >
{regionalLists}
</div>
<div style={{ marginTop: '10px' }}>{regionalLists}</div>
</div>
)
}
@@ -20,15 +20,15 @@ interface Props {
}
export class AdblockPage extends React.Component<Props, {}> {
constructor (props: Props) {
constructor(props: Props) {
super(props)
}
get actions () {
get actions() {
return this.props.actions
}
render () {
render() {
const { actions, adblockData } = this.props
return (
<div id='adblockPage'>
@@ -50,14 +50,11 @@ export class AdblockPage extends React.Component<Props, {}> {
}
export const mapStateToProps = (state: AdBlock.ApplicationState) => ({
adblockData: state.adblockData
adblockData: state.adblockData,
})
export const mapDispatchToProps = (dispatch: Dispatch) => ({
actions: bindActionCreators(adblockActions, dispatch)
actions: bindActionCreators(adblockActions, dispatch),
})
export default connect(
mapStateToProps,
mapDispatchToProps
)(AdblockPage)
export default connect(mapStateToProps, mapDispatchToProps)(AdblockPage)
@@ -11,7 +11,7 @@ interface Props {
}
export class CustomFilters extends React.Component<Props, {}> {
constructor (props: Props) {
constructor(props: Props) {
super(props)
}
@@ -19,17 +19,13 @@ export class CustomFilters extends React.Component<Props, {}> {
this.props.actions.updateCustomFilters(event.target.value)
}
render () {
render() {
return (
<div>
<div
style={{ fontSize: '18px', marginTop: '20px' }}
>
<div style={{ fontSize: '18px', marginTop: '20px' }}>
{getLocale('customFiltersTitle')}
</div>
<div
style={{ fontWeight: 'bold' }}
>
<div style={{ fontWeight: 'bold' }}>
{getLocale('customFiltersInstructions')}
</div>
<textarea
@@ -20,12 +20,12 @@ interface State {
}
export class CustomSubscriptions extends React.Component<Props, State> {
constructor (props: Props) {
constructor(props: Props) {
super(props)
this.state = {
currentlyAddingSubscription: false,
newSubscriptionUrl: '',
currentlyOpenedContextMenu: undefined
currentlyOpenedContextMenu: undefined,
}
}
@@ -38,7 +38,11 @@ export class CustomSubscriptions extends React.Component<Props, State> {
if (url.protocol !== 'https:' && url.protocol !== 'http:') {
return false
}
if (this.props.subscriptions.filter(subscription => subscription.subscription_url === url.href).length !== 0) {
if (
this.props.subscriptions.filter(
(subscription) => subscription.subscription_url === url.href,
).length !== 0
) {
return false
}
return true
@@ -51,7 +55,7 @@ export class CustomSubscriptions extends React.Component<Props, State> {
onStartAddSubscription = (event: React.MouseEvent<HTMLButtonElement>) => {
this.setState((state, props) => ({
...state,
currentlyAddingSubscription: true
currentlyAddingSubscription: true,
}))
}
@@ -59,7 +63,7 @@ export class CustomSubscriptions extends React.Component<Props, State> {
this.setState((state, props) => ({
...state,
currentlyAddingSubscription: false,
newSubscriptionUrl: ''
newSubscriptionUrl: '',
}))
}
@@ -67,7 +71,7 @@ export class CustomSubscriptions extends React.Component<Props, State> {
const newSubscriptionUrl = event.target.value
this.setState((state, props) => ({
...state,
newSubscriptionUrl
newSubscriptionUrl,
}))
}
@@ -76,50 +80,73 @@ export class CustomSubscriptions extends React.Component<Props, State> {
this.setState((state, props) => ({
...state,
currentlyAddingSubscription: false,
newSubscriptionUrl: ''
newSubscriptionUrl: '',
}))
}
onNewSubscriptionUrlKeyDown = (event: React.KeyboardEvent<HTMLInputElement>) => {
onNewSubscriptionUrlKeyDown = (
event: React.KeyboardEvent<HTMLInputElement>,
) => {
if (event.key === 'Enter' && this.newSubscriptionUrlValid()) {
this.props.actions.submitNewSubscription(this.state.newSubscriptionUrl)
this.setState((state, props) => ({
...state,
currentlyAddingSubscription: false,
newSubscriptionUrl: ''
newSubscriptionUrl: '',
}))
}
}
onToggleSubscription = (subscriptionUrl: string, event: React.ChangeEvent<HTMLInputElement>) => {
this.props.actions.setSubscriptionEnabled(subscriptionUrl, event.target.checked)
onToggleSubscription = (
subscriptionUrl: string,
event: React.ChangeEvent<HTMLInputElement>,
) => {
this.props.actions.setSubscriptionEnabled(
subscriptionUrl,
event.target.checked,
)
}
onClickSubscriptionContextMenu = (subscriptionUrl: string, event: React.MouseEvent<HTMLSpanElement>) => {
const currentlyOpenedContextMenu = (this.state.currentlyOpenedContextMenu === subscriptionUrl) ? undefined : subscriptionUrl
onClickSubscriptionContextMenu = (
subscriptionUrl: string,
event: React.MouseEvent<HTMLSpanElement>,
) => {
const currentlyOpenedContextMenu =
this.state.currentlyOpenedContextMenu === subscriptionUrl
? undefined
: subscriptionUrl
this.setState((state, props) => ({
...state,
currentlyOpenedContextMenu
currentlyOpenedContextMenu,
}))
}
onRefreshSubscription = (subscriptionUrl: string, event: React.MouseEvent<HTMLButtonElement>) => {
onRefreshSubscription = (
subscriptionUrl: string,
event: React.MouseEvent<HTMLButtonElement>,
) => {
this.props.actions.refreshSubscription(subscriptionUrl)
this.setState((state, props) => ({
...state,
currentlyOpenedContextMenu: undefined
currentlyOpenedContextMenu: undefined,
}))
}
onUnsubscribe = (subscriptionUrl: string, event: React.MouseEvent<HTMLButtonElement>) => {
onUnsubscribe = (
subscriptionUrl: string,
event: React.MouseEvent<HTMLButtonElement>,
) => {
this.props.actions.deleteSubscription(subscriptionUrl)
this.setState((state, props) => ({
...state,
currentlyOpenedContextMenu: undefined
currentlyOpenedContextMenu: undefined,
}))
}
onViewSource = (subscriptionUrl: string, event: React.MouseEvent<HTMLButtonElement>) => {
onViewSource = (
subscriptionUrl: string,
event: React.MouseEvent<HTMLButtonElement>,
) => {
this.props.actions.viewSubscriptionSource(subscriptionUrl)
}
@@ -146,16 +173,41 @@ export class CustomSubscriptions extends React.Component<Props, State> {
className='filterListGridCell'
style={{ gridRow, gridColumn: 2, color: '#bd1531' }}
>
<span title={'Last attempted ' + new Date(subscription.last_update_attempt).toISOString()}>{'Download failure'}</span>
<span
title={
'Last attempted '
+ new Date(subscription.last_update_attempt).toISOString()
}
>
{'Download failure'}
</span>
</div>
)
} else if (subscription.last_successful_update_attempt !== subscription.last_update_attempt) {
} else if (
subscription.last_successful_update_attempt
!== subscription.last_update_attempt
) {
lastUpdatedCell = (
<div
className='filterListGridCell'
style={{ gridRow, gridColumn: 2, color: '#bd1531' }}
>
<span title={'Last succeeded ' + new Date(subscription.last_successful_update_attempt).toISOString() + ', attempted ' + new Date(subscription.last_update_attempt).toISOString()}>{'Download failure since ' + formatDistanceToNow(new Date(subscription.last_successful_update_attempt)) + ' ago'}</span>
<span
title={
'Last succeeded '
+ new Date(
subscription.last_successful_update_attempt,
).toISOString()
+ ', attempted '
+ new Date(subscription.last_update_attempt).toISOString()
}
>
{'Download failure since '
+ formatDistanceToNow(
new Date(subscription.last_successful_update_attempt),
)
+ ' ago'}
</span>
</div>
)
} else {
@@ -164,87 +216,186 @@ export class CustomSubscriptions extends React.Component<Props, State> {
className='filterListGridCell'
style={{ gridRow, gridColumn: 2 }}
>
<span title={new Date(subscription.last_successful_update_attempt).toISOString()}>{formatDistanceToNow(new Date(subscription.last_successful_update_attempt)) + ' ago'}</span>
<span
title={new Date(
subscription.last_successful_update_attempt,
).toISOString()}
>
{formatDistanceToNow(
new Date(subscription.last_successful_update_attempt),
) + ' ago'}
</span>
</div>
)
}
const onToggleThisSubscription = (e: React.ChangeEvent<HTMLInputElement>) => this.onToggleSubscription(subscription.subscription_url, e)
const onClickThisContextMenu = (e: React.MouseEvent<HTMLSpanElement, MouseEvent>) => this.onClickSubscriptionContextMenu(subscription.subscription_url, e)
const onRefreshThisSubscription = (e: React.MouseEvent<HTMLButtonElement, MouseEvent>) => this.onRefreshSubscription(subscription.subscription_url, e)
const onViewThisSource = (e: React.MouseEvent<HTMLButtonElement, MouseEvent>) => this.onViewSource(subscription.subscription_url, e)
const onUnsubscribeThisList = (e: React.MouseEvent<HTMLButtonElement, MouseEvent>) => this.onUnsubscribe(subscription.subscription_url, e)
const onToggleThisSubscription = (
e: React.ChangeEvent<HTMLInputElement>,
) => this.onToggleSubscription(subscription.subscription_url, e)
const onClickThisContextMenu = (
e: React.MouseEvent<HTMLSpanElement, MouseEvent>,
) => this.onClickSubscriptionContextMenu(subscription.subscription_url, e)
const onRefreshThisSubscription = (
e: React.MouseEvent<HTMLButtonElement, MouseEvent>,
) => this.onRefreshSubscription(subscription.subscription_url, e)
const onViewThisSource = (
e: React.MouseEvent<HTMLButtonElement, MouseEvent>,
) => this.onViewSource(subscription.subscription_url, e)
const onUnsubscribeThisList = (
e: React.MouseEvent<HTMLButtonElement, MouseEvent>,
) => this.onUnsubscribe(subscription.subscription_url, e)
return (
<React.Fragment key={subscription.subscription_url}>
<div style={{ gridRow, gridColumn: '1 / span 4', borderBottom: '1px solid #e8e8e8' }}/>
<div className='filterListGridCell' style={{ gridRow, gridColumn: 1 }}>{subscription.subscription_url}</div>
<div
style={{
gridRow,
gridColumn: '1 / span 4',
borderBottom: '1px solid #e8e8e8',
}}
/>
<div
className='filterListGridCell'
style={{ gridRow, gridColumn: 1 }}
>
{subscription.subscription_url}
</div>
{lastUpdatedCell}
{
subscription.last_successful_update_attempt
? (<div className='filterListGridCell' style={{ gridRow, gridColumn: 3 }}><input type='checkbox' checked={subscription.enabled} onChange={onToggleThisSubscription}/></div>)
: (<></>)
}
<div className='filterListGridCell' style={{ gridRow, gridColumn: '4 / span 5' }}>
<span style={{ cursor: 'pointer', color: '#656565', userSelect: 'none', fontSize: '1.25em' }} onClick={onClickThisContextMenu}></span>
{
(subscription.subscription_url === this.state.currentlyOpenedContextMenu)
? (<div style={{ display: 'flex', flexDirection: 'column' }}>
<button onClick={onRefreshThisSubscription}>{getLocale('customListSubscriptionsTriggerUpdate')}</button>
{
subscription.last_successful_update_attempt
? <button onClick={onViewThisSource}>{getLocale('customListSubscriptionsViewListSource')}</button>
: <></>
}
<button onClick={onUnsubscribeThisList}>{getLocale('customListSubscriptionsUnsubscribe')}</button>
</div>)
: (<></>)
}
{subscription.last_successful_update_attempt ? (
<div
className='filterListGridCell'
style={{ gridRow, gridColumn: 3 }}
>
<input
type='checkbox'
checked={subscription.enabled}
onChange={onToggleThisSubscription}
/>
</div>
) : (
<></>
)}
<div
className='filterListGridCell'
style={{ gridRow, gridColumn: '4 / span 5' }}
>
<span
style={{
cursor: 'pointer',
color: '#656565',
userSelect: 'none',
fontSize: '1.25em',
}}
onClick={onClickThisContextMenu}
>
</span>
{subscription.subscription_url
=== this.state.currentlyOpenedContextMenu ? (
<div style={{ display: 'flex', flexDirection: 'column' }}>
<button onClick={onRefreshThisSubscription}>
{getLocale('customListSubscriptionsTriggerUpdate')}
</button>
{subscription.last_successful_update_attempt ? (
<button onClick={onViewThisSource}>
{getLocale('customListSubscriptionsViewListSource')}
</button>
) : (
<></>
)}
<button onClick={onUnsubscribeThisList}>
{getLocale('customListSubscriptionsUnsubscribe')}
</button>
</div>
) : (
<></>
)}
</div>
</React.Fragment>
)
})
return (
<>
<style>.filterListGridCell {'{'} padding: 6px 15px {'}'}</style>
<div style={{ display: 'grid', gridTemplateColumns: '50fr 30fr 3em 3em 9em' }}>
<div style={{ gridRow: 1, gridColumn: '1 / span 4', background: '#fafafa', borderBottom: '2px solid #e8e8e8', borderRadius: '4px 4px 0 0' }}/>
<div className='filterListGridCell' style={{ gridRow: 1, gridColumn: 1, fontWeight: 'bold' }}>{getLocale('customListSubscriptionsTableFilterListColumn')}</div>
<div className='filterListGridCell' style={{ gridRow: 1, gridColumn: 2, fontWeight: 'bold' }}>{getLocale('customListSubscriptionsTableLastUpdatedColumn')}</div>
<style>
.filterListGridCell {'{'} padding: 6px 15px {'}'}
</style>
<div
style={{
display: 'grid',
gridTemplateColumns: '50fr 30fr 3em 3em 9em',
}}
>
<div
style={{
gridRow: 1,
gridColumn: '1 / span 4',
background: '#fafafa',
borderBottom: '2px solid #e8e8e8',
borderRadius: '4px 4px 0 0',
}}
/>
<div
className='filterListGridCell'
style={{ gridRow: 1, gridColumn: 1, fontWeight: 'bold' }}
>
{getLocale('customListSubscriptionsTableFilterListColumn')}
</div>
<div
className='filterListGridCell'
style={{ gridRow: 1, gridColumn: 2, fontWeight: 'bold' }}
>
{getLocale('customListSubscriptionsTableLastUpdatedColumn')}
</div>
{rows}
</div>
</>
)
}
render () {
const addSubscriptionSection = this.state.currentlyAddingSubscription
? (
<>
<input autoFocus={true} value={this.state.newSubscriptionUrl} onChange={this.onChangeNewSubscriptionUrl} onKeyDown={this.onNewSubscriptionUrlKeyDown} placeholder={getLocale('customListSubscriptionsEnterSubscriptionUrlPlaceholder')}/>
<button disabled={!this.newSubscriptionUrlValid()} onClick={this.onSubmitNewSubscription}>{getLocale('customListSubscriptionsSubmitNewSubscription')}</button>
<button onClick={this.onCancelAddSubscription}>{getLocale('customListSubscriptionsCancelAddSubscription')}</button>
</>
)
: (<button onClick={this.onStartAddSubscription}>{getLocale('customListSubscriptionsAddNewFilterList')}</button>)
render() {
const addSubscriptionSection = this.state.currentlyAddingSubscription ? (
<>
<input
autoFocus={true}
value={this.state.newSubscriptionUrl}
onChange={this.onChangeNewSubscriptionUrl}
onKeyDown={this.onNewSubscriptionUrlKeyDown}
placeholder={getLocale(
'customListSubscriptionsEnterSubscriptionUrlPlaceholder',
)}
/>
<button
disabled={!this.newSubscriptionUrlValid()}
onClick={this.onSubmitNewSubscription}
>
{getLocale('customListSubscriptionsSubmitNewSubscription')}
</button>
<button onClick={this.onCancelAddSubscription}>
{getLocale('customListSubscriptionsCancelAddSubscription')}
</button>
</>
) : (
<button onClick={this.onStartAddSubscription}>
{getLocale('customListSubscriptionsAddNewFilterList')}
</button>
)
const existingListsSection = this.props.subscriptions.length === 0 ? (<></>) : this.renderTable(this.props.subscriptions)
const existingListsSection =
this.props.subscriptions.length === 0 ? (
<></>
) : (
this.renderTable(this.props.subscriptions)
)
return (
<div>
<div
style={{ fontSize: '18px', marginTop: '20px' }}
>
<div style={{ fontSize: '18px', marginTop: '20px' }}>
{getLocale('customListSubscriptionsTitle')}
</div>
<div>
{getLocale('customListSubscriptionsInstructions')}
</div>
<div>{getLocale('customListSubscriptionsInstructions')}</div>
{existingListsSection}
{addSubscriptionSection}
<div>
{getLocale('customListSubscriptionsDisclaimer')}
</div>
<div>{getLocale('customListSubscriptionsDisclaimer')}</div>
</div>
)
}
@@ -15,5 +15,5 @@ export const enum types {
ADBLOCK_SET_SUBSCRIPTION_ENABLED = '@@adblock/ADBLOCK_SET_SUBSCRIPTION_ENABLED',
ADBLOCK_DELETE_SUBSCRIPTION = '@@adblock/ADBLOCK_DELETE_SUBSCRIPTION',
ADBLOCK_REFRESH_SUBSCRIPTION = '@@adblock/ADBLOCK_REFRESH_SUBSCRIPTION',
ADBLOCK_VIEW_SUBSCRIPTION_SOURCE = '@@adblock/ADBLOCK_VIEW_SUBSCRIPTION_SOURCE'
ADBLOCK_VIEW_SUBSCRIPTION_SOURCE = '@@adblock/ADBLOCK_VIEW_SUBSCRIPTION_SOURCE',
}
@@ -15,7 +15,10 @@ const updateCustomFilters = debounce((customFilters: string) => {
chrome.send('brave_adblock.updateCustomFilters', [customFilters])
}, 1500)
const adblockReducer: Reducer<AdBlock.State | undefined> = (state: AdBlock.State | undefined, action) => {
const adblockReducer: Reducer<AdBlock.State | undefined> = (
state: AdBlock.State | undefined,
action,
) => {
if (state === undefined) {
state = storage.load()
}
@@ -23,15 +26,20 @@ const adblockReducer: Reducer<AdBlock.State | undefined> = (state: AdBlock.State
const startingState = state
switch (action.type) {
case types.ADBLOCK_ENABLE_FILTER_LIST:
chrome.send('brave_adblock.enableFilterList', [action.payload.uuid, action.payload.enabled])
chrome.send('brave_adblock.enableFilterList', [
action.payload.uuid,
action.payload.enabled,
])
state = {
...state,
settings: {
...state.settings,
regionalLists: state.settings.regionalLists.map(resource =>
resource.uuid === action.payload.uuid ? { ...resource, enabled: action.payload.enabled } : resource
)
}
regionalLists: state.settings.regionalLists.map((resource) =>
resource.uuid === action.payload.uuid
? { ...resource, enabled: action.payload.enabled }
: resource,
),
},
}
break
case types.ADBLOCK_GET_CUSTOM_FILTERS:
@@ -44,10 +52,15 @@ const adblockReducer: Reducer<AdBlock.State | undefined> = (state: AdBlock.State
chrome.send('brave_adblock.getListSubscriptions')
break
case types.ADBLOCK_SUBMIT_NEW_SUBSCRIPTION:
chrome.send('brave_adblock.submitNewSubscription', [action.payload.listUrl])
chrome.send('brave_adblock.submitNewSubscription', [
action.payload.listUrl,
])
break
case types.ADBLOCK_SET_SUBSCRIPTION_ENABLED:
chrome.send('brave_adblock.setSubscriptionEnabled', [action.payload.listUrl, action.payload.enabled])
chrome.send('brave_adblock.setSubscriptionEnabled', [
action.payload.listUrl,
action.payload.enabled,
])
break
case types.ADBLOCK_DELETE_SUBSCRIPTION:
chrome.send('brave_adblock.deleteSubscription', [action.payload.listUrl])
@@ -56,19 +69,45 @@ const adblockReducer: Reducer<AdBlock.State | undefined> = (state: AdBlock.State
chrome.send('brave_adblock.refreshSubscription', [action.payload.listUrl])
break
case types.ADBLOCK_VIEW_SUBSCRIPTION_SOURCE:
chrome.send('brave_adblock.viewSubscriptionSource', [action.payload.listUrl])
chrome.send('brave_adblock.viewSubscriptionSource', [
action.payload.listUrl,
])
break
case types.ADBLOCK_ON_GET_CUSTOM_FILTERS:
state = { ...state, settings: { ...state.settings, customFilters: action.payload.customFilters } }
state = {
...state,
settings: {
...state.settings,
customFilters: action.payload.customFilters,
},
}
break
case types.ADBLOCK_ON_GET_REGIONAL_LISTS:
state = { ...state, settings: { ...state.settings, regionalLists: action.payload.regionalLists } }
state = {
...state,
settings: {
...state.settings,
regionalLists: action.payload.regionalLists,
},
}
break
case types.ADBLOCK_ON_GET_LIST_SUBSCRIPTIONS:
state = { ...state, settings: { ...state.settings, listSubscriptions: action.payload.listSubscriptions } }
state = {
...state,
settings: {
...state.settings,
listSubscriptions: action.payload.listSubscriptions,
},
}
break
case types.ADBLOCK_UPDATE_CUSTOM_FILTERS:
state = { ...state, settings: { ...state.settings, customFilters: action.payload.customFilters } }
state = {
...state,
settings: {
...state.settings,
customFilters: action.payload.customFilters,
},
}
updateCustomFilters(state.settings.customFilters)
break
default:
@@ -8,5 +8,5 @@ import { combineReducers } from 'redux'
import adblockReducer from './adblock_reducer'
export default combineReducers<AdBlock.ApplicationState>({
adblockData: adblockReducer
adblockData: adblockReducer,
})
+2 -2
View File
@@ -10,8 +10,8 @@ export const defaultState: AdBlock.State = {
settings: {
customFilters: '',
regionalLists: [],
listSubscriptions: []
}
listSubscriptions: [],
},
}
export const load = (): AdBlock.State => {