import React, { useState } from 'react'; import { useTranslation } from 'react-i18next'; import { useDispatch, useSelector } from 'react-redux'; import cn from 'classnames'; import { REPOSITORY, PRIVACY_POLICY_LINK, THEMES } from '../../helpers/constants'; import { LANGUAGES } from '../../helpers/twosky'; import i18n from '../../i18n'; import Version from './Version'; import './Footer.css'; import './Select.css'; import { setHtmlLangAttr, setUITheme } from '../../helpers/helpers'; import { changeTheme } from '../../actions'; import { RootState } from '../../initialState'; const linksData = [ { href: REPOSITORY.URL, name: 'homepage', }, { href: PRIVACY_POLICY_LINK, name: 'privacy_policy', }, { href: REPOSITORY.ISSUES, className: 'btn btn-outline-primary btn-sm footer__link--report', name: 'report_an_issue', }, ]; const Footer = () => { const { t } = useTranslation(); const dispatch = useDispatch(); const currentTheme = useSelector((state: RootState) => (state.dashboard ? state.dashboard.theme : THEMES.auto)); const profileName = useSelector((state: RootState) => (state.dashboard ? state.dashboard.name : '')); const isLoggedIn = profileName !== ''; const [currentThemeLocal, setCurrentThemeLocal] = useState(THEMES.auto); const getYear = () => { const today = new Date(); return today.getFullYear(); }; const changeLanguage = (event: any) => { const { value } = event.target; i18n.changeLanguage(value); setHtmlLangAttr(value); }; const onThemeChange = (value: any) => { if (isLoggedIn) { dispatch(changeTheme(value)); } else { setUITheme(value); setCurrentThemeLocal(value); } }; const renderCopyright = () => (
{t('copyright')} © {getYear()}{' '} AdGuard
); const renderLinks = (linksData: any) => linksData.map(({ name, href, className = '' }: any) => ( {t(name)} )); const renderThemeButtons = () => { const currentValue = isLoggedIn ? currentTheme : currentThemeLocal; const content = { auto: { desc: t('theme_auto_desc'), icon: '#auto', }, dark: { desc: t('theme_dark_desc'), icon: '#dark', }, light: { desc: t('theme_light_desc'), icon: '#light', }, }; return Object.values(THEMES) .map((theme: any) => ( )); }; return ( <>
{renderCopyright()}
); }; export default Footer;