2021-05-24 17:11:46 +10:00
|
|
|
import React, { useState } from "react";
|
2021-06-05 18:05:35 +10:00
|
|
|
import { Box, Close, Grid, useThemeUI, IconButton, Text, Flex } from "theme-ui";
|
2021-05-24 17:11:46 +10:00
|
|
|
import { useSpring, animated, config } from "react-spring";
|
|
|
|
|
import ReactResizeDetector from "react-resize-detector";
|
|
|
|
|
import SimpleBar from "simplebar-react";
|
2021-05-24 13:34:21 +10:00
|
|
|
|
|
|
|
|
import { useGroup } from "../../contexts/GroupContext";
|
2021-06-08 23:46:20 +10:00
|
|
|
import { UNGROUP_ID, ADD_TO_MAP_ID } from "../../contexts/TileDragContext";
|
2021-05-24 13:34:21 +10:00
|
|
|
|
2021-05-27 17:19:36 +10:00
|
|
|
import useResponsiveLayout from "../../hooks/useResponsiveLayout";
|
|
|
|
|
|
2021-06-05 18:05:35 +10:00
|
|
|
import ChangeNicknameIcon from "../../icons/ChangeNicknameIcon";
|
|
|
|
|
|
|
|
|
|
import GroupNameModal from "../../modals/GroupNameModal";
|
|
|
|
|
|
|
|
|
|
import { renameGroup } from "../../helpers/group";
|
|
|
|
|
|
2021-06-08 23:46:20 +10:00
|
|
|
import Droppable from "../drag/Droppable";
|
|
|
|
|
|
|
|
|
|
function TilesOverlay({ modalSize, children }) {
|
2021-06-05 18:05:35 +10:00
|
|
|
const {
|
|
|
|
|
groups,
|
|
|
|
|
openGroupId,
|
|
|
|
|
onGroupClose,
|
|
|
|
|
onGroupSelect,
|
|
|
|
|
onGroupsChange,
|
|
|
|
|
} = useGroup();
|
2021-05-24 17:11:46 +10:00
|
|
|
|
2021-05-27 17:37:59 +10:00
|
|
|
const { theme } = useThemeUI();
|
|
|
|
|
|
2021-05-27 17:19:36 +10:00
|
|
|
const layout = useResponsiveLayout();
|
|
|
|
|
|
2021-05-24 17:11:46 +10:00
|
|
|
const openAnimation = useSpring({
|
|
|
|
|
opacity: openGroupId ? 1 : 0,
|
2021-05-24 17:28:57 +10:00
|
|
|
transform: openGroupId ? "scale(1)" : "scale(0.99)",
|
2021-05-24 17:11:46 +10:00
|
|
|
config: config.gentle,
|
|
|
|
|
});
|
2021-05-24 13:34:21 +10:00
|
|
|
|
2021-05-28 17:06:20 +10:00
|
|
|
const [containerSize, setContinerSize] = useState({ width: 0, height: 0 });
|
|
|
|
|
function handleContainerResize(width, height) {
|
2021-05-24 17:11:46 +10:00
|
|
|
const size = Math.min(width, height) - 16;
|
2021-05-28 17:06:20 +10:00
|
|
|
setContinerSize({ width: size, height: size });
|
2021-05-24 13:34:21 +10:00
|
|
|
}
|
|
|
|
|
|
2021-06-05 18:05:35 +10:00
|
|
|
const [isGroupNameModalOpen, setIsGroupNameModalOpen] = useState(false);
|
|
|
|
|
function handleGroupNameChange(name) {
|
|
|
|
|
onGroupsChange(renameGroup(groups, openGroupId, name));
|
|
|
|
|
setIsGroupNameModalOpen(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const group = groups.find((group) => group.id === openGroupId);
|
|
|
|
|
|
2021-06-10 20:07:40 +10:00
|
|
|
if (!openGroupId) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-24 13:34:21 +10:00
|
|
|
return (
|
2021-05-24 17:11:46 +10:00
|
|
|
<>
|
2021-06-10 20:07:40 +10:00
|
|
|
<Box
|
|
|
|
|
sx={{
|
|
|
|
|
position: "absolute",
|
|
|
|
|
width: "100%",
|
|
|
|
|
height: "100%",
|
|
|
|
|
top: 0,
|
|
|
|
|
}}
|
|
|
|
|
bg="overlay"
|
|
|
|
|
/>
|
2021-05-28 17:06:20 +10:00
|
|
|
<ReactResizeDetector
|
|
|
|
|
handleWidth
|
|
|
|
|
handleHeight
|
|
|
|
|
onResize={handleContainerResize}
|
|
|
|
|
>
|
2021-05-24 17:11:46 +10:00
|
|
|
<animated.div
|
|
|
|
|
style={{
|
|
|
|
|
...openAnimation,
|
|
|
|
|
position: "absolute",
|
|
|
|
|
width: "100%",
|
|
|
|
|
height: "100%",
|
|
|
|
|
top: 0,
|
|
|
|
|
display: "flex",
|
|
|
|
|
alignItems: "center",
|
|
|
|
|
justifyContent: "center",
|
|
|
|
|
cursor: "pointer",
|
|
|
|
|
pointerEvents: openGroupId ? undefined : "none",
|
|
|
|
|
}}
|
|
|
|
|
onClick={() => openGroupId && onGroupClose()}
|
|
|
|
|
>
|
|
|
|
|
<Box
|
|
|
|
|
sx={{
|
2021-05-28 17:06:20 +10:00
|
|
|
width: containerSize.width,
|
|
|
|
|
height: containerSize.height,
|
2021-05-24 17:11:46 +10:00
|
|
|
borderRadius: "8px",
|
|
|
|
|
border: "1px solid",
|
|
|
|
|
borderColor: "border",
|
|
|
|
|
cursor: "default",
|
|
|
|
|
display: "flex",
|
2021-06-05 18:05:35 +10:00
|
|
|
justifyContent: "flex-start",
|
|
|
|
|
alignItems: "center",
|
2021-05-24 17:11:46 +10:00
|
|
|
position: "relative",
|
2021-06-05 18:05:35 +10:00
|
|
|
flexDirection: "column",
|
2021-05-24 17:11:46 +10:00
|
|
|
}}
|
|
|
|
|
bg="background"
|
|
|
|
|
onClick={(e) => e.stopPropagation()}
|
|
|
|
|
>
|
2021-06-05 18:05:35 +10:00
|
|
|
<Flex my={1} sx={{ position: "relative" }}>
|
|
|
|
|
<Text as="p" my="2px">
|
|
|
|
|
{group?.name}
|
|
|
|
|
</Text>
|
|
|
|
|
<IconButton
|
|
|
|
|
sx={{
|
|
|
|
|
width: "24px",
|
|
|
|
|
height: "24px",
|
|
|
|
|
position: group?.name ? "absolute" : "relative",
|
|
|
|
|
left: group?.name ? "100%" : 0,
|
|
|
|
|
}}
|
|
|
|
|
title="Edit Group"
|
|
|
|
|
aria-label="Edit Group"
|
|
|
|
|
onClick={() => setIsGroupNameModalOpen(true)}
|
|
|
|
|
>
|
|
|
|
|
<ChangeNicknameIcon />
|
|
|
|
|
</IconButton>
|
|
|
|
|
</Flex>
|
2021-05-24 17:11:46 +10:00
|
|
|
<SimpleBar
|
|
|
|
|
style={{
|
2021-05-28 17:06:20 +10:00
|
|
|
width: containerSize.width - 16,
|
|
|
|
|
height: containerSize.height - 48,
|
2021-05-27 17:37:59 +10:00
|
|
|
marginBottom: "8px",
|
|
|
|
|
backgroundColor: theme.colors.muted,
|
2021-05-24 17:11:46 +10:00
|
|
|
}}
|
2021-05-27 17:37:59 +10:00
|
|
|
onClick={() => onGroupSelect()}
|
2021-05-24 17:11:46 +10:00
|
|
|
>
|
|
|
|
|
<Grid
|
|
|
|
|
sx={{
|
|
|
|
|
borderRadius: "4px",
|
|
|
|
|
overflow: "hidden",
|
2021-06-08 23:46:20 +10:00
|
|
|
position: "relative",
|
2021-05-24 17:11:46 +10:00
|
|
|
}}
|
|
|
|
|
gap={2}
|
2021-05-27 17:19:36 +10:00
|
|
|
columns={`repeat(${layout.groupGridColumns}, 1fr)`}
|
2021-05-27 17:37:59 +10:00
|
|
|
p={3}
|
2021-05-24 17:11:46 +10:00
|
|
|
>
|
2021-06-08 23:46:20 +10:00
|
|
|
<Droppable
|
|
|
|
|
id={ADD_TO_MAP_ID}
|
|
|
|
|
style={{
|
|
|
|
|
position: "absolute",
|
|
|
|
|
width: modalSize.width,
|
|
|
|
|
height: `calc(100% + ${
|
|
|
|
|
modalSize.height - containerSize.height + 48
|
|
|
|
|
}px)`,
|
|
|
|
|
left: `-${
|
|
|
|
|
(modalSize.width - containerSize.width) / 2 + 8
|
|
|
|
|
}px`,
|
|
|
|
|
top: `-${
|
|
|
|
|
(modalSize.height - containerSize.height) / 2 + 48
|
|
|
|
|
}px`,
|
|
|
|
|
zIndex: -1,
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
<Droppable
|
|
|
|
|
id={UNGROUP_ID}
|
|
|
|
|
style={{
|
|
|
|
|
position: "absolute",
|
2021-06-09 23:24:24 +10:00
|
|
|
top: 0,
|
|
|
|
|
bottom: 0,
|
|
|
|
|
left: 0,
|
|
|
|
|
right: 0,
|
2021-06-08 23:46:20 +10:00
|
|
|
zIndex: -1,
|
|
|
|
|
}}
|
|
|
|
|
/>
|
2021-05-24 17:11:46 +10:00
|
|
|
{children}
|
|
|
|
|
</Grid>
|
|
|
|
|
</SimpleBar>
|
|
|
|
|
<Close
|
|
|
|
|
onClick={() => onGroupClose()}
|
|
|
|
|
sx={{ position: "absolute", top: 0, right: 0 }}
|
|
|
|
|
/>
|
|
|
|
|
</Box>
|
|
|
|
|
</animated.div>
|
|
|
|
|
</ReactResizeDetector>
|
2021-06-05 18:05:35 +10:00
|
|
|
<GroupNameModal
|
|
|
|
|
isOpen={isGroupNameModalOpen}
|
|
|
|
|
name={group?.name}
|
|
|
|
|
onSubmit={handleGroupNameChange}
|
|
|
|
|
onRequestClose={() => setIsGroupNameModalOpen(false)}
|
|
|
|
|
/>
|
2021-05-24 17:11:46 +10:00
|
|
|
</>
|
2021-05-24 13:34:21 +10:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default TilesOverlay;
|