// @flow import React, { Component } from 'react'; import { Layout, Container, Header } from './Layout'; import CustomScrollbars from './CustomScrollbars'; import Accordion from './Accordion'; import ChevronDownSVG from '../assets/images/icon-chevron-down.svg'; import ChevronUpSVG from '../assets/images/icon-chevron-up.svg'; import TickSVG from '../assets/images/icon-tick.svg'; import type { SettingsReduxState } from '../redux/settings/reducers'; import type { RelayLocation, RelayListCity, RelayListCountry } from '../lib/ipc-facade'; export type SelectLocationProps = { settings: SettingsReduxState, onClose: () => void; onSelect: (location: RelayLocation) => void; }; export default class SelectLocation extends Component { props: SelectLocationProps; _selectedCell: ?HTMLElement; state = { expanded: ([]: Array), }; constructor(props: SelectLocationProps, context?: any) { super(props, context); // set initially expanded country based on relaySettings const relaySettings = this.props.settings.relaySettings; if(relaySettings.normal) { const { location } = relaySettings.normal; if(location === 'any') { // no-op } else if(location.country) { this.state.expanded.push(location.country); } else if(location.city) { this.state.expanded.push(location.city[0]); } } } componentDidMount() { // restore scroll to selected cell const cell = this._selectedCell; if(cell) { // this is non-standard webkit method but it works great! if(typeof(cell.scrollIntoViewIfNeeded) !== 'function') { console.warn('HTMLElement.scrollIntoViewIfNeeded() is not available anymore! Please replace it with viable alternative.'); return; } cell.scrollIntoViewIfNeeded(true); } } render() { return (