import React from "react"; import { Flex, Box, Text, IconButton, Close, Grid } from "theme-ui"; import SimpleBar from "simplebar-react"; import { DndContext } from "@dnd-kit/core"; import { SortableContext, arrayMove } from "@dnd-kit/sortable"; import RemoveMapIcon from "../../icons/RemoveMapIcon"; import ResetMapIcon from "../../icons/ResetMapIcon"; import MapTile from "./MapTile"; import Link from "../Link"; import FilterBar from "../FilterBar"; import Sortable from "../Sortable"; import { useDatabase } from "../../contexts/DatabaseContext"; import useResponsiveLayout from "../../hooks/useResponsiveLayout"; function MapTiles({ maps, groups, selectedMaps, selectedMapStates, onMapSelect, onMapsRemove, onMapsReset, onMapAdd, onMapEdit, onDone, selectMode, onSelectModeChange, search, onSearchChange, onMapsGroup, }) { const { databaseStatus } = useDatabase(); const layout = useResponsiveLayout(); let hasMapState = false; for (let state of selectedMapStates) { if ( Object.values(state.tokens).length > 0 || Object.values(state.drawShapes).length > 0 || Object.values(state.fogShapes).length > 0 || Object.values(state.notes).length > 0 ) { hasMapState = true; break; } } let hasSelectedDefaultMap = selectedMaps.some( (map) => map.type === "default" ); function mapToTile(map) { const isSelected = selectedMaps.includes(map); return ( ); } const multipleSelected = selectedMaps.length > 1; function handleDragEnd({ active, over }) { if (active && over && active.id !== over.id) { const oldIndex = groups.indexOf(active.id); const newIndex = groups.indexOf(over.id); onMapsGroup(arrayMove(groups, oldIndex, newIndex)); } } return ( onMapSelect()} search={search} onSearchChange={onSearchChange} selectMode={selectMode} onSelectModeChange={onSelectModeChange} onAdd={onMapAdd} addTitle="Add Map" /> onMapSelect()} > {groups.map((mapId) => ( {mapToTile(maps.find((map) => map.id === mapId))} ))} {databaseStatus === "disabled" && ( Map saving is unavailable. See FAQ{" "} for more information. )} {selectedMaps.length > 0 && ( onMapSelect()} /> onMapsReset()} disabled={!hasMapState} > onMapsRemove()} disabled={hasSelectedDefaultMap} > )} ); } export default MapTiles;