import {Button, ConfigProvider, FloatButton, Layout, Space, theme, Tooltip, Typography} from 'antd' import {Link, Navigate, Route, Routes, useLocation, useNavigate} from 'react-router-dom' import TextPage from './pages/TextPage' import DomainSearchPage from './pages/search/DomainSearchPage' import EntitySearchPage from './pages/search/EntitySearchPage' import TldPage from './pages/infrastructure/TldPage' import StatisticsPage from './pages/StatisticsPage' import WatchlistPage from './pages/tracking/WatchlistPage' import UserPage from './pages/UserPage' import React, {useCallback, useEffect, useMemo, useState} from 'react' import {getUser} from './utils/api' import LoginPage, {AuthenticatedContext} from './pages/LoginPage' import ConnectorPage from './pages/tracking/ConnectorPage' import NotFoundPage from './pages/NotFoundPage' import useBreakpoint from './hooks/useBreakpoint' import {Sider} from './components/Sider' import {jt, t} from 'ttag' import {BugOutlined, InfoCircleOutlined, MergeOutlined} from '@ant-design/icons' import TrackedDomainPage from './pages/tracking/TrackedDomainPage' import IcannRegistrarPage from "./pages/infrastructure/IcannRegistrarPage" const PROJECT_LINK = 'https://github.com/maelgangloff/domain-watchdog' const LICENSE_LINK = 'https://www.gnu.org/licenses/agpl-3.0.txt' const ProjectLink = Domain Watchdog const LicenseLink = AGPL-3.0-or-later export default function App(): React.ReactElement { const navigate = useNavigate() const location = useLocation() const sm = useBreakpoint('sm') const [isAuthenticated, setIsAuthenticated] = useState(false) const authenticated = useCallback((authenticated: boolean) => { setIsAuthenticated(authenticated) }, []) const contextValue = useMemo(() => ({ authenticated, setIsAuthenticated }), [authenticated, setIsAuthenticated]) const [darkMode, setDarkMode] = useState(false) const windowQuery = window.matchMedia('(prefers-color-scheme:dark)') const darkModeChange = useCallback((event: MediaQueryListEvent) => { setDarkMode(event.matches) }, []) useEffect(() => { windowQuery.addEventListener('change', darkModeChange) return () => { windowQuery.removeEventListener('change', darkModeChange) } }, [windowQuery, darkModeChange]) useEffect(() => { setDarkMode(windowQuery.matches) getUser().then(() => { setIsAuthenticated(true) if (location.pathname === '/login') navigate('/home') }).catch(() => { setIsAuthenticated(false) const pathname = location.pathname if (!['/login', '/tos', '/faq', '/privacy'].includes(pathname)) navigate('/home') }) }, []) return ( {/* Ant will use a break-off tab to toggle the collapse of the sider when collapseWidth = 0 */} }/> }/> }/> }/> }/> }/> }/> }/> }/> }/> }/> }/> }/> }/> }/> }/> }/> {t`TOS`} {t`Privacy Policy`} {t`FAQ`} {t`Documentation`} {jt`${ProjectLink} is an open source project distributed under the ${LicenseLink} license.`} } > } target='_blank' href={PROJECT_LINK}/> } target='_blank' href={PROJECT_LINK + '/issues'}/> ) }