import React from 'react'; import { connect } from 'react-redux'; import FontAwesomeIcon from '@fortawesome/react-fontawesome' import faSearch from '@fortawesome/fontawesome-free-solid/faSearch'; import faCode from '@fortawesome/fontawesome-free-solid/faCode'; import faBook from '@fortawesome/fontawesome-free-solid/faBook'; import faGithub from '@fortawesome/fontawesome-free-brands/faGithub'; import { Ellipsis, ExpandableListItem, ListItem } from '/components'; import { classes } from '/common/util'; import { actions as envActions } from '/reducers/env'; import 'github-fork-ribbon-css/gh-fork-ribbon.css'; import styles from './stylesheet.scss'; @connect( ({ env }) => ({ env }), { ...envActions } ) class Navigator extends React.Component { constructor(props) { super(props); const { categoryKey } = this.props.env; this.state = { poweredByOpened: false, categoriesOpened: { [categoryKey]: true, }, query: '', } } togglePoweredBy(poweredByOpened = !this.state.poweredByOpened) { this.setState({ poweredByOpened }); } toggleCategory(key, categoryOpened = !this.state.categoriesOpened[key]) { const categoriesOpened = { ...this.state.categoriesOpened, [key]: categoryOpened, }; this.setState({ categoriesOpened }); } handleChangeQuery(e) { const { categories } = this.props.env; const categoriesOpened = {}; const query = e.target.value; categories.forEach(category => { if (this.testQuery(name) || category.algorithms.find(algorithm => this.testQuery(algorithm.name))) { categoriesOpened[category.key] = true; } }); this.setState({ categoriesOpened, query }); } testQuery(value) { const { query } = this.state; return new RegExp(query, 'i').test(value); } render() { const { poweredByOpened, categoriesOpened, query } = this.state; const { className, style } = this.props; const { categoryKey: selectedCategoryKey, algorithmKey: selectedAlgorithmKey, categories } = this.props.env; return ( ); } } export default Navigator;