-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathApp.tsx
135 lines (125 loc) · 3.26 KB
/
App.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
import React, {useCallback, useState} from 'react';
import { BrowserRouter as Router, Route, Switch } from "react-router-dom";
import { initializeApp } from "firebase/app";
import { getAnalytics } from "firebase/analytics";
import './App.scss';
import './components/widgets/TimeSelector';
import Feedback from './components/pages/Feedback';
import Start from './components/pages/Start';
import ChargingSession from './components/pages/ChargingSession';
import Schedule from './components/pages/Schedule';
import {ChargingMode} from "./data/models/ChargingMode";
/**
* Default deaprture time: 17:30
*/
const firebaseConfig = {
apiKey: "AIzaSyAQckdYeatXEj2BAA-D-7p_IM6RAId9P08",
authDomain: "design-project-c4242.firebaseapp.com",
projectId: "design-project-c4242",
storageBucket: "design-project-c4242.appspot.com",
messagingSenderId: "61399143585",
appId: "1:61399143585:web:fef93464a561a110280ce0",
measurementId: "G-CL6CR3FFGS"
};
// Initialize Firebase
const app = initializeApp(firebaseConfig);
const analytics = getAnalytics(app);
const DEFAULT_TIME = {hour: 17, minutes: 30};
/**
* Default chargind mode: none (unselected)
*/
const DEFAULT_MODE: ChargingMode | null = null;
export interface SessionType {
/**
* Type of the mode of the charging session: either fast or solar power mode; null is default.
*/
mode: ChargingMode | null,
/**
* Type of the hour of the user's expected departure time.
*/
hour: number,
/**
* Type of the minutes of the user's expected departure time.
*/
minutes: number,
/**
* Type of the price of the charging session.
*/
price: number,
/**
* Type of the CO2 emmisions of the charging session.
*/
CO2: number,
/**
* Type of the user's desired energy.
*/
energy: number,
}
/**
* Defines the charging settings: mode, departure time, price and CO2 emmissions.
* @returns - Router with paths to all main components.
*/
export default function App() {
/**
* Default values for the charging settings.
*/
const defaultState: SessionType = {
/**
* Default hour is 5.
*/
hour: DEFAULT_TIME.hour,
/**
* Default minutes are 30.
*/
minutes: DEFAULT_TIME.minutes,
/**
* Default mode is unselected (null).
*/
mode: DEFAULT_MODE,
/**
* Price is 0 by default.
*/
price: 0,
/**
* CO2 emmisisons are 0 by default.
*/
CO2: 0,
/**
* Desired energy is 0 be default.
*/
energy: 0,
}
const [settings, setSetting] = useState<SessionType>(defaultState);
const setSettings = (values: SessionType) => {
setSetting({
...settings,
hour: values.hour,
minutes: values.minutes,
mode: values.mode,
price: values.price,
energy: values.energy,
CO2: values.CO2,
})
};
return (
<Router>
<Switch>
<Route exact path="/">
<Start />
</Route>
<Route path="/session">
<ChargingSession
settings={settings}/>
</Route>
<Route path="/schedule">
<Schedule
settings={settings}
setSettings={setSettings}/>
</Route>
<Route path="/feedback">
<Feedback/>
</Route>
</Switch>
</Router>
);
}