From 6fedcc171d80cefe4c3c89910b7f090953786c6b Mon Sep 17 00:00:00 2001 From: Mitchell McCaffrey Date: Thu, 5 Nov 2020 16:21:52 +1100 Subject: [PATCH] Added note edit flags --- src/components/map/Map.js | 10 ++++++++-- src/components/map/MapSettings.js | 10 ++++++++++ src/contexts/MapDataContext.js | 2 +- src/database.js | 1 + src/network/NetworkedMapAndTokens.js | 7 +++++++ 5 files changed, 27 insertions(+), 3 deletions(-) diff --git a/src/components/map/Map.js b/src/components/map/Map.js index adc9029..cd3305f 100644 --- a/src/components/map/Map.js +++ b/src/components/map/Map.js @@ -40,6 +40,7 @@ function Map({ allowMapDrawing, allowFogDrawing, allowMapChange, + allowNoteEditing, disabledTokens, session, }) { @@ -138,7 +139,6 @@ function Map({ disabledControls.push("pan"); disabledControls.push("measure"); disabledControls.push("pointer"); - disabledControls.push("note"); } if (!allowFogDrawing) { disabledControls.push("fog"); @@ -146,6 +146,9 @@ function Map({ if (!allowMapChange) { disabledControls.push("map"); } + if (!allowNoteEditing) { + disabledControls.push("note"); + } const disabledSettings = { fog: [], drawing: [] }; if (mapShapes.length === 0) { @@ -399,7 +402,10 @@ function Map({ : [] } onNoteMenuOpen={handleNoteMenuOpen} - draggable={selectedToolId === "note" || selectedToolId === "pan"} + draggable={ + allowNoteEditing && + (selectedToolId === "note" || selectedToolId === "pan") + } onNoteDragStart={(e, noteId) => setNoteDraggingOptions({ dragging: true, noteId, noteGroup: e.target }) } diff --git a/src/components/map/MapSettings.js b/src/components/map/MapSettings.js index 3c6181b..622bd0d 100644 --- a/src/components/map/MapSettings.js +++ b/src/components/map/MapSettings.js @@ -233,6 +233,16 @@ function MapSettings({ /> Tokens + diff --git a/src/contexts/MapDataContext.js b/src/contexts/MapDataContext.js index a9a3621..9d7e4b4 100644 --- a/src/contexts/MapDataContext.js +++ b/src/contexts/MapDataContext.js @@ -19,7 +19,7 @@ const defaultMapState = { fogDrawActionIndex: -1, fogDrawActions: [], // Flags to determine what other people can edit - editFlags: ["drawing", "tokens"], + editFlags: ["drawing", "tokens", "notes"], notes: {}, }; diff --git a/src/database.js b/src/database.js index 91cf035..6164f28 100644 --- a/src/database.js +++ b/src/database.js @@ -277,6 +277,7 @@ function loadVersions(db) { .toCollection() .modify((state) => { state.notes = {}; + state.editFlags = [...state.editFlags, "notes"]; }); }); } diff --git a/src/network/NetworkedMapAndTokens.js b/src/network/NetworkedMapAndTokens.js index 9d22be7..8566c54 100644 --- a/src/network/NetworkedMapAndTokens.js +++ b/src/network/NetworkedMapAndTokens.js @@ -463,6 +463,12 @@ function NetworkedMapAndTokens({ session }) { currentMapState !== null && (currentMapState.editFlags.includes("fog") || currentMap.owner === userId); + const canEditNotes = + currentMap !== null && + currentMapState !== null && + (currentMapState.editFlags.includes("notes") || + currentMap.owner === userId); + const disabledMapTokens = {}; // If we have a map and state and have the token permission disabled // and are not the map owner @@ -499,6 +505,7 @@ function NetworkedMapAndTokens({ session }) { allowMapDrawing={canEditMapDrawing} allowFogDrawing={canEditFogDrawing} allowMapChange={canChangeMap} + allowNoteEditing={canEditNotes} disabledTokens={disabledMapTokens} session={session} />