2020-05-03 18:22:09 +10:00
|
|
|
import React, { useContext } from "react";
|
|
|
|
|
import { Flex, Box, Text } 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-04-23 20:32:33 +10:00
|
|
|
import MapTile from "./MapTile";
|
2020-05-03 18:22:09 +10:00
|
|
|
import Link from "../Link";
|
|
|
|
|
|
|
|
|
|
import DatabaseContext from "../../contexts/DatabaseContext";
|
2020-04-23 11:54:29 +10:00
|
|
|
|
2020-04-23 20:32:33 +10:00
|
|
|
function MapTiles({
|
|
|
|
|
maps,
|
|
|
|
|
selectedMap,
|
2020-04-26 17:12:15 +10:00
|
|
|
selectedMapState,
|
2020-04-23 20:32:33 +10:00
|
|
|
onMapSelect,
|
|
|
|
|
onMapAdd,
|
|
|
|
|
onMapRemove,
|
|
|
|
|
onMapReset,
|
2020-05-19 16:21:01 +10:00
|
|
|
onDone,
|
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-04-23 11:54:29 +10:00
|
|
|
return (
|
2020-05-03 18:22:09 +10:00
|
|
|
<Box sx={{ position: "relative" }}>
|
2020-09-06 13:20:05 +10:00
|
|
|
<SimpleBar style={{ maxHeight: "300px" }}>
|
2020-04-25 00:42:23 +10:00
|
|
|
<Flex
|
2020-09-06 13:20:05 +10:00
|
|
|
p={2}
|
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-08-06 13:31:46 +10:00
|
|
|
onClick={() => onMapSelect(null)}
|
2020-04-25 00:42:23 +10:00
|
|
|
>
|
2020-05-03 18:22:09 +10:00
|
|
|
<Flex
|
|
|
|
|
onClick={onMapAdd}
|
|
|
|
|
sx={{
|
|
|
|
|
":hover": {
|
|
|
|
|
color: "primary",
|
|
|
|
|
},
|
|
|
|
|
":focus": {
|
|
|
|
|
outline: "none",
|
|
|
|
|
},
|
|
|
|
|
":active": {
|
|
|
|
|
color: "secondary",
|
|
|
|
|
},
|
2020-09-08 14:26:38 +10:00
|
|
|
width: isSmallScreen ? "48%" : "32%",
|
2020-09-06 13:20:05 +10:00
|
|
|
height: "0",
|
2020-09-08 14:26:38 +10:00
|
|
|
paddingTop: isSmallScreen ? "48%" : "32%",
|
2020-05-03 18:22:09 +10:00
|
|
|
borderRadius: "4px",
|
2020-09-06 13:20:05 +10:00
|
|
|
position: "relative",
|
2020-05-03 18:22:09 +10:00
|
|
|
cursor: "pointer",
|
|
|
|
|
}}
|
2020-09-06 13:20:05 +10:00
|
|
|
my={1}
|
2020-09-08 14:26:38 +10:00
|
|
|
mx={`${isSmallScreen ? 1 : 2 / 3}%`}
|
2020-05-03 18:22:09 +10:00
|
|
|
bg="muted"
|
|
|
|
|
aria-label="Add Map"
|
|
|
|
|
title="Add Map"
|
|
|
|
|
>
|
2020-09-06 13:20:05 +10:00
|
|
|
<Flex
|
|
|
|
|
sx={{
|
|
|
|
|
width: "100%",
|
|
|
|
|
height: "100%",
|
|
|
|
|
position: "absolute",
|
|
|
|
|
top: 0,
|
|
|
|
|
left: 0,
|
|
|
|
|
justifyContent: "center",
|
|
|
|
|
alignItems: "center",
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<AddIcon large />
|
|
|
|
|
</Flex>
|
2020-05-03 18:22:09 +10:00
|
|
|
</Flex>
|
2020-06-27 11:18:47 +10:00
|
|
|
{maps.map((map) => {
|
|
|
|
|
const isSelected = selectedMap && map.id === selectedMap.id;
|
|
|
|
|
return (
|
|
|
|
|
<MapTile
|
|
|
|
|
key={map.id}
|
|
|
|
|
// TODO: Move to selected map here and fix url error
|
|
|
|
|
// when done is clicked
|
|
|
|
|
map={map}
|
|
|
|
|
mapState={isSelected && selectedMapState}
|
|
|
|
|
isSelected={isSelected}
|
|
|
|
|
onMapSelect={onMapSelect}
|
|
|
|
|
onMapRemove={onMapRemove}
|
|
|
|
|
onMapReset={onMapReset}
|
|
|
|
|
onDone={onDone}
|
2020-09-06 13:20:05 +10:00
|
|
|
large={isSmallScreen}
|
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>
|
|
|
|
|
)}
|
|
|
|
|
</Box>
|
2020-04-23 11:54:29 +10:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-23 18:01:40 +10:00
|
|
|
export default MapTiles;
|