From 476544592104a7c233a87244b5690ebeaf8fdd03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABl=20Gangloff?= Date: Sat, 3 Aug 2024 21:50:07 +0200 Subject: [PATCH] refactor: split Sider from App.tsx --- assets/App.tsx | 158 +--------------------------------- assets/components/Sider.tsx | 163 ++++++++++++++++++++++++++++++++++++ 2 files changed, 166 insertions(+), 155 deletions(-) create mode 100644 assets/components/Sider.tsx diff --git a/assets/App.tsx b/assets/App.tsx index 22a0482..0a60082 100644 --- a/assets/App.tsx +++ b/assets/App.tsx @@ -1,21 +1,4 @@ -import {Badge, Layout, Menu, theme} from "antd"; -import { - ApiOutlined, - BankOutlined, - CloudServerOutlined, - CompassOutlined, - FileProtectOutlined, - FileSearchOutlined, - HomeOutlined, - InfoCircleOutlined, - LineChartOutlined, - LoginOutlined, - LogoutOutlined, - QuestionCircleOutlined, - SearchOutlined, - TeamOutlined, - UserOutlined -} from "@ant-design/icons"; +import {Layout, theme} from "antd"; import {Link, Navigate, Route, Routes, useLocation, useNavigate} from "react-router-dom"; import TextPage from "./pages/TextPage"; import DomainSearchPage from "./pages/search/DomainSearchPage"; @@ -30,9 +13,8 @@ import {getUser} from "./utils/api"; import LoginPage, {AuthenticatedContext} from "./pages/LoginPage"; import ConnectorsPage from "./pages/tracking/ConnectorsPage"; import NotFoundPage from "./pages/NotFoundPage"; -import {ItemType, MenuItemType} from "antd/lib/menu/interface"; -import {t} from 'ttag' import useBreakpoint from "./hooks/useBreakpoint"; +import {Sider} from "./components/Sider"; export default function App() { const { @@ -67,145 +49,11 @@ export default function App() { }, []); - const menuItems: ItemType[] = [ - { - key: 'home', - label: t`Home`, - icon: , - onClick: () => navigate('/home') - }, - { - key: 'search', - label: t`Search`, - icon: , - children: [ - { - key: 'domain-finder', - icon: , - label: t`Domain`, - title: t`Domain Finder`, - disabled: !isAuthenticated, - onClick: () => navigate('/search/domain') - }, - { - key: 'entity-finder', - icon: , - label: t`Entity`, - title: t`Entity Finder`, - disabled: !isAuthenticated, - onClick: () => navigate('/search/entity') - }, - { - key: 'ns-finder', - icon: , - label: t`Nameserver`, - title: t`Nameserver Finder`, - disabled: !isAuthenticated, - onClick: () => navigate('/search/nameserver') - } - ] - }, - { - key: 'info', - label: t`Information`, - icon: , - children: [ - { - key: 'tld-list', - icon: , - label: t`TLD`, - title: t`TLD list`, - disabled: !isAuthenticated, - onClick: () => navigate('/info/tld') - }, - { - key: 'stats', - icon: , - label: t`Statistics`, - disabled: !isAuthenticated, - onClick: () => navigate('/info/stats') - } - ] - }, - { - key: 'tracking', - label: t`Tracking`, - icon: , - children: [ - { - key: 'watchlist', - icon: , - label: t`My Watchlists`, - disabled: !isAuthenticated, - onClick: () => navigate('/tracking/watchlist') - }, - { - key: 'connectors', - icon: , - label: t`My Connectors`, - disabled: !isAuthenticated, - onClick: () => navigate('/tracking/connectors') - } - ] - }, - { - key: 'watchdog', - label: t`My Watchdog`, - icon: , - children: [ - { - key: 'account', - icon: , - label: t`My Account`, - disabled: !isAuthenticated, - onClick: () => navigate('/user') - }, - { - key: 'tos', - icon: , - label: t`TOS`, - onClick: () => navigate('/tos') - }, - { - key: 'privacy', - icon: , - label: t`Privacy Policy`, - onClick: () => navigate('/privacy') - } - ] - }, - { - key: '5', - icon: , - label: t`FAQ`, - onClick: () => navigate('/faq') - }, - - ] - - return {/* Ant will use a break-off tab to toggle the collapse of the sider when collapseWidth = 0*/} - , - label: t`Log out`, - danger: true, - onClick: () => window.location.replace("/logout") - } : { - key: '8', - icon: , - label: t`Log in`, - onClick: () => navigate('/login') - }]} - /> + diff --git a/assets/components/Sider.tsx b/assets/components/Sider.tsx new file mode 100644 index 0000000..3290db1 --- /dev/null +++ b/assets/components/Sider.tsx @@ -0,0 +1,163 @@ +import {ItemType, MenuItemType} from "antd/lib/menu/interface"; +import {t} from "ttag"; +import { + ApiOutlined, + BankOutlined, + CloudServerOutlined, + CompassOutlined, + FileProtectOutlined, + FileSearchOutlined, + HomeOutlined, + InfoCircleOutlined, + LineChartOutlined, + LoginOutlined, + LogoutOutlined, + QuestionCircleOutlined, + SearchOutlined, + TeamOutlined, + UserOutlined +} from "@ant-design/icons"; +import {Badge, Menu} from "antd"; +import React from "react"; +import {useNavigate} from "react-router-dom"; + +export function Sider({isAuthenticated}: { isAuthenticated: boolean }) { + const navigate = useNavigate() + + + const menuItems: ItemType[] = [ + { + key: 'home', + label: t`Home`, + icon: , + onClick: () => navigate('/home') + }, + { + key: 'search', + label: t`Search`, + icon: , + children: [ + { + key: 'domain-finder', + icon: , + label: t`Domain`, + title: t`Domain Finder`, + disabled: !isAuthenticated, + onClick: () => navigate('/search/domain') + }, + { + key: 'entity-finder', + icon: , + label: t`Entity`, + title: t`Entity Finder`, + disabled: true, + onClick: () => navigate('/search/entity') + }, + { + key: 'ns-finder', + icon: , + label: t`Nameserver`, + title: t`Nameserver Finder`, + disabled: true, + onClick: () => navigate('/search/nameserver') + } + ] + }, + { + key: 'info', + label: t`Information`, + icon: , + children: [ + { + key: 'tld-list', + icon: , + label: t`TLD`, + title: t`TLD list`, + disabled: !isAuthenticated, + onClick: () => navigate('/info/tld') + }, + { + key: 'stats', + icon: , + label: t`Statistics`, + disabled: true, + onClick: () => navigate('/info/stats') + } + ] + }, + { + key: 'tracking', + label: t`Tracking`, + icon: , + children: [ + { + key: 'watchlist', + icon: , + label: t`My Watchlists`, + disabled: !isAuthenticated, + onClick: () => navigate('/tracking/watchlist') + }, + { + key: 'connectors', + icon: , + label: t`My Connectors`, + disabled: !isAuthenticated, + onClick: () => navigate('/tracking/connectors') + } + ] + }, + { + key: 'watchdog', + label: t`My Watchdog`, + icon: , + children: [ + { + key: 'account', + icon: , + label: t`My Account`, + disabled: !isAuthenticated, + onClick: () => navigate('/user') + }, + { + key: 'tos', + icon: , + label: t`TOS`, + onClick: () => navigate('/tos') + }, + { + key: 'privacy', + icon: , + label: t`Privacy Policy`, + onClick: () => navigate('/privacy') + } + ] + }, + { + key: '5', + icon: , + label: t`FAQ`, + onClick: () => navigate('/faq') + }, + + ] + + return , + label: t`Log out`, + danger: true, + onClick: () => window.location.replace("/logout") + } : { + key: '8', + icon: , + label: t`Log in`, + onClick: () => navigate('/login') + }]} + /> + +} \ No newline at end of file