2020-09-30 13:58:43 +10:00
|
|
|
import React from "react";
|
2020-04-26 12:39:56 +10:00
|
|
|
import { Flex, Image as UIImage, IconButton, Box, Text } from "theme-ui";
|
2020-04-23 20:32:33 +10:00
|
|
|
|
2020-09-24 16:54:33 +10:00
|
|
|
import EditMapIcon from "../../icons/EditMapIcon";
|
2020-04-23 20:32:33 +10:00
|
|
|
|
2020-04-24 15:50:05 +10:00
|
|
|
import useDataSource from "../../helpers/useDataSource";
|
2020-05-20 11:35:14 +10:00
|
|
|
import { mapSources as defaultMapSources, unknownSource } from "../../maps";
|
2020-04-24 15:50:05 +10:00
|
|
|
|
2020-09-30 12:30:33 +10:00
|
|
|
function MapTile({
|
|
|
|
|
map,
|
|
|
|
|
isSelected,
|
|
|
|
|
onMapSelect,
|
|
|
|
|
onMapEdit,
|
|
|
|
|
onDone,
|
|
|
|
|
large,
|
|
|
|
|
canEdit,
|
|
|
|
|
}) {
|
2020-04-24 15:50:05 +10:00
|
|
|
const isDefault = map.type === "default";
|
2020-07-13 19:36:38 +10:00
|
|
|
const mapSource = useDataSource(
|
2020-07-17 15:02:21 +10:00
|
|
|
isDefault
|
|
|
|
|
? map
|
|
|
|
|
: map.resolutions && map.resolutions.low
|
|
|
|
|
? map.resolutions.low
|
|
|
|
|
: map,
|
2020-07-13 19:36:38 +10:00
|
|
|
defaultMapSources,
|
|
|
|
|
unknownSource
|
|
|
|
|
);
|
|
|
|
|
|
2020-04-23 20:32:33 +10:00
|
|
|
return (
|
|
|
|
|
<Flex
|
|
|
|
|
key={map.id}
|
|
|
|
|
sx={{
|
|
|
|
|
position: "relative",
|
2020-09-08 14:26:38 +10:00
|
|
|
width: large ? "48%" : "32%",
|
2020-09-06 13:20:05 +10:00
|
|
|
height: "0",
|
2020-09-08 14:26:38 +10:00
|
|
|
paddingTop: large ? "48%" : "32%",
|
2020-04-23 20:32:33 +10:00
|
|
|
borderRadius: "4px",
|
|
|
|
|
justifyContent: "center",
|
|
|
|
|
alignItems: "center",
|
|
|
|
|
cursor: "pointer",
|
2020-09-06 13:20:05 +10:00
|
|
|
overflow: "hidden",
|
2020-09-30 13:58:43 +10:00
|
|
|
userSelect: "none",
|
2020-04-23 20:32:33 +10:00
|
|
|
}}
|
2020-09-06 13:20:05 +10:00
|
|
|
my={1}
|
2020-09-08 14:26:38 +10:00
|
|
|
mx={`${large ? 1 : 2 / 3}%`}
|
2020-04-23 20:32:33 +10:00
|
|
|
bg="muted"
|
2020-08-06 13:31:46 +10:00
|
|
|
onClick={(e) => {
|
|
|
|
|
e.stopPropagation();
|
2020-09-30 12:30:33 +10:00
|
|
|
onMapSelect(map);
|
2020-04-23 20:32:33 +10:00
|
|
|
}}
|
2020-04-23 22:12:50 +10:00
|
|
|
onDoubleClick={(e) => {
|
2020-09-30 13:58:43 +10:00
|
|
|
if (canEdit) {
|
2020-05-19 16:21:01 +10:00
|
|
|
onDone(e);
|
2020-04-23 22:12:50 +10:00
|
|
|
}
|
|
|
|
|
}}
|
2020-04-23 20:32:33 +10:00
|
|
|
>
|
|
|
|
|
<UIImage
|
2020-09-06 13:20:05 +10:00
|
|
|
sx={{
|
|
|
|
|
width: "100%",
|
|
|
|
|
height: "100%",
|
|
|
|
|
objectFit: "contain",
|
|
|
|
|
position: "absolute",
|
|
|
|
|
top: 0,
|
|
|
|
|
left: 0,
|
|
|
|
|
}}
|
2020-04-24 15:50:05 +10:00
|
|
|
src={mapSource}
|
2020-04-23 20:32:33 +10:00
|
|
|
/>
|
2020-04-26 12:39:56 +10:00
|
|
|
<Flex
|
|
|
|
|
sx={{
|
|
|
|
|
position: "absolute",
|
|
|
|
|
top: 0,
|
|
|
|
|
left: 0,
|
|
|
|
|
right: 0,
|
|
|
|
|
bottom: 0,
|
|
|
|
|
background:
|
2020-04-26 19:04:18 +10:00
|
|
|
"linear-gradient(to bottom, rgba(0,0,0,0) 70%, rgba(0,0,0,0.65) 100%);",
|
2020-04-26 12:39:56 +10:00
|
|
|
alignItems: "flex-end",
|
|
|
|
|
justifyContent: "center",
|
|
|
|
|
}}
|
|
|
|
|
p={2}
|
|
|
|
|
>
|
2020-04-30 14:42:15 +10:00
|
|
|
<Text
|
|
|
|
|
as="p"
|
|
|
|
|
variant="heading"
|
|
|
|
|
color="hsl(210, 50%, 96%)"
|
|
|
|
|
sx={{ textAlign: "center" }}
|
|
|
|
|
>
|
2020-04-26 12:39:56 +10:00
|
|
|
{map.name}
|
|
|
|
|
</Text>
|
|
|
|
|
</Flex>
|
2020-09-06 13:20:05 +10:00
|
|
|
<Box
|
|
|
|
|
sx={{
|
|
|
|
|
width: "100%",
|
|
|
|
|
height: "100%",
|
|
|
|
|
position: "absolute",
|
|
|
|
|
top: 0,
|
|
|
|
|
left: 0,
|
|
|
|
|
borderColor: "primary",
|
|
|
|
|
borderStyle: isSelected ? "solid" : "none",
|
|
|
|
|
borderWidth: "4px",
|
|
|
|
|
pointerEvents: "none",
|
|
|
|
|
borderRadius: "4px",
|
|
|
|
|
}}
|
|
|
|
|
/>
|
2020-09-30 12:30:33 +10:00
|
|
|
{canEdit && (
|
2020-04-23 20:32:33 +10:00
|
|
|
<Box sx={{ position: "absolute", top: 0, right: 0 }}>
|
2020-09-24 16:54:33 +10:00
|
|
|
<IconButton
|
|
|
|
|
aria-label="Edit Map"
|
|
|
|
|
title="Edit Map"
|
|
|
|
|
onClick={(e) => {
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
e.stopPropagation();
|
|
|
|
|
onMapEdit(map.id);
|
|
|
|
|
}}
|
|
|
|
|
bg="overlay"
|
|
|
|
|
sx={{ borderRadius: "50%" }}
|
|
|
|
|
m={2}
|
|
|
|
|
>
|
|
|
|
|
<EditMapIcon />
|
|
|
|
|
</IconButton>
|
2020-04-23 20:32:33 +10:00
|
|
|
</Box>
|
|
|
|
|
)}
|
|
|
|
|
</Flex>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default MapTile;
|