<commit_before>// @flow
import lonlat from '@conveyal/lonlat'
import React from 'react'
import {LayerGroup, Marker, Polyline} from 'react-leaflet'

import {NEW_LINE_WEIGHT} from '../../constants'
import colors from '../../constants/colors'
import {
  getNewStopIconForZoom,
  getSnappedStopIconForZoom,
  enlargeIconBy
} from '../map/circle-icons'
import DirectionalMarkers from '../directional-markers'
import getStops from '../../utils/get-stops'

import type {FeatureCollection, Segment, Stop} from '../../types'

type Props = {
  bidirectional: boolean,
  highlightSegment?: number,
  highlightStop?: any,
  segments: Segment[]
}

type State = {
  directionalMarkerPatterns: [
    {
      geometry: {
        coordinates: number[]
      }
    }
  ],
  geojson: FeatureCollection,
  stops: Stop[],
  stopRadius: number
}

/**
 * A layer to display (not edit) an added trip pattern
 */
export default class AddTripPatternLayer extends LayerGroup {
  props: Props
  state: State

  state = {
    ...getStateFromProps(this.props),
    newStopIcon: getNewStopIconForZoom(this.context.map.getZoom()),
    newSnappedStopIcon: getSnappedStopIconForZoom(this.context.map.getZoom())
  }

  componentDidMount () {
    super.componentDidMount()
    this.context.map.on('zoomend', this._onZoomend)
  }

  componentWillUnmount () {
    super.componentWillUnmount()
    this.context.map.off('zoomend', this._onZoomend)
  }

  _onZoomend = () => {
    const z = this.context.map.getZoom()
    this.setState({
      newStopIcon: getNewStopIconForZoom(z),
      newSnappedStopIcon: getSnappedStopIconForZoom(z)
    })
  }

  render () {
    const {
      directionalMarkerPatterns,
      newStopIcon,
      newSnappedStopIcon,
      segmentsPolylinePositions,
      stops
    } = this.state<commit_msg>fix(add-trip-pattern): Correctly update Add Trip Pattern map display layer on props change<commit_after>// @flow
import lonlat from '@conveyal/lonlat'
import React from 'react'
import {LayerGroup, Marker, Polyline} from 'react-leaflet'

import {NEW_LINE_WEIGHT} from '../../constants'
import colors from '../../constants/colors'
import {
  getNewStopIconForZoom,
  getSnappedStopIconForZoom,
  enlargeIconBy
} from '../map/circle-icons'
import DirectionalMarkers from '../directional-markers'
import getStops from '../../utils/get-stops'

import type {FeatureCollection, Segment, Stop} from '../../types'

type Props = {
  bidirectional: boolean,
  highlightSegment?: number,
  highlightStop?: any,
  segments: Segment[]
}

type State = {
  directionalMarkerPatterns: [
    {
      geometry: {
        coordinates: number[]
      }
    }
  ],
  geojson: FeatureCollection,
  stops: Stop[],
  stopRadius: number
}

/**
 * A layer to display (not edit) an added trip pattern
 */
export default class AddTripPatternLayer extends LayerGroup {
  props: Props
  state: State

  state = {
    ...getStateFromProps(this.props),
    newStopIcon: getNewStopIconForZoom(this.context.map.getZoom()),
    newSnappedStopIcon: getSnappedStopIconForZoom(this.context.map.getZoom())
  }

  componentWillReceiveProps (newProps: Props) {
    this.setState(getStateFromProps(newProps))
  }

  componentDidMount () {
    super.componentDidMount()
    this.context.map.on('zoomend', this._onZoomend)
  }

  componentWillUnmount () {
    super.componentWillUnmount()
    this.context.map.off('zoomend', this._onZoomend)
  }

  _onZoomend = () => {
    const z = this.context.map.getZoom()
    this.setState({
      newStopIcon: getNewStopIconForZoom(z),
      newSnappedStopIcon: getSnappedStopIconForZoom(z)
    })
  }

  render () {
    const {
      directionalMarkerPatterns,
      newStopIcon,
      newSnappedStopIcon,
      segmentsPolylinePositions,
      stops
    } = this.state
{'fraction_non_alphanumeric': 0.12070343725019984, 'fraction_numerical': 0.0, 'mean_word_length': 3.533816425120773, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1690557', 'n_tokens_mistral': 1190, 'n_tokens_neox': 1193, 'n_words': 250}