import React, { useEffect, useState } from 'react' import { connect } from 'react-redux' import { t } from 'ttag' import config, { LayerConfig } from '../config' import { toggleLayer } from '../actions/layers' import ShapefileUpload from './ShapefileUpload' import { CustomLayer } from '../reducers/customLayers' import CustomLayerListItem from './CustomLayerListItem' type LayersProps = { layers: string[] customLayers: CustomLayer[] state: any onToggleLayer: (namne: string) => void } const Layers = ({ layers, customLayers, state, onToggleLayer }: LayersProps) => { const { layers: layersConfig, layerCategories } = config const [expanded, setExpanded] = useState([]) const [showColorPicker, setShowColorPicker] = useState('') useEffect(() => { if (!expanded.length) { setExpanded([...layerCategories.filter(c => c.showByDefault === true).map(c => c.label), 'custom']) } }, [expanded, layerCategories]) const customExpanded = expanded.includes('custom') return (
) } export default connect( (state: any) => { const { layers, customLayers } = state return { state, layers, customLayers } }, (dispatch: (action: any) => any) => { return { onToggleLayer: (name: string) => { dispatch(toggleLayer(name)) }, } }, )(Layers)