From 0ff9c6490885d0a637c5c4e698423a008dc4f538 Mon Sep 17 00:00:00 2001 From: Jeff Emmett <46964190+Jeff-Emmett@users.noreply.github.com> Date: Sun, 8 Dec 2024 05:45:31 -0500 Subject: [PATCH] same --- src/utils/handleInitialPageLoad.ts | 73 ++---------------------------- 1 file changed, 5 insertions(+), 68 deletions(-) diff --git a/src/utils/handleInitialPageLoad.ts b/src/utils/handleInitialPageLoad.ts index 88dbbdc..c0fd469 100644 --- a/src/utils/handleInitialPageLoad.ts +++ b/src/utils/handleInitialPageLoad.ts @@ -1,73 +1,10 @@ -import { Editor, TLShapeId } from "tldraw" +import { Editor } from "tldraw" export const handleInitialPageLoad = (editor: Editor) => { - // Wait for editor to be ready - // if (!editor.isMounted()) { - // editor.once("mount", () => handleInitialPageLoad(editor)) - // return - // } - - const url = new URL(window.location.href) - console.log("URL params:", { - x: url.searchParams.get("x"), - y: url.searchParams.get("y"), - zoom: url.searchParams.get("zoom"), - }) - - // Get camera parameters first - const x = url.searchParams.get("x") - const y = url.searchParams.get("y") - const zoom = url.searchParams.get("zoom") - - // Set camera position if coordinates exist - if (x && y && zoom) { - console.log("Setting camera to:", { - x: parseFloat(x), - y: parseFloat(y), - z: parseFloat(zoom), - }) - - requestAnimationFrame(() => { - editor.setCamera({ - x: parseFloat(x), - y: parseFloat(y), - z: parseFloat(zoom), - }) - }) + if (!editor.store || !editor.getInstanceState().isFocused) { + setTimeout(() => handleInitialPageLoad(editor), 100) + return } - // Get shape/frame parameters last - const frameId = url.searchParams.get("frameId") - const isLocked = url.searchParams.get("isLocked") === "true" - - // Handle frame-specific logic - if (frameId) { - const frame = editor.getShape(frameId as TLShapeId) - if (frame) { - editor.select(frameId as TLShapeId) - - // If x/y/zoom are not provided in URL, zoom to frame bounds - if (!x || !y || !zoom) { - editor.zoomToBounds(editor.getShapePageBounds(frame)!, { - animation: { duration: 0 }, - targetZoom: 1, - }) - } - - // Apply camera lock after camera is positioned - if (isLocked) { - // Use requestAnimationFrame to ensure camera is set before locking - requestAnimationFrame(() => { - editor.setCameraOptions({ - isLocked: true, - // Optional: you may want to also set these options for locked frames - //shouldSnapToGrid: false, - //shouldUseEdgeScrolling: false, - }) - }) - } - } else { - console.warn("Frame not found:", frameId) - } - } + editor.setCurrentTool("hand") }