2020-05-03 18:22:09 +10:00
|
|
|
import React, { useContext } from "react";
|
2020-09-24 16:54:33 +10:00
|
|
|
import { Flex, Box, Text, IconButton, Close } from "theme-ui";
|
2020-04-25 00:42:23 +10:00
|
|
|
import SimpleBar from "simplebar-react";
|
2020-09-06 13:20:05 +10:00
|
|
|
import { useMedia } from "react-media";
|
2020-04-23 11:54:29 +10:00
|
|
|
|
|
|
|
|
import AddIcon from "../../icons/AddIcon";
|
2020-09-24 16:54:33 +10:00
|
|
|
import RemoveMapIcon from "../../icons/RemoveMapIcon";
|
|
|
|
|
import ResetMapIcon from "../../icons/ResetMapIcon";
|
2020-09-30 12:30:33 +10:00
|
|
|
import SelectMultipleIcon from "../../icons/SelectMultipleIcon";
|
|
|
|
|
import SelectSingleIcon from "../../icons/SelectSingleIcon";
|
2020-04-23 11:54:29 +10:00
|
|
|
|
2020-04-23 20:32:33 +10:00
|
|
|
import MapTile from "./MapTile";
|
2020-05-03 18:22:09 +10:00
|
|
|
import Link from "../Link";
|
2020-09-30 12:30:33 +10:00
|
|
|
import Search from "../Search";
|
2020-05-03 18:22:09 +10:00
|
|
|
|
|
|
|
|
import DatabaseContext from "../../contexts/DatabaseContext";
|
2020-04-23 11:54:29 +10:00
|
|
|
|
2020-04-23 20:32:33 +10:00
|
|
|
function MapTiles({
|
|
|
|
|
maps,
|
2020-09-30 12:30:33 +10:00
|
|
|
selectedMaps,
|
|
|
|
|
selectedMapStates,
|
2020-04-23 20:32:33 +10:00
|
|
|
onMapSelect,
|
2020-09-30 12:30:33 +10:00
|
|
|
onMapsRemove,
|
|
|
|
|
onMapsReset,
|
2020-09-24 16:54:33 +10:00
|
|
|
onMapAdd,
|
|
|
|
|
onMapEdit,
|
2020-05-19 16:21:01 +10:00
|
|
|
onDone,
|
2020-09-30 12:30:33 +10:00
|
|
|
selectMode,
|
|
|
|
|
onSelectModeChange,
|
2020-04-23 20:32:33 +10:00
|
|
|
}) {
|
2020-05-03 18:22:09 +10:00
|
|
|
const { databaseStatus } = useContext(DatabaseContext);
|
2020-09-06 13:20:05 +10:00
|
|
|
const isSmallScreen = useMedia({ query: "(max-width: 500px)" });
|
|
|
|
|
|
2020-09-30 12:30:33 +10:00
|
|
|
let hasMapState = false;
|
|
|
|
|
if (selectedMapStates.length > 0) {
|
|
|
|
|
for (let state of selectedMapStates) {
|
|
|
|
|
if (
|
|
|
|
|
Object.values(state.tokens).length > 0 ||
|
|
|
|
|
state.mapDrawActions.length > 0 ||
|
|
|
|
|
state.fogDrawActions.length > 0
|
|
|
|
|
) {
|
|
|
|
|
hasMapState = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-09-24 16:54:33 +10:00
|
|
|
|
2020-04-23 11:54:29 +10:00
|
|
|
return (
|
2020-05-03 18:22:09 +10:00
|
|
|
<Box sx={{ position: "relative" }}>
|
2020-09-30 12:30:33 +10:00
|
|
|
<Flex
|
|
|
|
|
bg="muted"
|
|
|
|
|
sx={{
|
|
|
|
|
border: "1px solid",
|
|
|
|
|
borderColor: "text",
|
|
|
|
|
borderRadius: "4px",
|
|
|
|
|
alignItems: "center",
|
|
|
|
|
":focus-within": {
|
|
|
|
|
outline: "1px auto",
|
|
|
|
|
outlineColor: "primary",
|
|
|
|
|
outlineOffset: "0px",
|
|
|
|
|
},
|
|
|
|
|
}}
|
|
|
|
|
onFocus={() => onMapSelect()}
|
|
|
|
|
>
|
|
|
|
|
<Search />
|
|
|
|
|
<IconButton
|
|
|
|
|
onClick={() =>
|
|
|
|
|
onSelectModeChange(selectMode === "single" ? "multiple" : "single")
|
|
|
|
|
}
|
|
|
|
|
aria-label={
|
|
|
|
|
selectMode === "single" ? "Select Multiple" : "Select Single"
|
|
|
|
|
}
|
|
|
|
|
title={selectMode === "single" ? "Select Multiple" : "Select Single"}
|
|
|
|
|
ml={1}
|
|
|
|
|
>
|
|
|
|
|
{selectMode === "single" ? (
|
|
|
|
|
<SelectMultipleIcon />
|
|
|
|
|
) : (
|
|
|
|
|
<SelectSingleIcon />
|
|
|
|
|
)}
|
|
|
|
|
</IconButton>
|
|
|
|
|
<IconButton
|
|
|
|
|
onClick={onMapAdd}
|
|
|
|
|
aria-label="Add Map"
|
|
|
|
|
title="Add Map"
|
|
|
|
|
mr={1}
|
|
|
|
|
>
|
|
|
|
|
<AddIcon />
|
|
|
|
|
</IconButton>
|
|
|
|
|
</Flex>
|
2020-09-24 16:54:33 +10:00
|
|
|
<SimpleBar style={{ maxHeight: "400px" }}>
|
2020-04-25 00:42:23 +10:00
|
|
|
<Flex
|
2020-09-06 13:20:05 +10:00
|
|
|
p={2}
|
2020-09-24 16:54:33 +10:00
|
|
|
pb={4}
|
2020-05-03 18:22:09 +10:00
|
|
|
bg="muted"
|
2020-04-25 00:42:23 +10:00
|
|
|
sx={{
|
2020-05-03 18:22:09 +10:00
|
|
|
flexWrap: "wrap",
|
2020-04-25 00:42:23 +10:00
|
|
|
borderRadius: "4px",
|
|
|
|
|
}}
|
2020-09-30 12:30:33 +10:00
|
|
|
onClick={() => onMapSelect()}
|
2020-04-25 00:42:23 +10:00
|
|
|
>
|
2020-06-27 11:18:47 +10:00
|
|
|
{maps.map((map) => {
|
2020-09-30 12:30:33 +10:00
|
|
|
const isSelected = selectedMaps.includes(map);
|
2020-06-27 11:18:47 +10:00
|
|
|
return (
|
|
|
|
|
<MapTile
|
|
|
|
|
key={map.id}
|
|
|
|
|
map={map}
|
|
|
|
|
isSelected={isSelected}
|
|
|
|
|
onMapSelect={onMapSelect}
|
2020-09-24 16:54:33 +10:00
|
|
|
onMapEdit={onMapEdit}
|
2020-06-27 11:18:47 +10:00
|
|
|
onDone={onDone}
|
2020-09-06 13:20:05 +10:00
|
|
|
large={isSmallScreen}
|
2020-09-30 12:30:33 +10:00
|
|
|
canEdit={isSelected && selectMode === "single"}
|
2020-06-27 11:18:47 +10:00
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
})}
|
2020-04-25 00:42:23 +10:00
|
|
|
</Flex>
|
2020-05-03 18:22:09 +10:00
|
|
|
</SimpleBar>
|
|
|
|
|
{databaseStatus === "disabled" && (
|
|
|
|
|
<Box
|
|
|
|
|
sx={{
|
|
|
|
|
position: "absolute",
|
|
|
|
|
top: 0,
|
|
|
|
|
left: 0,
|
|
|
|
|
right: 0,
|
|
|
|
|
textAlign: "center",
|
|
|
|
|
}}
|
|
|
|
|
bg="highlight"
|
|
|
|
|
p={1}
|
|
|
|
|
>
|
|
|
|
|
<Text as="p" variant="body2">
|
2020-05-03 18:30:01 +10:00
|
|
|
Map saving is unavailable. See <Link to="/faq#saving">FAQ</Link> for
|
|
|
|
|
more information.
|
2020-05-03 18:22:09 +10:00
|
|
|
</Text>
|
|
|
|
|
</Box>
|
|
|
|
|
)}
|
2020-09-30 12:30:33 +10:00
|
|
|
{selectedMaps.length > 0 && (
|
2020-09-24 16:54:33 +10:00
|
|
|
<Flex
|
|
|
|
|
sx={{
|
|
|
|
|
position: "absolute",
|
|
|
|
|
bottom: 0,
|
|
|
|
|
left: 0,
|
|
|
|
|
right: 0,
|
|
|
|
|
justifyContent: "space-between",
|
|
|
|
|
}}
|
|
|
|
|
bg="overlay"
|
|
|
|
|
>
|
|
|
|
|
<Close
|
|
|
|
|
title="Clear Selection"
|
|
|
|
|
aria-label="Clear Selection"
|
2020-09-30 12:30:33 +10:00
|
|
|
onClick={() => onMapSelect()}
|
2020-09-24 16:54:33 +10:00
|
|
|
/>
|
|
|
|
|
<Flex>
|
|
|
|
|
<IconButton
|
|
|
|
|
aria-label="Reset Map"
|
|
|
|
|
title="Reset Map"
|
2020-09-30 12:30:33 +10:00
|
|
|
onClick={() => onMapsReset()}
|
2020-09-24 16:54:33 +10:00
|
|
|
disabled={!hasMapState}
|
|
|
|
|
>
|
|
|
|
|
<ResetMapIcon />
|
|
|
|
|
</IconButton>
|
|
|
|
|
<IconButton
|
|
|
|
|
aria-label="Remove Map"
|
|
|
|
|
title="Remove Map"
|
2020-09-30 12:30:33 +10:00
|
|
|
onClick={() => onMapsRemove()}
|
2020-09-24 16:54:33 +10:00
|
|
|
>
|
|
|
|
|
<RemoveMapIcon />
|
|
|
|
|
</IconButton>
|
|
|
|
|
</Flex>
|
|
|
|
|
</Flex>
|
|
|
|
|
)}
|
2020-05-03 18:22:09 +10:00
|
|
|
</Box>
|
2020-04-23 11:54:29 +10:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-23 18:01:40 +10:00
|
|
|
export default MapTiles;
|