/* eslint-disable @typescript-eslint/indent */ /* eslint-disable @typescript-eslint/no-unsafe-argument */ /* eslint-disable @typescript-eslint/no-unsafe-member-access */ /* eslint-disable @typescript-eslint/no-unsafe-assignment */ import React, { memo, useEffect, useMemo, useState } from 'react'; import { FormattedMessage, useIntl } from 'react-intl'; import { useAtomValue, useSetAtom } from 'jotai'; import useGetStyleKey from 'hooks/useGetStyleKey'; import updateStyle from 'common/utils/update-style'; import ZoomBase from './zoom-base'; import Conditional from './conditional'; import InputNumber from 'common/input-number'; import ColorPicker from 'common/color-picker'; import { Select, SelectTrigger, SelectValue, SelectIcon, SelectContent, SelectViewport, SelectItem, SelectItemText, SelectItemIndicator, } from 'common/select'; import { layerState, mapState, selectedLayerIDState, styleObjState, } from 'atoms/map'; import { columnsState, distinctState } from 'atoms/general'; import { Row, Column, Selector, Label } from 'common/styles'; import { ReactComponent as Arrow } from '../../assets/icons/arrow-down.svg'; import { ReactComponent as Check } from '../../assets/icons/tick.svg'; const options = [ 'static', 'dynamic', 'zoom', 'conditional', 'heatmap-density', ] as const; type OptionsType = typeof options[number]; interface IProps { type: | 'size' | 'color' | 'stroke' | 'stroke-color' | 'stroke-size' | 'stroke-opacity' | 'weight' | 'intensity'; } const BaseOn = ({ type }: IProps) => { const intl = useIntl(); const map = useAtomValue(mapState); const openLayerID = useAtomValue(selectedLayerIDState); const setStyleObj = useSetAtom(styleObjState); const columns = useAtomValue(columnsState); const distinctFunc = useAtomValue(distinctState); const layer = useAtomValue(layerState); const { styleKey, property } = useGetStyleKey(type); // @ts-ignore line const [size, setSize] = useState(layer?.layout?.[property] ?? 1); const [color, setColor] = useState( // @ts-ignore line layer?.paint?.[property] ?? '#C11010' ); const [method, setMethod] = useState(options[0]); const [methodType, setMethodType] = useState<'match' | 'step'>('match'); const [selectedCol, setSelectedCol] = useState(''); useEffect(() => { // @ts-ignore line // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access const expression = layer?.[styleKey]?.[property]; if (expression?.[0] === 'match' || expression?.[0] === 'step') { setMethod('conditional'); setMethodType(expression?.[0]); setSelectedCol(expression?.[1]?.[1]); } else if (expression?.[0] === 'interpolate') { if (expression?.[2]?.[0] === 'heatmap-density') setMethod('heatmap-density'); else setMethod('zoom'); } else if (expression?.[0] === 'get') setMethod('dynamic'); else setMethod('static'); if (['color', 'stroke-color'].includes(type)) setColor(expression ?? '#C11010'); if (['size', 'stroke-size', 'weight', 'intensity'].includes(type)) setSize(expression ?? 1); }, [layer, styleKey, property]); const component = useMemo(() => { return { static: ['color', 'stroke-color'].includes(type) ? ( // { if (property && styleKey && openLayerID && map) updateStyle( openLayerID, map, styleKey, property, newColor, setStyleObj ); }} /> ) : ( { if (property && styleKey && openLayerID && map) updateStyle( openLayerID, map, styleKey, property, number, setStyleObj ); }} /> ), dynamic: ( ), zoom: property && , 'heatmap-density': property && , conditional: property && ( ), }[method]; }, [ method, methodType, selectedCol, size, columns, property, styleKey, color, ]); return ( {method === 'static' && component} {method !== 'static' && {component}} ); }; export default memo(BaseOn);