Skip to content

Commit 5a7e3df

Browse files
committed
feat: replace recoil with jotai
1 parent 6a37296 commit 5a7e3df

File tree

6 files changed

+660
-56
lines changed

6 files changed

+660
-56
lines changed

frontend/app/GlobalState.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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 {atom} from 'jotai';
14+
15+
export interface UserDataState {
16+
Longitude: number;
17+
Latitude: number;
18+
SearchRadius: number;
19+
PostCode: number;
20+
TargetDiesel: number;
21+
TargetE5: number;
22+
TargetE10: number;
23+
}
24+
25+
export enum FuelType {
26+
E5 = 'e5',
27+
E10 = 'e10',
28+
Diesel = 'diesel'
29+
}
30+
31+
const GlobalState = {
32+
jwtToken: '',
33+
userNameState: atom(''),
34+
userUuidState: atom(''),
35+
userDataState: atom({Latitude: 0.0, Longitude: 0.0, SearchRadius: 0, PostCode: 0, TargetDiesel: 0.0, TargetE10: 0.0, TargetE5: 0.0} as UserDataState),
36+
jwtTokenState: atom(''),
37+
locationModalState: atom(false),
38+
targetPriceModalState: atom(false),
39+
loginModalState: atom(true),
40+
fuelTypeState: atom(FuelType.E5),
41+
webWorkerRefState: atom<null|Worker>(null),
42+
}
43+
export default GlobalState;
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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+
.responseMsg {
14+
color: #ff0000;
15+
}
16+
17+
.toright {
18+
float: right;
19+
}

frontend/app/login/login.tsx

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,54 @@
1313
import { useNavigate } from "react-router";
1414
import Button from '@mui/material/Button';
1515
import * as React from 'react';
16+
import GlobalState from "~/GlobalState";
17+
import styles from './login.module.css';
18+
import { useAtom } from "jotai";
19+
20+
interface MsgData {
21+
jwtToken?: string;
22+
newNotificationUrl?: string;
23+
}
24+
25+
interface TabPanelProps {
26+
children?: React.ReactNode;
27+
index: number;
28+
value: number;
29+
}
30+
31+
function TabPanel(props: TabPanelProps) {
32+
const { children, value, index, ...other } = props;
33+
34+
return (
35+
<div
36+
role="tabpanel"
37+
hidden={value !== index}
38+
id={`simple-tabpanel-${index}`}
39+
aria-labelledby={`simple-tab-${index}`}
40+
{...other}
41+
>
42+
{value === index && (
43+
<>{children}</>
44+
)}
45+
</div>
46+
);
47+
}
1648

1749
export function Login() {
1850
const navigate = useNavigate();
19-
51+
let controller: AbortController | null = null;
52+
const [globalUserName,setGlobalUserName] = useAtom(GlobalState.userNameState);
53+
const [globalUuid,setGlobalUuid] = useAtom(GlobalState.userUuidState);
54+
const [globalJwtToken,setGlobalJwtToken] = useAtom(GlobalState.jwtTokenState);
55+
const [globalUserDataState,setGlobalUserDataState] = useAtom(GlobalState.userDataState);
56+
const [globalWebWorkerRefState, setGlobalWebWorkerRefState] = useAtom(GlobalState.webWorkerRefState);
57+
const [globalLoginModal, setGlobalLoginModal] = useAtom(GlobalState.loginModalState);
58+
const [userName, setUserName] = React.useState('');
59+
const [password1, setPassword1] = React.useState('');
60+
const [password2, setPassword2] = React.useState('');
61+
const [responseMsg, setResponseMsg] = React.useState('');
62+
const [activeTab, setActiveTab] = React.useState(0);
63+
2064
const navToApp = () => {
2165
navigate("/app/app");
2266
}

frontend/app/root.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import {
2121

2222
import type { Route } from "./+types/root";
2323
import "./root.css";
24-
import { RecoilRoot } from "recoil";
24+
import { Provider } from "jotai";
2525

2626
export const links: Route.LinksFunction = () => [
2727
{ rel: "preconnect", href: "https://fonts.googleapis.com" },
@@ -37,8 +37,8 @@ export const links: Route.LinksFunction = () => [
3737
];
3838

3939
export function Layout({ children }: { children: React.ReactNode }) {
40-
return (
41-
<RecoilRoot>
40+
return (
41+
<Provider>
4242
<html lang="en">
4343
<head>
4444
<meta charSet="utf-8" />
@@ -52,7 +52,7 @@ export function Layout({ children }: { children: React.ReactNode }) {
5252
<Scripts />
5353
</body>
5454
</html>
55-
</RecoilRoot>
55+
</Provider>
5656
);
5757
}
5858

0 commit comments

Comments
 (0)