import React, { Component } from "react"; import { NavLink } from "react-router-dom"; import Modal from "react-modal"; import "../assets/stylesheets/navbar.scss"; Modal.setAppElement("#root"); export default class NavBar extends Component { constructor(props) { super(props); this.state = { clicks: 0, modalOpen_return: false, modalOpacity: 0, }; this.openModal = this.openModal.bind(this); this.closeModal = this.closeModal.bind(this); } componentDidMount() { let path = window.location.pathname; if (path.includes("statistics")) { document.getElementById("statistics").style.backgroundColor = "#007CBE"; document.getElementById("statistics-s").style.color = "white"; } else if (path.includes("map")) { document.getElementById("map").style.backgroundColor = "#007CBE"; document.getElementById("map-s").style.color = "white"; } else if (path.includes("cable")) { document.getElementById("browse").style.backgroundColor = "#007CBE"; document.getElementById("browse-s").style.color = "white"; } else { document.getElementById("browse").style.backgroundColor = "#007CBE"; document.getElementById("browse-s").style.color = "white"; } } handleClick = () => { const { clicks, timer } = this.state; if (clicks === 0) { const newTimer = setTimeout(() => { this.setState({ clicks: 0 }); clearTimeout(newTimer); }, 1000); this.setState({ timer: newTimer }); } this.setState({ clicks: clicks + 1 }); if (clicks + 1 === 2) { window.location.replace("/settings"); clearTimeout(timer); this.setState({ clicks: 0, timer: null }); } }; componentWillUnmount() { if (this.state.timer) { clearTimeout(this.state.timer); } } openModal = (modal) => { this.setState({ [modal]: true }, () => { setTimeout(() => this.setState({ modalOpacity: 1 }), 10); }); }; closeModal = (modal) => { this.setState({ modalOpacity: 0 }, () => { setTimeout(() => this.setState({ [modal]: false }), 300); }); }; returnCable = (tray) => { this.props.socket.send( `{"type": "cable_get","call": "send","data": {"tray": ${tray}}}` ); console.log("Cable returned from tray " + tray); this.closeModal("modalOpen_return"); }; render() { const { modalOpen_return, modalOpacity } = this.state; const modalStyle = { content: { opacity: modalOpacity, transition: "opacity 300ms ease-in-out", top: "50%", left: "50%", right: "auto", bottom: "auto", marginRight: "-50%", width: "auto", height: "auto", transform: "translate(-50%, -50%)", overflow: "hidden", display: "flex", flexDirection: "column", justifyContent: "center", alignItems: "center", borderRadius: "20px", background: "linear-gradient(-30deg, rgb(187, 194, 236) 0%, rgba(255, 255, 255, 1) 100%)", boxShadow: "0 0 20px rgba(0, 0, 0, 0.5)", minWidth: "30%", minHeight: "30%" }, overlay: { opacity: modalOpacity, transition: "opacity 300ms ease-in-out", backgroundColor: "rgba(255, 255, 255, 0.15)", backdropFilter: "blur(5px)", }, }; return (