import React from 'react'; import { useDispatch, useSelector } from 'react-redux'; import { Button, Form, Icon, Message, Segment, Radio } from 'semantic-ui-react'; import ToastContext from '../../components/toasts/ToastContext'; import Headline from '../../components/headline/Headline'; import { xhrPost } from '../../services/xhr'; import { SegmentPart } from '../../components/segment/SegmentPart'; import './GeneralSettings.less'; const GeneralSettings = function Users() { const dispatch = useDispatch(); const [loading, setLoading] = React.useState(true); const settings = useSelector((state) => state.generalSettings.settings); const [interval, setInterval] = React.useState(''); const [port, setPort] = React.useState(''); const [scrapingAntApiKey, setScrapingAntApiKey] = React.useState(''); const [scrapingAntProxy, setScrapingAntProxy] = React.useState(''); const [workingHourFrom, setWorkingHourFrom] = React.useState(null); const [workingHourTo, setWorkingHourTo] = React.useState(null); const ctx = React.useContext(ToastContext); React.useEffect(() => { async function init() { await dispatch.generalSettings.getGeneralSettings(); setLoading(false); } init(); }, []); React.useEffect(() => { async function init() { setInterval(settings?.interval); setPort(settings?.port); setScrapingAntApiKey(settings?.scrapingAnt?.apiKey); setWorkingHourFrom(settings?.workingHours?.from); setWorkingHourTo(settings?.workingHours?.to); setScrapingAntProxy(settings?.scrapingAnt?.proxy || 'datacenter'); } init(); }, [settings]); const nullOrEmpty = (val) => val == null || val.length === 0; const throwMessage = (message, type) => { ctx.showToast({ title: type === 'error' ? 'Error' : 'Success', message: message, delay: 5000, backgroundColor: type === 'error' ? '#db2828' : '#87eb8f', color: type === 'error' ? '#fff' : '#000', }); }; const onStore = async () => { if (nullOrEmpty(interval)) { throwMessage('Interval may not be empty.', 'error'); return; } if (nullOrEmpty(port)) { throwMessage('Port may not be empty.', 'error'); return; } if ( (!nullOrEmpty(workingHourFrom) && nullOrEmpty(workingHourTo)) || (nullOrEmpty(workingHourFrom) && !nullOrEmpty(workingHourTo)) ) { throwMessage('Working hours to and from must be set if either to or from has been set before.', 'error'); return; } try { await xhrPost('/api/admin/generalSettings', { interval, port, scrapingAnt: { apiKey: scrapingAntApiKey, proxy: scrapingAntProxy, }, workingHours: { from: workingHourFrom, to: workingHourTo, }, }); } catch (exception) { console.error(exception); throwMessage('Error while trying to store settings.', 'error'); return; } throwMessage('Settings stored successfully. You MUST restart Fredy.', 'success'); }; return (
{!loading && (
Info

If you change any settings, you must restart Fredy afterwards.

setInterval(e.target.value)} /> setPort(e.target.value)} /> setScrapingAntApiKey(e.target.value)} /> ScrapingAnt is needed to scrape Immoscout. ScrapingAnt itself is using 2 different types of proxies.{' '}

Datacenter-Proxy

Proxy server located in one of the datacenters across the world. Datacenter proxies are slower and more likely to fail, but they are cheaper. A call with a datacenter proxy cost 10 credits.

Residential-Proxy

High-quality proxy server located in one of the real people houses across the world. Datacenter proxies are faster and more likely to success, but they are more expensive. A call with a datacenter proxy cost 250 credits.

On the free tier, you have 10.000 credits, so chose your option wisely. Keep in mind, only successful calls will be charged.
setScrapingAntProxy(value)} /> setScrapingAntProxy(value)} />
setWorkingHourFrom(e.target.value)} />
until
setWorkingHourTo(e.target.value)} />
)}
); }; export default GeneralSettings;