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