mirror of
https://github.com/idanoo/autobrr
synced 2025-07-23 00:39:13 +00:00
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:
parent
ab718b8232
commit
172fa651af
6 changed files with 113 additions and 99 deletions
|
@ -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 {
|
||||
|
|
25
web/src/components/portal/Portal.tsx
Normal file
25
web/src/components/portal/Portal.tsx
Normal 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)
|
||||
};
|
6
web/src/components/portal/index.ts
Normal file
6
web/src/components/portal/index.ts
Normal 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"
|
Loading…
Add table
Add a link
Reference in a new issue