import React, {Component} from 'react'; import Typed from 'typed.js'; import './Header.scss'; import {Button} from "react-bootstrap"; import StringConnectionsFilter from "../components/filters/StringConnectionsFilter"; import {cleanNumber, validateIpAddress, validateMin, validatePort} from "../utils"; import RulesConnectionsFilter from "../components/filters/RulesConnectionsFilter"; import {filtersDefinitions, filtersNames} from "../components/filters/FiltersDefinitions"; class Header extends Component { constructor(props) { super(props); this.state = {}; filtersNames.forEach(elem => this.state[`${elem}_active`] = false); this.fetchStateFromLocalStorage = this.fetchStateFromLocalStorage.bind(this); } componentDidMount() { const options = { strings: ["caronte$ "], typeSpeed: 50, cursorChar: "❚" }; this.typed = new Typed(this.el, options); this.fetchStateFromLocalStorage(); if (typeof window !== "undefined") { window.addEventListener("quick-filters", this.fetchStateFromLocalStorage); } } componentWillUnmount() { this.typed.destroy(); if (typeof window !== "undefined") { window.removeEventListener("quick-filters", this.fetchStateFromLocalStorage); } } fetchStateFromLocalStorage() { let newState = {}; filtersNames.forEach(elem => newState[`${elem}_active`] = localStorage.getItem(`filters.${elem}`) === "true"); this.setState(newState); } render() { let quickFilters = filtersNames.filter(name => this.state[`${name}_active`]) .map(name => filtersDefinitions[name]) .slice(0, 5); return (

{ this.el = el; }}/>

{quickFilters}
); } } export default Header;