2024-08-04 02:10:47 +02:00
|
|
|
import {Button, Layout, Space, theme, Typography} from "antd";
|
2024-07-26 23:55:12 +02:00
|
|
|
import {Link, Navigate, Route, Routes, useLocation, useNavigate} from "react-router-dom";
|
2024-07-26 16:45:10 +02:00
|
|
|
import TextPage from "./pages/TextPage";
|
|
|
|
|
import DomainSearchPage from "./pages/search/DomainSearchPage";
|
|
|
|
|
import EntitySearchPage from "./pages/search/EntitySearchPage";
|
|
|
|
|
import NameserverSearchPage from "./pages/search/NameserverSearchPage";
|
|
|
|
|
import TldPage from "./pages/info/TldPage";
|
|
|
|
|
import StatisticsPage from "./pages/info/StatisticsPage";
|
2024-07-27 17:19:25 +02:00
|
|
|
import WatchlistPage from "./pages/tracking/WatchlistPage";
|
2024-07-26 23:55:12 +02:00
|
|
|
import UserPage from "./pages/watchdog/UserPage";
|
2024-07-26 18:31:47 +02:00
|
|
|
import React, {useCallback, useEffect, useMemo, useState} from "react";
|
2024-07-26 16:45:10 +02:00
|
|
|
import {getUser} from "./utils/api";
|
2024-07-26 18:31:47 +02:00
|
|
|
import LoginPage, {AuthenticatedContext} from "./pages/LoginPage";
|
|
|
|
|
import ConnectorsPage from "./pages/tracking/ConnectorsPage";
|
|
|
|
|
import NotFoundPage from "./pages/NotFoundPage";
|
2024-07-30 06:13:31 +02:00
|
|
|
import useBreakpoint from "./hooks/useBreakpoint";
|
2024-08-03 21:50:07 +02:00
|
|
|
import {Sider} from "./components/Sider";
|
2024-08-04 02:10:47 +02:00
|
|
|
import {jt, t} from "ttag";
|
|
|
|
|
|
|
|
|
|
const ProjectLink = <Link to='https://github.com/maelgangloff/domain-watchdog'>Domain Watchdog</Link>
|
|
|
|
|
const LicenseLink = <Link to='https://www.gnu.org/licenses/agpl-3.0.txt'>AGPL-3.0-or-later</Link>
|
2024-07-26 16:45:10 +02:00
|
|
|
|
|
|
|
|
export default function App() {
|
|
|
|
|
const {
|
|
|
|
|
token: {colorBgContainer, borderRadiusLG},
|
|
|
|
|
} = theme.useToken()
|
2024-07-26 18:31:47 +02:00
|
|
|
|
2024-07-26 16:45:10 +02:00
|
|
|
const navigate = useNavigate()
|
2024-07-26 18:31:47 +02:00
|
|
|
const location = useLocation()
|
2024-07-30 06:13:31 +02:00
|
|
|
const sm = useBreakpoint('sm')
|
2024-07-26 18:31:47 +02:00
|
|
|
|
2024-07-26 23:55:12 +02:00
|
|
|
|
|
|
|
|
const [isAuthenticated, setIsAuthenticated] = useState(false)
|
|
|
|
|
|
|
|
|
|
|
2024-07-26 18:31:47 +02:00
|
|
|
const authenticated = useCallback((authenticated: boolean) => {
|
|
|
|
|
setIsAuthenticated(authenticated)
|
|
|
|
|
}, []);
|
2024-07-26 16:45:10 +02:00
|
|
|
|
2024-07-26 18:31:47 +02:00
|
|
|
const contextValue = useMemo(() => ({
|
|
|
|
|
authenticated,
|
|
|
|
|
setIsAuthenticated
|
|
|
|
|
}), [authenticated, setIsAuthenticated]);
|
2024-07-26 16:45:10 +02:00
|
|
|
|
|
|
|
|
useEffect(() => {
|
2024-07-26 18:31:47 +02:00
|
|
|
getUser().then(() => {
|
|
|
|
|
setIsAuthenticated(true)
|
2024-08-02 16:17:55 +02:00
|
|
|
if (location.pathname === '/login') navigate('/home')
|
2024-07-26 18:31:47 +02:00
|
|
|
}).catch(() => {
|
|
|
|
|
setIsAuthenticated(false)
|
2024-08-04 15:49:38 +02:00
|
|
|
if (location.pathname !== '/login') navigate('/home')
|
2024-07-26 18:31:47 +02:00
|
|
|
})
|
2024-07-26 16:45:10 +02:00
|
|
|
}, []);
|
|
|
|
|
|
|
|
|
|
|
2024-07-26 18:31:47 +02:00
|
|
|
return <AuthenticatedContext.Provider value={contextValue}>
|
|
|
|
|
<Layout hasSider style={{minHeight: '100vh'}}>
|
2024-07-30 06:13:31 +02:00
|
|
|
{/* Ant will use a break-off tab to toggle the collapse of the sider when collapseWidth = 0*/}
|
|
|
|
|
<Layout.Sider collapsible breakpoint="sm" {...(sm ? {collapsedWidth: 0} : {})}>
|
2024-08-03 21:50:07 +02:00
|
|
|
<Sider isAuthenticated={isAuthenticated}/>
|
2024-07-26 18:31:47 +02:00
|
|
|
</Layout.Sider>
|
|
|
|
|
<Layout>
|
|
|
|
|
<Layout.Header style={{padding: 0, background: colorBgContainer}}/>
|
2024-07-30 06:21:37 +02:00
|
|
|
<Layout.Content style={sm ? {margin: '24px 0'} : {margin: '24px 16px 0'}}>
|
2024-07-26 18:31:47 +02:00
|
|
|
<div style={{
|
|
|
|
|
padding: 24,
|
|
|
|
|
minHeight: 360,
|
|
|
|
|
background: colorBgContainer,
|
|
|
|
|
borderRadius: borderRadiusLG,
|
|
|
|
|
}}>
|
|
|
|
|
|
|
|
|
|
<Routes>
|
2024-07-27 12:59:40 +02:00
|
|
|
<Route path="/" element={<Navigate to="/login"/>}/>
|
2024-07-28 01:04:08 +02:00
|
|
|
<Route path="/home" element={<TextPage resource='home.md'/>}/>
|
2024-07-26 18:31:47 +02:00
|
|
|
|
|
|
|
|
<Route path="/search/domain" element={<DomainSearchPage/>}/>
|
|
|
|
|
<Route path="/search/entity" element={<EntitySearchPage/>}/>
|
|
|
|
|
<Route path="/search/nameserver" element={<NameserverSearchPage/>}/>
|
|
|
|
|
|
|
|
|
|
<Route path="/info/tld" element={<TldPage/>}/>
|
|
|
|
|
<Route path="/info/stats" element={<StatisticsPage/>}/>
|
|
|
|
|
|
2024-07-27 17:19:25 +02:00
|
|
|
<Route path="/tracking/watchlist" element={<WatchlistPage/>}/>
|
2024-07-26 18:31:47 +02:00
|
|
|
<Route path="/tracking/connectors" element={<ConnectorsPage/>}/>
|
|
|
|
|
|
|
|
|
|
<Route path="/user" element={<UserPage/>}/>
|
|
|
|
|
|
2024-07-28 01:04:08 +02:00
|
|
|
<Route path="/faq" element={<TextPage resource='faq.md'/>}/>
|
|
|
|
|
<Route path="/tos" element={<TextPage resource='tos.md'/>}/>
|
|
|
|
|
<Route path="/privacy" element={<TextPage resource='privacy.md'/>}/>
|
2024-07-26 18:31:47 +02:00
|
|
|
|
|
|
|
|
<Route path="/login" element={<LoginPage/>}/>
|
|
|
|
|
|
|
|
|
|
<Route path="*" element={<NotFoundPage/>}/>
|
|
|
|
|
</Routes>
|
|
|
|
|
</div>
|
|
|
|
|
</Layout.Content>
|
|
|
|
|
<Layout.Footer style={{textAlign: 'center'}}>
|
2024-08-04 01:32:58 +02:00
|
|
|
<Space size='middle'>
|
2024-08-04 01:35:04 +02:00
|
|
|
<Link to='/tos'><Button type='text'>{t`TOS`}</Button></Link>
|
2024-08-04 01:32:58 +02:00
|
|
|
<Link to='/privacy'><Button type='text'>{t`Privacy Policy`}</Button></Link>
|
|
|
|
|
<Link to='/faq'><Button type='text'>{t`FAQ`}</Button></Link>
|
2024-08-04 22:28:42 +02:00
|
|
|
<Typography.Link href='https://github.com/maelgangloff/domain-watchdog/wiki'><Button
|
|
|
|
|
type='text'>{t`Documentation`}</Button></Typography.Link>
|
2024-08-04 01:32:58 +02:00
|
|
|
</Space>
|
2024-08-05 01:30:27 +02:00
|
|
|
<Typography.Paragraph style={{marginTop: '1em'}}>
|
|
|
|
|
{jt`${ProjectLink} is an open source project distributed under the ${LicenseLink} license.`}
|
|
|
|
|
</Typography.Paragraph>
|
2024-07-26 18:31:47 +02:00
|
|
|
</Layout.Footer>
|
|
|
|
|
</Layout>
|
2024-07-26 16:45:10 +02:00
|
|
|
</Layout>
|
2024-07-26 18:31:47 +02:00
|
|
|
</AuthenticatedContext.Provider>
|
2024-07-26 16:45:10 +02:00
|
|
|
}
|