Added locking to notes

This commit is contained in:
Mitchell McCaffrey 2020-11-05 15:30:22 +11:00
parent 9790d4e44f
commit f5aec514f8
2 changed files with 26 additions and 11 deletions

View File

@ -106,7 +106,7 @@ function MapNotes({
map={map} map={map}
key={note.id} key={note.id}
onNoteMenuOpen={onNoteMenuOpen} onNoteMenuOpen={onNoteMenuOpen}
draggable={draggable} draggable={draggable && !note.locked}
onNoteChange={onNoteChange} onNoteChange={onNoteChange}
onNoteDragStart={onNoteDragStart} onNoteDragStart={onNoteDragStart}
onNoteDragEnd={onNoteDragEnd} onNoteDragEnd={onNoteDragEnd}

View File

@ -29,13 +29,6 @@ function Note({
const noteWidth = map && (mapWidth / map.grid.size.x) * note.size; const noteWidth = map && (mapWidth / map.grid.size.x) * note.size;
const noteHeight = map && (mapHeight / map.grid.size.y) * note.size; const noteHeight = map && (mapHeight / map.grid.size.y) * note.size;
function handleClick(event) {
if (draggable) {
const noteNode = event.target;
onNoteMenuOpen && onNoteMenuOpen(note.id, noteNode);
}
}
function handleDragStart(event) { function handleDragStart(event) {
onNoteDragStart && onNoteDragStart(event, note.id); onNoteDragStart && onNoteDragStart(event, note.id);
} }
@ -90,16 +83,38 @@ function Note({
setPreventMapInteraction(false); setPreventMapInteraction(false);
} }
function handlePointerDown() { function handleClick(event) {
if (draggable) { if (draggable) {
setPreventMapInteraction(true); const noteNode = event.target;
onNoteMenuOpen && onNoteMenuOpen(note.id, noteNode);
} }
} }
function handlePointerUp() { // Store note pointer down time to check for a click when note is locked
const notePointerDownTimeRef = useRef();
function handlePointerDown(event) {
if (draggable) {
setPreventMapInteraction(true);
}
if (note.locked && map.owner === userId) {
notePointerDownTimeRef.current = event.evt.timeStamp;
}
}
function handlePointerUp(event) {
if (draggable) { if (draggable) {
setPreventMapInteraction(false); setPreventMapInteraction(false);
} }
// Check note click when locked and we are the map owner
// We can't use onClick because that doesn't check pointer distance
if (note.locked && map.owner === userId) {
// If down and up time is small trigger a click
const delta = event.evt.timeStamp - notePointerDownTimeRef.current;
if (delta < 300) {
const noteNode = event.target;
onNoteMenuOpen(note.id, noteNode);
}
}
} }
const [fontSize, setFontSize] = useState(1); const [fontSize, setFontSize] = useState(1);