From ad8a99c291cd4094efac2a813e2a9727163d79a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABl=20Gangloff?= Date: Fri, 20 Dec 2024 20:21:05 +0100 Subject: [PATCH] feat: add dark theme support --- assets/App.tsx | 126 ++++++++++++--------- assets/components/search/DomainDiagram.tsx | 2 +- src/Service/RDAPService.php | 3 +- 3 files changed, 74 insertions(+), 57 deletions(-) diff --git a/assets/App.tsx b/assets/App.tsx index 6c0ebab..1fbb872 100644 --- a/assets/App.tsx +++ b/assets/App.tsx @@ -1,4 +1,4 @@ -import {Button, Layout, Space, theme, Typography} from "antd"; +import {Button, ConfigProvider, Layout, Space, theme, 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"; @@ -21,9 +21,6 @@ const ProjectLink = D const LicenseLink = AGPL-3.0-or-later export default function App() { - const { - token: {colorBgContainer, borderRadiusLG}, - } = theme.useToken() const navigate = useNavigate() const location = useLocation() @@ -32,7 +29,6 @@ export default function App() { const [isAuthenticated, setIsAuthenticated] = useState(false) - const authenticated = useCallback((authenticated: boolean) => { setIsAuthenticated(authenticated) }, []); @@ -42,6 +38,23 @@ export default function App() { 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) + }, []) useEffect(() => { getUser().then(() => { @@ -52,63 +65,66 @@ export default function App() { 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*/} - - - - - - -
+ return + + + {/* Ant will use a break-off tab to toggle the collapse of the sider when collapseWidth = 0*/} + + + + + + +
+ + }/> + }/> - - }/> - }/> + }/> + }/> + }/> + }/> - }/> - }/> - }/> - }/> + }/> + }/> - }/> - }/> + }/> + }/> - }/> - }/> + }/> + }/> + }/> - }/> - }/> - }/> + }/> - }/> - - }/> - -
-
- - - - - - - - - {jt`${ProjectLink} is an open source project distributed under the ${LicenseLink} license.`} - - + }/> + +
+
+ + + + + + + + + {jt`${ProjectLink} is an open source project distributed under the ${LicenseLink} license.`} + + +
- -
+ + } \ No newline at end of file diff --git a/assets/components/search/DomainDiagram.tsx b/assets/components/search/DomainDiagram.tsx index d52da76..21442fb 100644 --- a/assets/components/search/DomainDiagram.tsx +++ b/assets/components/search/DomainDiagram.tsx @@ -36,7 +36,7 @@ export function DomainDiagram({domain}: { domain: Domain }) { return registerEntity($rdapEntity); + $this->em->flush(); $domainEntity = $this->domainEntityRepository->findOneBy([ 'domain' => $domain, @@ -327,6 +328,7 @@ readonly class RDAPService continue; } $entity = $this->registerEntity($rdapEntity); + $this->em->flush(); $nameserverEntity = $this->nameserverEntityRepository->findOneBy([ 'nameserver' => $nameserver, @@ -477,7 +479,6 @@ readonly class RDAPService } $this->em->persist($entity); - $this->em->flush(); if (isset($domainEntities)) { /** @var DomainEntity[] $domainEntities */