Added note edit flags

This commit is contained in:
Mitchell McCaffrey 2020-11-05 16:21:52 +11:00
parent 8873e59205
commit 6fedcc171d
5 changed files with 27 additions and 3 deletions

View File

@ -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 })
}

View File

@ -233,6 +233,16 @@ function MapSettings({
/>
Tokens
</Label>
<Label>
<Checkbox
checked={
!mapStateEmpty && mapState.editFlags.includes("notes")
}
disabled={mapStateEmpty}
onChange={(e) => handleFlagChange(e, "notes")}
/>
Notes
</Label>
</Flex>
</Box>
</>

View File

@ -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: {},
};

View File

@ -277,6 +277,7 @@ function loadVersions(db) {
.toCollection()
.modify((state) => {
state.notes = {};
state.editFlags = [...state.editFlags, "notes"];
});
});
}

View File

@ -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}
/>