// @flow import React, { Component } from 'react'; import { If, Then } from 'react-if'; import { Layout, Container, Header } from './Layout'; import { servers } from '../config'; import CustomScrollbars from './CustomScrollbars'; import type { SettingsReduxState } from '../redux/settings/reducers'; export type SelectLocationProps = { settings: SettingsReduxState, onClose: () => void; onSelect: (server: string) => void; }; export default class SelectLocation extends Component { props: SelectLocationProps; _selectedCell: ?HTMLElement; onSelect(name: string) { this.props.onSelect(name); } isSelected(server: string) { return server === this.props.settings.preferredServer; } drawCell(key: string, name: string, icon: ?string, onClick: (e: Event) => void): React.Element<*> { const classes = ['select-location__cell']; const selected = this.isSelected(key); if(selected) { classes.push('select-location__cell--selected'); } const cellClass = classes.join(' '); return (
this.onCellRef(key, e) }>
{ name }
); } onCellRef(key: string, element: HTMLElement) { // save reference to selected cell if(this.isSelected(key)) { this._selectedCell = element; } } 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(): React.Element<*> { return (