2021-02-06 13:32:38 +11:00
|
|
|
import React, { useState } from "react";
|
2020-04-13 18:15:00 +10:00
|
|
|
import { IconButton } from "theme-ui";
|
2020-03-20 14:48:46 +11:00
|
|
|
|
2020-04-23 18:01:40 +10:00
|
|
|
import SelectMapModal from "../../modals/SelectMapModal";
|
|
|
|
|
import SelectMapIcon from "../../icons/SelectMapIcon";
|
2020-03-20 14:48:46 +11:00
|
|
|
|
2021-02-06 13:32:38 +11:00
|
|
|
import { useMapData } from "../../contexts/MapDataContext";
|
|
|
|
|
import { useAuth } from "../../contexts/AuthContext";
|
2020-05-19 16:33:23 +10:00
|
|
|
|
|
|
|
|
function SelectMapButton({
|
|
|
|
|
onMapChange,
|
|
|
|
|
onMapStateChange,
|
|
|
|
|
currentMap,
|
|
|
|
|
currentMapState,
|
2020-07-17 15:57:52 +10:00
|
|
|
disabled,
|
2020-05-19 16:33:23 +10:00
|
|
|
}) {
|
2020-05-19 16:21:01 +10:00
|
|
|
const [isModalOpen, setIsModalOpen] = useState(false);
|
2020-05-19 16:33:23 +10:00
|
|
|
|
2021-02-06 13:32:38 +11:00
|
|
|
const { updateMapState } = useMapData();
|
|
|
|
|
const { userId } = useAuth();
|
2020-03-20 14:48:46 +11:00
|
|
|
function openModal() {
|
2020-08-11 18:48:48 +10:00
|
|
|
if (currentMapState && currentMap && currentMap.owner === userId) {
|
|
|
|
|
updateMapState(currentMapState.mapId, currentMapState);
|
|
|
|
|
}
|
2020-05-19 16:21:01 +10:00
|
|
|
setIsModalOpen(true);
|
2020-03-20 14:48:46 +11:00
|
|
|
}
|
|
|
|
|
|
2020-04-23 21:54:58 +10:00
|
|
|
function handleDone() {
|
2020-06-27 11:18:47 +10:00
|
|
|
setIsModalOpen(false);
|
2020-03-20 14:48:46 +11:00
|
|
|
}
|
|
|
|
|
|
2020-03-19 17:33:57 +11:00
|
|
|
return (
|
|
|
|
|
<>
|
2020-04-23 18:01:40 +10:00
|
|
|
<IconButton
|
|
|
|
|
aria-label="Select Map"
|
|
|
|
|
title="Select Map"
|
|
|
|
|
onClick={openModal}
|
2020-07-17 15:57:52 +10:00
|
|
|
disabled={disabled}
|
2020-04-23 18:01:40 +10:00
|
|
|
>
|
|
|
|
|
<SelectMapIcon />
|
2020-03-19 17:33:57 +11:00
|
|
|
</IconButton>
|
2020-04-23 18:01:40 +10:00
|
|
|
<SelectMapModal
|
2020-05-19 16:21:01 +10:00
|
|
|
isOpen={isModalOpen}
|
2020-04-13 18:15:00 +10:00
|
|
|
onDone={handleDone}
|
2020-04-23 21:54:58 +10:00
|
|
|
onMapChange={onMapChange}
|
|
|
|
|
onMapStateChange={onMapStateChange}
|
|
|
|
|
currentMap={currentMap}
|
2020-04-13 18:15:00 +10:00
|
|
|
/>
|
2020-03-19 17:33:57 +11:00
|
|
|
</>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-23 18:01:40 +10:00
|
|
|
export default SelectMapButton;
|