import React, { Component, Fragment } from 'react'; import PropTypes from 'prop-types'; import Upstream from './Upstream'; import Checkbox from '../ui/Checkbox'; import Loading from '../ui/Loading'; import PageTitle from '../ui/PageTitle'; import Card from '../ui/Card'; import './Settings.css'; export default class Settings extends Component { settings = { filtering: { enabled: false, title: 'Block domains using filters and hosts files', subtitle: 'You can setup blocking rules in the Filters settings.', }, safebrowsing: { enabled: false, title: 'Use AdGuard browsing security web service', subtitle: 'AdGuard DNS will check if domain is blacklisted by the browsing security web service (sb.adtidy.org). It will use privacy-safe lookup API to do the check.', }, parental: { enabled: false, title: 'Use AdGuard parental control web service', subtitle: 'AdGuard DNS will check if domain contains adult materials. It uses the same privacy-friendly API as the browsing security web service.', }, safesearch: { enabled: false, title: 'Enforce safe search', subtitle: 'AdGuard DNS can enforce safe search in the major search engines: Google, Bing, Yandex.', }, }; componentDidMount() { this.props.initSettings(this.settings); } handleUpstreamChange = (value) => { this.props.handleUpstreamChange({ upstream: value }); }; handleUpstreamSubmit = () => { this.props.setUpstream(this.props.settings.upstream); }; handleUpstreamTest = () => { this.props.testUpstream(this.props.settings.upstream); }; renderSettings = (settings) => { if (Object.keys(settings).length > 0) { return Object.keys(settings).map((key) => { const setting = settings[key]; const { enabled } = setting; return ( this.props.toggleSetting(key, enabled)} />); }); } return (
No settings
); } render() { const { settings, upstream } = this.props; return ( {settings.processing && } {!settings.processing &&
{this.renderSettings(settings.settingsList)}
}
); } } Settings.propTypes = { initSettings: PropTypes.func, settings: PropTypes.object, settingsList: PropTypes.object, toggleSetting: PropTypes.func, handleUpstreamChange: PropTypes.func, setUpstream: PropTypes.func, upstream: PropTypes.string, };