Fix bug that caused closing the select map modal to select the map

Added ability to deselect a map by clicking outside of the map select tile
This commit is contained in:
Mitchell McCaffrey 2020-08-06 13:31:46 +10:00
parent 4347b5759d
commit 93a09db707
3 changed files with 18 additions and 3 deletions

View File

@ -109,7 +109,8 @@ function MapTile({
}} }}
m={2} m={2}
bg="muted" bg="muted"
onClick={() => { onClick={(e) => {
e.stopPropagation();
setIsTileMenuOpen(false); setIsTileMenuOpen(false);
if (!isSelected) { if (!isSelected) {
onMapSelect(map); onMapSelect(map);

View File

@ -31,6 +31,7 @@ function MapTiles({
width: "500px", width: "500px",
borderRadius: "4px", borderRadius: "4px",
}} }}
onClick={() => onMapSelect(null)}
> >
<Flex <Flex
onClick={onMapAdd} onClick={onMapAdd}

View File

@ -184,7 +184,11 @@ function SelectMapModal({
async function handleMapSelect(map) { async function handleMapSelect(map) {
await applyMapChanges(); await applyMapChanges();
setSelectedMapId(map.id); if (map) {
setSelectedMapId(map.id);
} else {
setSelectedMapId(null);
}
} }
async function handleMapReset(id) { async function handleMapReset(id) {
@ -195,6 +199,13 @@ function SelectMapModal({
} }
} }
async function handleClose() {
if (selectedMapId) {
await applyMapChanges();
}
onDone();
}
async function handleDone() { async function handleDone() {
if (imageLoading) { if (imageLoading) {
return; return;
@ -202,6 +213,8 @@ function SelectMapModal({
if (selectedMapId) { if (selectedMapId) {
await applyMapChanges(); await applyMapChanges();
onMapChange(selectedMapWithChanges, selectedMapStateWithChanges); onMapChange(selectedMapWithChanges, selectedMapStateWithChanges);
} else {
onMapChange(null, null);
} }
onDone(); onDone();
} }
@ -250,7 +263,7 @@ function SelectMapModal({
}; };
return ( return (
<Modal isOpen={isOpen} onRequestClose={handleDone}> <Modal isOpen={isOpen} onRequestClose={handleClose}>
<ImageDrop onDrop={handleImagesUpload} dropText="Drop map to upload"> <ImageDrop onDrop={handleImagesUpload} dropText="Drop map to upload">
<input <input
onChange={(event) => handleImagesUpload(event.target.files)} onChange={(event) => handleImagesUpload(event.target.files)}