pineafan | 54a1e55 | 2021-09-03 17:51:18 +0100 | [diff] [blame] | 1 | import React, { Component } from "react"; |
pineafan | a5ce910 | 2021-09-02 17:21:31 +0100 | [diff] [blame] | 2 | import Styles from '../styles/navbar.module.css'; |
pineafan | df39fd4 | 2021-09-04 16:05:27 +0100 | [diff] [blame] | 3 | import Cookies from 'js-cookie'; |
| 4 | // import { setInfo } from "../redux/actions/main" |
pineafan | 8808b71 | 2021-09-04 16:11:30 +0100 | [diff] [blame^] | 5 | // import { connect } from "react-redux"; |
pineafan | df39fd4 | 2021-09-04 16:05:27 +0100 | [diff] [blame] | 6 | // import { makeStore } from "../redux/store"; |
| 7 | |
| 8 | // const store = makeStore(); |
pineafan | a5ce910 | 2021-09-02 17:21:31 +0100 | [diff] [blame] | 9 | |
| 10 | class NavBar extends Component { |
| 11 | constructor(props) { |
| 12 | super(props); |
| 13 | this.state = { |
pineafan | df39fd4 | 2021-09-04 16:05:27 +0100 | [diff] [blame] | 14 | isOpen: false, |
| 15 | cookie: 'light' |
pineafan | a5ce910 | 2021-09-02 17:21:31 +0100 | [diff] [blame] | 16 | } |
Samuel Shuert | 604e31d | 2021-09-02 16:06:20 -0500 | [diff] [blame] | 17 | this.isTouchDevice = false |
pineafan | 54a1e55 | 2021-09-03 17:51:18 +0100 | [diff] [blame] | 18 | this.hoverSensor = React.createRef(); |
pineafan | a5ce910 | 2021-09-02 17:21:31 +0100 | [diff] [blame] | 19 | } |
pineafan | 54a1e55 | 2021-09-03 17:51:18 +0100 | [diff] [blame] | 20 | |
Samuel Shuert | 604e31d | 2021-09-02 16:06:20 -0500 | [diff] [blame] | 21 | componentDidMount() { |
| 22 | let hasTouchScreen = false; |
| 23 | if ("maxTouchPoints" in navigator) { |
| 24 | hasTouchScreen = navigator.maxTouchPoints > 0; |
| 25 | } else if ("msMaxTouchPoints" in navigator) { |
| 26 | hasTouchScreen = navigator.msMaxTouchPoints > 0; |
| 27 | } else { |
| 28 | const mQ = window.matchMedia && matchMedia("(pointer:coarse)"); |
| 29 | if (mQ && mQ.media === "(pointer:coarse)") { |
| 30 | hasTouchScreen = !!mQ.matches; |
| 31 | } else if ("orientation" in window) { |
| 32 | hasTouchScreen = true; |
| 33 | } else { |
| 34 | var UA = navigator.userAgent; |
| 35 | hasTouchScreen = /\b(BlackBerry|webOS|iPhone|IEMobile)\b/i.test(UA) || /\b(Android|Windows Phone|iPad|iPod)\b/i.test(UA); |
| 36 | } |
| 37 | } |
| 38 | if (hasTouchScreen) { |
| 39 | this.isTouchDevice = true |
| 40 | } else { |
| 41 | this.isTouchDevice = false |
| 42 | } |
pineafan | df39fd4 | 2021-09-04 16:05:27 +0100 | [diff] [blame] | 43 | this.setState({ |
| 44 | cookie: Cookies.get('theme') |
| 45 | }) |
Samuel Shuert | 604e31d | 2021-09-02 16:06:20 -0500 | [diff] [blame] | 46 | } |
| 47 | |
Samuel Shuert | 604e31d | 2021-09-02 16:06:20 -0500 | [diff] [blame] | 48 | onClick() { |
| 49 | if ( this.isTouchDevice ) { |
| 50 | return this.toggleVertical(this) |
| 51 | } |
| 52 | } |
pineafan | a5ce910 | 2021-09-02 17:21:31 +0100 | [diff] [blame] | 53 | |
| 54 | toggleVertical(prevState, force=null) { |
| 55 | this.setState(prevState => ({ |
| 56 | isOpen: (force === null) ? !prevState.isOpen : force |
| 57 | })); |
| 58 | } |
| 59 | |
pineafan | df39fd4 | 2021-09-04 16:05:27 +0100 | [diff] [blame] | 60 | updateCookie(that) { |
| 61 | // return () => { |
| 62 | // if (that.props.theme == "light") { |
| 63 | // that.props.setInfo('dark') |
| 64 | // } else { |
| 65 | // that.props.setInfo('light') |
| 66 | // } |
| 67 | // this.setState({ |
| 68 | // cookie: that.props.theme |
| 69 | // }) |
| 70 | // // store.dispatch(); |
| 71 | // } |
| 72 | } |
| 73 | |
pineafan | a5ce910 | 2021-09-02 17:21:31 +0100 | [diff] [blame] | 74 | render() { |
| 75 | return ( |
| 76 | <> |
pineafan | d494b85 | 2021-09-03 19:49:49 +0100 | [diff] [blame] | 77 | <div ref={this.hoverSensor} className={this.isTouchDevice ? (Styles.container + " " + (this.state.isOpen ? Styles.containerOpen : null)) : Styles.containerDesktop + " " + Styles.container}> |
pineafan | a5ce910 | 2021-09-02 17:21:31 +0100 | [diff] [blame] | 78 | <div className={Styles.group}> |
pineafan | aed3024 | 2021-09-04 09:33:40 +0100 | [diff] [blame] | 79 | <img alt="CMP" className={Styles.headerIcon} src="/Icons/CMP.svg" onClick={() => {this.onClick()}}/> |
| 80 | <a href="/#"><img alt="Home" className={Styles.icon} src="/Icons/Homepage.svg"/></a> |
| 81 | <a href="/gps#"><img alt="GPS" className={Styles.icon} src="/Icons/GS.svg"/></a> |
| 82 | <a href="/rsm#"><img alt="RSM" className={Styles.icon} src="/Icons/RM.svg"/></a> |
| 83 | <a href="/clicksforms#"><img alt="ClicksForms" className={Styles.icon} src="/Icons/CF.svg"/></a> |
Samuel Shuert | 604e31d | 2021-09-02 16:06:20 -0500 | [diff] [blame] | 84 | {/* <a href="/castaway#"><img className={Styles.icon} src="/Icons/CA.svg"/></a> */} |
Samuel Shuert | 52f3777 | 2021-09-02 12:29:40 -0500 | [diff] [blame] | 85 | {/* <a href="https://clcks.dev"><img className={Styles.icon} src="/Icons/CL.svg"/></a> */} |
pineafan | a5ce910 | 2021-09-02 17:21:31 +0100 | [diff] [blame] | 86 | </div> |
| 87 | <div className={Styles.group}> |
pineafan | df39fd4 | 2021-09-04 16:05:27 +0100 | [diff] [blame] | 88 | <a onClick={this.updateCookie(this)}><img |
| 89 | alt="Theme" |
| 90 | className={Styles.icon} |
| 91 | src={this.state.cookie + ".svg"} |
| 92 | /></a> |
pineafan | a5ce910 | 2021-09-02 17:21:31 +0100 | [diff] [blame] | 93 | </div> |
| 94 | </div> |
| 95 | </> |
| 96 | ) |
| 97 | } |
| 98 | } |
| 99 | |
pineafan | df39fd4 | 2021-09-04 16:05:27 +0100 | [diff] [blame] | 100 | |
| 101 | // const mapStateToProps = state => { |
| 102 | // return { theme: state.main.theme } |
| 103 | // } |
| 104 | |
| 105 | // const mapDispatchToProps = { |
| 106 | // setInfo |
| 107 | // } |
| 108 | |
| 109 | // const nav = connect(mapStateToProps, mapDispatchToProps)(NavBar); |
| 110 | // export default nav; |
| 111 | |
pineafan | a5ce910 | 2021-09-02 17:21:31 +0100 | [diff] [blame] | 112 | export default NavBar; |