feat(web): replace react-portal with own implementation (#1862)

* feat(web): replace react-portal with own implementation

* chore: add missing license headers
This commit is contained in:
ze0s 2024-12-07 18:05:56 +01:00 committed by GitHub
parent ab718b8232
commit 172fa651af
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 113 additions and 99 deletions

View file

@ -7,11 +7,11 @@ import { useEffect } from "react";
import { RouterProvider } from "@tanstack/react-router"
import { QueryClientProvider } from "@tanstack/react-query";
import { Toaster } from "react-hot-toast";
import { Portal } from "react-portal";
import { Router } from "@app/routes";
import { routerBasePath } from "@utils";
import { queryClient } from "@api/QueryClient";
import { SettingsContext } from "@utils/Context";
import { Portal } from "@components/portal";
declare module '@tanstack/react-router' {
interface Register {

View file

@ -0,0 +1,25 @@
/*
* Copyright (c) 2021 - 2024, Ludvig Lundgren and the autobrr contributors.
* SPDX-License-Identifier: GPL-2.0-or-later
*/
import { useEffect, ReactNode } from "react";
import { createPortal } from "react-dom";
interface PortalProps {
children?: ReactNode;
}
export const Portal = ({children }: PortalProps) => {
const mount = document.getElementById("portal-root");
const el = document.createElement("div");
useEffect(() => {
mount?.appendChild(el);
return () => {
mount?.removeChild(el);
}
}, [el, mount]);
return createPortal(children, el)
};

View file

@ -0,0 +1,6 @@
/*
* Copyright (c) 2021 - 2024, Ludvig Lundgren and the autobrr contributors.
* SPDX-License-Identifier: GPL-2.0-or-later
*/
export { Portal } from "./Portal"