blob: a841d383e3a82ea5f16e534498d4b1b515ff26a6 [file] [log] [blame]
pineafan54a1e552021-09-03 17:51:18 +01001import React, { Component } from "react";
pineafana5ce9102021-09-02 17:21:31 +01002import Styles from '../styles/navbar.module.css';
pineafandf39fd42021-09-04 16:05:27 +01003import Cookies from 'js-cookie';
4// import { setInfo } from "../redux/actions/main"
5import { connect } from "react-redux";
6// import { makeStore } from "../redux/store";
7
8// const store = makeStore();
pineafana5ce9102021-09-02 17:21:31 +01009
10class NavBar extends Component {
11 constructor(props) {
12 super(props);
13 this.state = {
pineafandf39fd42021-09-04 16:05:27 +010014 isOpen: false,
15 cookie: 'light'
pineafana5ce9102021-09-02 17:21:31 +010016 }
Samuel Shuert604e31d2021-09-02 16:06:20 -050017 this.isTouchDevice = false
pineafan54a1e552021-09-03 17:51:18 +010018 this.hoverSensor = React.createRef();
pineafana5ce9102021-09-02 17:21:31 +010019 }
pineafan54a1e552021-09-03 17:51:18 +010020
Samuel Shuert604e31d2021-09-02 16:06:20 -050021 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 }
pineafandf39fd42021-09-04 16:05:27 +010043 this.setState({
44 cookie: Cookies.get('theme')
45 })
Samuel Shuert604e31d2021-09-02 16:06:20 -050046 }
47
Samuel Shuert604e31d2021-09-02 16:06:20 -050048 onClick() {
49 if ( this.isTouchDevice ) {
50 return this.toggleVertical(this)
51 }
52 }
pineafana5ce9102021-09-02 17:21:31 +010053
54 toggleVertical(prevState, force=null) {
55 this.setState(prevState => ({
56 isOpen: (force === null) ? !prevState.isOpen : force
57 }));
58 }
59
pineafandf39fd42021-09-04 16:05:27 +010060 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
pineafana5ce9102021-09-02 17:21:31 +010074 render() {
75 return (
76 <>
pineafand494b852021-09-03 19:49:49 +010077 <div ref={this.hoverSensor} className={this.isTouchDevice ? (Styles.container + " " + (this.state.isOpen ? Styles.containerOpen : null)) : Styles.containerDesktop + " " + Styles.container}>
pineafana5ce9102021-09-02 17:21:31 +010078 <div className={Styles.group}>
pineafanaed30242021-09-04 09:33:40 +010079 <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 Shuert604e31d2021-09-02 16:06:20 -050084 {/* <a href="/castaway#"><img className={Styles.icon} src="/Icons/CA.svg"/></a> */}
Samuel Shuert52f37772021-09-02 12:29:40 -050085 {/* <a href="https://clcks.dev"><img className={Styles.icon} src="/Icons/CL.svg"/></a> */}
pineafana5ce9102021-09-02 17:21:31 +010086 </div>
87 <div className={Styles.group}>
pineafandf39fd42021-09-04 16:05:27 +010088 <a onClick={this.updateCookie(this)}><img
89 alt="Theme"
90 className={Styles.icon}
91 src={this.state.cookie + ".svg"}
92 /></a>
pineafana5ce9102021-09-02 17:21:31 +010093 </div>
94 </div>
95 </>
96 )
97 }
98}
99
pineafandf39fd42021-09-04 16:05:27 +0100100
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
pineafana5ce9102021-09-02 17:21:31 +0100112export default NavBar;