diff --git a/package.json b/package.json index 8d117ea9..a19b2fb8 100644 --- a/package.json +++ b/package.json @@ -19,6 +19,7 @@ ] }, "dependencies": { + "@dwelle/tunnel-rat": "0.1.1", "@sentry/browser": "6.2.5", "@sentry/integrations": "6.2.5", "@testing-library/jest-dom": "5.16.2", diff --git a/src/components/LayerUI.tsx b/src/components/LayerUI.tsx index 380c01c1..16151200 100644 --- a/src/components/LayerUI.tsx +++ b/src/components/LayerUI.tsx @@ -40,17 +40,12 @@ import { actionToggleStats } from "../actions/actionToggleStats"; import Footer from "./footer/Footer"; import { hostSidebarCountersAtom } from "./Sidebar/Sidebar"; import { jotaiScope } from "../jotai"; -import { useAtom } from "jotai"; +import { Provider, useAtom } from "jotai"; import MainMenu from "./main-menu/MainMenu"; import { ActiveConfirmDialog } from "./ActiveConfirmDialog"; import { HandButton } from "./HandButton"; import { isHandToolActive } from "../appState"; -import { - mainMenuTunnel, - welcomeScreenMenuHintTunnel, - welcomeScreenToolbarHintTunnel, - welcomeScreenCenterTunnel, -} from "./tunnels"; +import { TunnelsContext, useInitializeTunnels } from "./context/tunnels"; interface LayerUIProps { actionManager: ActionManager; @@ -130,6 +125,8 @@ const LayerUI = ({ }: LayerUIProps) => { const device = useDevice(); + const tunnels = useInitializeTunnels(); + const renderJSONExportDialog = () => { if (!UIOptions.canvasActions.export) { return null; @@ -201,8 +198,8 @@ const LayerUI = ({
( componentName: string, @@ -17,7 +18,8 @@ export const withInternalFallback =
(
__fallback?: boolean;
}
> = (props) => {
- const [counter, setCounter] = useAtom(counterAtom);
+ const { jotaiScope } = useTunnels();
+ const [counter, setCounter] = useAtom(counterAtom, jotaiScope);
useLayoutEffect(() => {
setCounter((counter) => counter + 1);
diff --git a/src/components/main-menu/MainMenu.tsx b/src/components/main-menu/MainMenu.tsx
index cc0de1b5..636ffc6e 100644
--- a/src/components/main-menu/MainMenu.tsx
+++ b/src/components/main-menu/MainMenu.tsx
@@ -13,7 +13,7 @@ import { t } from "../../i18n";
import { HamburgerMenuIcon } from "../icons";
import { withInternalFallback } from "../hoc/withInternalFallback";
import { composeEventHandlers } from "../../utils";
-import { mainMenuTunnel } from "../tunnels";
+import { useTunnels } from "../context/tunnels";
const MainMenu = Object.assign(
withInternalFallback(
@@ -28,6 +28,7 @@ const MainMenu = Object.assign(
*/
onSelect?: (event: Event) => void;
}) => {
+ const { mainMenuTunnel } = useTunnels();
const device = useDevice();
const appState = useExcalidrawAppState();
const setAppState = useExcalidrawSetAppState();
diff --git a/src/components/tunnels.ts b/src/components/tunnels.ts
deleted file mode 100644
index 646adac0..00000000
--- a/src/components/tunnels.ts
+++ /dev/null
@@ -1,8 +0,0 @@
-import tunnel from "tunnel-rat";
-
-export const mainMenuTunnel = tunnel();
-export const welcomeScreenMenuHintTunnel = tunnel();
-export const welcomeScreenToolbarHintTunnel = tunnel();
-export const welcomeScreenHelpHintTunnel = tunnel();
-export const welcomeScreenCenterTunnel = tunnel();
-export const footerCenterTunnel = tunnel();
diff --git a/src/components/welcome-screen/WelcomeScreen.Center.tsx b/src/components/welcome-screen/WelcomeScreen.Center.tsx
index 169503a6..d05018c3 100644
--- a/src/components/welcome-screen/WelcomeScreen.Center.tsx
+++ b/src/components/welcome-screen/WelcomeScreen.Center.tsx
@@ -6,8 +6,8 @@ import {
useExcalidrawActionManager,
useExcalidrawAppState,
} from "../App";
+import { useTunnels } from "../context/tunnels";
import { ExcalLogo, HelpIcon, LoadIcon, usersIcon } from "../icons";
-import { welcomeScreenCenterTunnel } from "../tunnels";
const WelcomeScreenMenuItemContent = ({
icon,
@@ -89,6 +89,7 @@ const WelcomeScreenMenuItemLink = ({
WelcomeScreenMenuItemLink.displayName = "WelcomeScreenMenuItemLink";
const Center = ({ children }: { children?: React.ReactNode }) => {
+ const { welcomeScreenCenterTunnel } = useTunnels();
return (