From 331ffa788fee4203b1462d98e9df3657bca2cd22 Mon Sep 17 00:00:00 2001 From: Mats Walfridsson <61554783+wlfrdssn@users.noreply.github.com> Date: Fri, 24 Jan 2025 20:04:31 +0100 Subject: [PATCH 1/4] Update StartScreen.jsx --- src/StartScreen.jsx | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/StartScreen.jsx b/src/StartScreen.jsx index 27caab1..d4b6cb2 100644 --- a/src/StartScreen.jsx +++ b/src/StartScreen.jsx @@ -1,3 +1,4 @@ + import { useState } from "react"; import SelectMap from "./SelectMap"; import { readMap } from "./services/map"; @@ -10,7 +11,18 @@ export default function StartScreen() { const [state, setState] = useState("idle"); const setMap = useMap(getSetter); const pushNotification = useNotifications(getPush); - const event = useEvent(); + const { setEventMap, mapFilename: eventMapFilename } = useEvent( + getEvent, + ); + + function getEvent({ + mapFilename, + actions: { + event: { setMap: setEventMap }, + }, + }) { + return { mapFilename, setEventMap }; + } return ( <> @@ -72,6 +84,9 @@ export default function StartScreen() { const mapFile = await readMap(blob); const mapFilename = "Demo Map"; setMap(mapFilename, mapFile, new OcadTiler(mapFile), blob); + if (!eventMapFilename) { + setEventMap(mapFile, mapFilename); + } } catch (e) { console.error(e); setState("error"); From 39d27e5d466738e5c4fd3d442b1692299fd3831e Mon Sep 17 00:00:00 2001 From: Mats Walfridsson <61554783+wlfrdssn@users.noreply.github.com> Date: Fri, 24 Jan 2025 20:10:14 +0100 Subject: [PATCH 2/4] Update SelectMap.jsx --- src/SelectMap.jsx | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/src/SelectMap.jsx b/src/SelectMap.jsx index 9301d84..c9abb9f 100644 --- a/src/SelectMap.jsx +++ b/src/SelectMap.jsx @@ -2,8 +2,7 @@ import { useRef, useState } from "react"; import Spinner from "./ui/Spinner"; import Button from "./ui/Button"; import OcadTiler from "ocad-tiler"; - -import { useMap, useNotifications } from "./store"; +import useEvent, { useMap, useNotifications } from "./store"; import { readMap } from "./services/map"; export default function SelectMap({ @@ -18,6 +17,19 @@ export default function SelectMap({ const setMap = useMap(getSetter); const pushNotification = useNotifications(getPush); + const { setEventMap, mapFilename: eventMapFilename } = useEvent( + getEvent, + ); + + function getEvent({ + mapFilename, + actions: { + event: { setMap: setEventMap }, + }, + }) { + return { mapFilename, setEventMap }; + } + return ( <> {component ? ( @@ -48,9 +60,15 @@ export default function SelectMap({ setState("loading"); try { const [blob] = e.target.files; - const map = await readMap(blob); - setMap(blob.name, map, new OcadTiler(map), blob); - onMapLoaded && onMapLoaded(map, blob.name); + const mapFile = await readMap(blob); + const mapFilename = blob.name; + setMap(mapFilename, mapFile, new OcadTiler(mapFile), blob); + + if (!eventMapFilename) { + setEventMap(mapFile, mapFilename); + } + + onMapLoaded && onMapLoaded(mapFile, mapFilename); setState("idle"); } catch (e) { console.error(e); From 07c102c1b9f97f39aa79222495e2c726b3ed41ed Mon Sep 17 00:00:00 2001 From: Mats Walfridsson <61554783+wlfrdssn@users.noreply.github.com> Date: Fri, 24 Jan 2025 21:09:57 +0100 Subject: [PATCH 3/4] Update StartScreen.jsx --- src/StartScreen.jsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/StartScreen.jsx b/src/StartScreen.jsx index d4b6cb2..9ca23d6 100644 --- a/src/StartScreen.jsx +++ b/src/StartScreen.jsx @@ -48,11 +48,11 @@ export default function StartScreen() { .
- {event.mapFilename ? ( + {eventmapFilename ? (
You have courses saved from a previous session using the map
- {event.mapFilename}
+ {eventmapFilename}
Open this map to continue working.
You have courses saved from a previous session using the map
- {eventmapFilename}
+ {eventMapFilename}
Open this map to continue working.