From ec2bce1ccbced8b8429638efae64a0e3742299f5 Mon Sep 17 00:00:00 2001 From: Anton Tranelis Date: Mon, 12 Jan 2026 16:45:23 +0100 Subject: [PATCH] refactor: move info modal to dedicated /info route - Move Modal from always-rendered to route-based rendering at /info - Update Modal component to use MapOverlayPage instead of dialog element - Update ModalContent to use useNavigate for closing (navigates to /) - Add automatic redirect to /info when map.info_open is true on first load This change makes the info modal accessible via URL and improves the architecture by using the existing routing system. Co-Authored-By: Claude Opus 4.5 --- app/src/App.tsx | 21 +++++++++++++--- app/src/ModalContent.tsx | 22 ++++++----------- lib/src/Components/Gaming/Modal.tsx | 38 +++++++---------------------- 3 files changed, 33 insertions(+), 48 deletions(-) diff --git a/app/src/App.tsx b/app/src/App.tsx index e21ef608..7596bb0c 100644 --- a/app/src/App.tsx +++ b/app/src/App.tsx @@ -41,7 +41,7 @@ import { UserSettings, } from 'utopia-ui' -import { Route, Routes } from 'react-router-dom' +import { Route, Routes, useNavigate } from 'react-router-dom' import './App.css' import { Suspense, useEffect, useState } from 'react' @@ -196,6 +196,14 @@ function App() { const currentUrl = window.location.href const bottomRoutes = getBottomRoutes(currentUrl) + const navigate = useNavigate() + + // Redirect to /info if map.info_open is true (on first load) + useEffect(() => { + if (map?.info_open && window.location.pathname === '/') { + void navigate('/info') + } + }, [map?.info_open, navigate]) if (map && layers) return ( @@ -210,9 +218,6 @@ function App() { > {tagsApi && } - - - @@ -258,6 +263,14 @@ function App() { } /> + + + + } + /> } /> } /> } /> diff --git a/app/src/ModalContent.tsx b/app/src/ModalContent.tsx index c79a850b..88627061 100644 --- a/app/src/ModalContent.tsx +++ b/app/src/ModalContent.tsx @@ -4,7 +4,8 @@ /* eslint-disable @typescript-eslint/no-unsafe-member-access */ /* eslint-disable @typescript-eslint/prefer-nullish-coalescing */ -import { useEffect, useState } from 'react' +import { useState } from 'react' +import { useNavigate } from 'react-router-dom' import { TextView } from 'utopia-ui' import { config } from './config' @@ -61,21 +62,13 @@ export function Welcome1({ clickAction1, map }: ChapterProps) { ) } -const close = () => { - const myModal = document.getElementById('my_modal_3') as HTMLDialogElement - myModal.close() -} - export const ModalContent = ({ map }: { map: any }) => { - useEffect(() => { - const myModal = document.getElementById('my_modal_3') as HTMLDialogElement - if (map.info_open) { - myModal.showModal() - } - }, [map.info_open]) - + const navigate = useNavigate() const [chapter, setChapter] = useState(1) - // const setQuestsOpen = useSetQuestOpen() + + const close = () => { + void navigate('/') + } const ActiveChapter = () => { switch (chapter) { @@ -86,7 +79,6 @@ export const ModalContent = ({ map }: { map: any }) => { clickAction1={() => { close() setTimeout(() => { - // setQuestsOpen(true); setChapter(1) }, 1000) }} diff --git a/lib/src/Components/Gaming/Modal.tsx b/lib/src/Components/Gaming/Modal.tsx index 32f66058..5a4e7fb0 100644 --- a/lib/src/Components/Gaming/Modal.tsx +++ b/lib/src/Components/Gaming/Modal.tsx @@ -1,36 +1,16 @@ -import { useEffect } from 'react' +import { MapOverlayPage } from '#components/Templates' /** * @category Gaming */ -export function Modal({ - children, - showOnStartup, -}: { - children: React.ReactNode - showOnStartup?: boolean -}) { - useEffect(() => { - if (showOnStartup) { - window.my_modal_3.showModal() - } - // eslint-disable-next-line react-hooks/exhaustive-deps - }, []) - +export function Modal({ children }: { children: React.ReactNode }) { return ( - <> - {/* You can open the modal using ID.showModal() method */} - -
- - {children} -
-
- -
-
- + + {children} + ) }