Skip to content

Commit 0e51a6f

Browse files
committed
feat: add component
1 parent aaef773 commit 0e51a6f

File tree

5 files changed

+163
-2
lines changed

5 files changed

+163
-2
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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+
.headerBase {
14+
background-color: #0384fc;
15+
color: #ffffff;
16+
font-size: 24px;
17+
margin: auto;
18+
padding: 10px 0 10px 0;
19+
}
20+
21+
.headerButton {
22+
float: right;
23+
color: #ffffff !important;
24+
}

frontend/app/header/header.tsx

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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;
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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+
.myText {
14+
color: #000000;
15+
}
16+
17+
.headerTabs {
18+
display: flex;
19+
justify-content: space-around;
20+
}
21+
22+
.headerTab {
23+
width: fit-content;
24+
line-height: 2rem;
25+
}
26+
27+
.linkText {
28+
color: rgb(25, 118, 210);
29+
--Link-underlineColor: rgba(25, 118, 210, 0.4);
30+
font-family: "Roboto", "Helvetica", "Arial", sans-serif;
31+
font-weight: 400;
32+
text-decoration-color: var(--Link-underlineColor);
33+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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 './main-container.module.css';
15+
import Header from '../header/header';
16+
//import LocationModal from './components/LocationModal';
17+
//import TargetPriceModal from './components/TargetPriceModal';
18+
import Main from '../main/main';
19+
import { useAtom } from "jotai";
20+
import GlobalState from '../GlobalState';
21+
import { useEffect } from 'react';
22+
import { useNavigate } from 'react-router';
23+
24+
export interface TodoItem1 {
25+
name: string;
26+
id: string;
27+
}
28+
29+
function MainContainer() {
30+
const [globalJwtTokenState, setGlobalJwtTokenState] = useAtom(GlobalState.jwtTokenState);
31+
const [globalUserUuidState, setGlobalUserUuidState] = useAtom(GlobalState.userUuidState);
32+
const navigate = useNavigate();
33+
34+
useEffect(() => {
35+
if((!globalJwtTokenState || !globalUserUuidState || globalJwtTokenState.length < 10 || globalUserUuidState.length < 10)) {
36+
navigate('/');
37+
}
38+
});
39+
40+
return (
41+
<div className="App">
42+
<Header/>
43+
{/* <LocationModal/> */}
44+
{/* <TargetPriceModal/> */}
45+
<Main/>
46+
</div>
47+
);
48+
}
49+
50+
export default MainContainer;

frontend/app/routes/app.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
See the License for the specific language governing permissions and
1111
limitations under the License.
1212
*/
13-
import Main from "~/main/main";
1413
import type { Route } from "./+types/app";
1514
import { Welcome } from "~/welcome/welcome";
15+
import MainContainer from "~/main-container/main-container";
1616

1717
export function meta({}: Route.MetaArgs) {
1818
return [
@@ -22,5 +22,5 @@ export function meta({}: Route.MetaArgs) {
2222
}
2323

2424
export default function Home() {
25-
return <Main />;
25+
return <MainContainer />;
2626
}

0 commit comments

Comments
 (0)