Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix event map mismatch #40

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 23 additions & 5 deletions src/SelectMap.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -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 ? (
Expand Down Expand Up @@ -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);
Expand Down
21 changes: 18 additions & 3 deletions src/StartScreen.jsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

import { useState } from "react";
import SelectMap from "./SelectMap";
import { readMap } from "./services/map";
Expand All @@ -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 (
<>
Expand All @@ -36,11 +48,11 @@ export default function StartScreen() {
</a>
.
</p>
{event.mapFilename ? (
{eventMapFilename ? (
<p className="p-3 border border-indigo-600 rounded">
You have courses saved from a previous session using the map
<br />
<strong>{event.mapFilename}</strong>
<strong>{eventMapFilename}</strong>
<br />
Open this map to continue working.
</p>
Expand Down Expand Up @@ -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");
Expand Down