From 4d127a038bf768eded68aae3cfa5c1b12241bdac Mon Sep 17 00:00:00 2001 From: Maze Winther Date: Fri, 27 Mar 2026 00:55:15 +0100 Subject: chore: normalize line endings --- .../src/components/providers/editor-provider.tsx | 266 ++++++++++----------- 1 file changed, 133 insertions(+), 133 deletions(-) (limited to 'apps/web/src/components/providers') diff --git a/apps/web/src/components/providers/editor-provider.tsx b/apps/web/src/components/providers/editor-provider.tsx index 35e5dfba..79f1809a 100644 --- a/apps/web/src/components/providers/editor-provider.tsx +++ b/apps/web/src/components/providers/editor-provider.tsx @@ -1,133 +1,133 @@ -"use client"; - -import { useEffect, useState } from "react"; -import { useRouter } from "next/navigation"; -import { Loader2 } from "lucide-react"; -import { EditorCore } from "@/core"; -import { useEditor } from "@/hooks/use-editor"; -import { useKeybindingsListener } from "@/hooks/use-keybindings"; -import { useKeybindingsStore } from "@/stores/keybindings-store"; -import { useEditorActions } from "@/hooks/actions/use-editor-actions"; -import { loadFontAtlas } from "@/lib/fonts/google-fonts"; - -interface EditorProviderProps { - projectId: string; - children: React.ReactNode; -} - -export function EditorProvider({ projectId, children }: EditorProviderProps) { - const activeProject = useEditor((e) => e.project.getActiveOrNull()); - const router = useRouter(); - const [isLoading, setIsLoading] = useState(true); - const [error, setError] = useState(null); - const { setLoadingProject } = useKeybindingsStore(); - - useEffect(() => { - setLoadingProject(isLoading); - }, [isLoading, setLoadingProject]); - - useEffect(() => { - let cancelled = false; - const editor = EditorCore.getInstance(); - - const loadProject = async () => { - try { - setIsLoading(true); - await editor.project.loadProject({ id: projectId }); - - if (cancelled) return; - - setIsLoading(false); - loadFontAtlas(); - } catch (err) { - if (cancelled) return; - - const isNotFound = - err instanceof Error && - (err.message.includes("not found") || - err.message.includes("does not exist")); - - if (isNotFound) { - try { - const newProjectId = await editor.project.createNewProject({ - name: "Untitled Project", - }); - router.replace(`/editor/${newProjectId}`); - } catch (_createErr) { - setError("Failed to create project"); - setIsLoading(false); - } - } else { - setError( - err instanceof Error ? err.message : "Failed to load project", - ); - setIsLoading(false); - } - } - }; - - loadProject(); - - return () => { - cancelled = true; - }; - }, [projectId, router]); - - if (error) { - return ( -
-
-

{error}

-
-
- ); - } - - if (isLoading) { - return ( -
-
- -

Loading project...

-
-
- ); - } - - if (!activeProject) { - return ( -
-
- -

Exiting project...

-
-
- ); - } - - return ( - <> - - {children} - - ); -} - -function EditorRuntimeBindings() { - const editor = useEditor(); - - useEffect(() => { - const handleBeforeUnload = (event: BeforeUnloadEvent) => { - if (!editor.save.getIsDirty()) return; - event.preventDefault(); - (event as unknown as { returnValue: string }).returnValue = ""; - }; - - window.addEventListener("beforeunload", handleBeforeUnload); - return () => window.removeEventListener("beforeunload", handleBeforeUnload); - }, [editor]); - - useEditorActions(); - useKeybindingsListener(); - return null; -} +"use client"; + +import { useEffect, useState } from "react"; +import { useRouter } from "next/navigation"; +import { Loader2 } from "lucide-react"; +import { EditorCore } from "@/core"; +import { useEditor } from "@/hooks/use-editor"; +import { useKeybindingsListener } from "@/hooks/use-keybindings"; +import { useKeybindingsStore } from "@/stores/keybindings-store"; +import { useEditorActions } from "@/hooks/actions/use-editor-actions"; +import { loadFontAtlas } from "@/lib/fonts/google-fonts"; + +interface EditorProviderProps { + projectId: string; + children: React.ReactNode; +} + +export function EditorProvider({ projectId, children }: EditorProviderProps) { + const activeProject = useEditor((e) => e.project.getActiveOrNull()); + const router = useRouter(); + const [isLoading, setIsLoading] = useState(true); + const [error, setError] = useState(null); + const { setLoadingProject } = useKeybindingsStore(); + + useEffect(() => { + setLoadingProject(isLoading); + }, [isLoading, setLoadingProject]); + + useEffect(() => { + let cancelled = false; + const editor = EditorCore.getInstance(); + + const loadProject = async () => { + try { + setIsLoading(true); + await editor.project.loadProject({ id: projectId }); + + if (cancelled) return; + + setIsLoading(false); + loadFontAtlas(); + } catch (err) { + if (cancelled) return; + + const isNotFound = + err instanceof Error && + (err.message.includes("not found") || + err.message.includes("does not exist")); + + if (isNotFound) { + try { + const newProjectId = await editor.project.createNewProject({ + name: "Untitled Project", + }); + router.replace(`/editor/${newProjectId}`); + } catch (_createErr) { + setError("Failed to create project"); + setIsLoading(false); + } + } else { + setError( + err instanceof Error ? err.message : "Failed to load project", + ); + setIsLoading(false); + } + } + }; + + loadProject(); + + return () => { + cancelled = true; + }; + }, [projectId, router]); + + if (error) { + return ( +
+
+

{error}

+
+
+ ); + } + + if (isLoading) { + return ( +
+
+ +

Loading project...

+
+
+ ); + } + + if (!activeProject) { + return ( +
+
+ +

Exiting project...

+
+
+ ); + } + + return ( + <> + + {children} + + ); +} + +function EditorRuntimeBindings() { + const editor = useEditor(); + + useEffect(() => { + const handleBeforeUnload = (event: BeforeUnloadEvent) => { + if (!editor.save.getIsDirty()) return; + event.preventDefault(); + (event as unknown as { returnValue: string }).returnValue = ""; + }; + + window.addEventListener("beforeunload", handleBeforeUnload); + return () => window.removeEventListener("beforeunload", handleBeforeUnload); + }, [editor]); + + useEditorActions(); + useKeybindingsListener(); + return null; +} -- cgit v1.3.1