|
| 1 | +/* |
| 2 | + - Copyright 2022 Sven Loesekann |
| 3 | + Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | + you may not use this file except in compliance with the License. |
| 5 | + You may obtain a copy of the License at |
| 6 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 7 | + Unless required by applicable law or agreed to in writing, software |
| 8 | + distributed under the License is distributed on an "AS IS" BASIS, |
| 9 | + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 10 | + See the License for the specific language governing permissions and |
| 11 | + limitations under the License. |
| 12 | +*/ |
| 13 | +import * as React from 'react'; |
| 14 | +import styles from "./header.module.css"; |
| 15 | +import {Button} from '@mui/material'; |
| 16 | +import type { FormEvent } from 'react'; |
| 17 | +import { useAtom } from "jotai"; |
| 18 | + |
| 19 | +import GlobalState from "../GlobalState"; |
| 20 | +import { useNavigate } from "react-router"; |
| 21 | + |
| 22 | +const Header = () => { |
| 23 | + const [locationModalState, setLocationModalState] = useAtom(GlobalState.locationModalState); |
| 24 | + const [targetPriceModalState, setTargetPriceModalState] = useAtom(GlobalState.targetPriceModalState); |
| 25 | + const [jwtTokenState, setJwtTokenState] = useAtom(GlobalState.jwtTokenState); |
| 26 | + const [globalLoginModal, setGlobalLoginModal] = useAtom(GlobalState.loginModalState); |
| 27 | + const [globalWebWorkerRefState, setGlobalWebWorkerRefState] = useAtom(GlobalState.webWorkerRefState); |
| 28 | + const navigate = useNavigate(); |
| 29 | + |
| 30 | + const logout = (event: FormEvent) => { |
| 31 | + console.log("Logout ",event); |
| 32 | + setJwtTokenState(''); |
| 33 | + globalWebWorkerRefState?.postMessage({jwtToken: '', newNotificationUrl: ''}); |
| 34 | + setGlobalWebWorkerRefState(null); |
| 35 | + setGlobalLoginModal(true); |
| 36 | + navigate('/'); |
| 37 | + } |
| 38 | + const location = (event: FormEvent) => { |
| 39 | + //console.log("Location ",event); |
| 40 | + setLocationModalState(true) |
| 41 | + } |
| 42 | + const targetPrice = (event: FormEvent) => { |
| 43 | + setTargetPriceModalState(true); |
| 44 | + } |
| 45 | + |
| 46 | + return <div className={styles.headerBase}> |
| 47 | + <span>Cheap Gas</span> |
| 48 | + <Button variant="outlined" onClick={logout} className={styles.headerButton}>Logout</Button> |
| 49 | + <Button variant="outlined" onClick={location} className={styles.headerButton}>Location</Button> |
| 50 | + <Button variant="outlined" onClick={targetPrice} className={styles.headerButton}>Target Price</Button> |
| 51 | + </div> |
| 52 | +} |
| 53 | + |
| 54 | +export default Header; |
0 commit comments