|
1 | 1 | import React, {ReactElement, useEffect, useState} from 'react';
|
2 |
| -import logo from '../assets/images/logos/logo.png'; |
3 |
| -import './App.css'; |
4 |
| -import {callBackendHealth} from "../background/api/api"; |
| 2 | +import {connect, ConnectedProps} from 'react-redux' |
| 3 | +import {addAccessToken, addRefreshToken} from "../background/redux/actions/tokens"; |
| 4 | +import {SystemState} from "../background/redux/actions/sytemState"; |
| 5 | +import {Button} from "react-bootstrap"; |
5 | 6 |
|
6 | 7 |
|
7 |
| -import {Button, Table, Container} from 'react-bootstrap'; |
8 |
| -import Header from "./basicElements/Header"; |
| 8 | +// this takes the redux store and maps everything that is needed to the function props |
| 9 | +const mapState = (state: SystemState) => ({ |
| 10 | + tokens: {refreshToken: state.tokens.refreshToken, accessToken: state.tokens.accessToken} |
| 11 | +}) |
9 | 12 |
|
10 |
| -function App():ReactElement { |
11 |
| - |
12 |
| - |
13 |
| - |
14 |
| - const [backendLiveTime, setBackendLiveTime] = useState<number | string>("not reachable"); |
15 |
| - const [backendUserCount, setBackendUserCount] = useState<number | string>("not reachable"); |
| 13 | +// this takes the redux actions and maps them to the props |
| 14 | +const mapDispatch = { |
| 15 | + addRefreshToken, addAccessToken |
| 16 | +} |
16 | 17 |
|
| 18 | +const connector = connect(mapState, mapDispatch) |
17 | 19 |
|
| 20 | +type PropsFromRedux = ConnectedProps<typeof connector> |
18 | 21 |
|
| 22 | +// this defines the component props and also adds the redux imported props |
| 23 | +type Props = PropsFromRedux & {} |
19 | 24 |
|
| 25 | +function App(props: Props): ReactElement { |
20 | 26 |
|
21 |
| - useEffect(() => { |
22 |
| - callInitialBackendRequests() |
23 |
| - // eslint-disable-next-line react-hooks/exhaustive-deps |
24 |
| - },[]); |
25 | 27 |
|
26 |
| - function callInitialBackendRequests():void { |
27 |
| - updateVariables() |
28 |
| - } |
| 28 | + console.log(props.tokens.refreshToken) |
| 29 | + console.log(props.tokens) |
29 | 30 |
|
30 |
| - function updateVariables(): void { |
31 |
| - Promise.all([callBackendHealth()]) |
32 |
| - .then(([backendHealthData]) => { |
33 |
| - setBackendLiveTime(backendHealthData.uptimeInSeconds); |
34 |
| - setBackendUserCount(backendHealthData.userCount) |
35 |
| - }) |
36 |
| - } |
37 | 31 |
|
38 | 32 | return (
|
39 | 33 | <div className="App">
|
40 |
| - <Header></Header> |
41 |
| - <Container> |
42 |
| - <h1> |
43 |
| - FileFighter |
44 |
| - </h1> |
45 |
| - |
46 |
| - |
47 |
| - <img src={logo} alt="logo"/> |
48 |
| - |
49 |
| - |
50 |
| - |
51 |
| - <div> |
52 |
| - <Button className={"mt-3 mb-2 float-right"} onClick={() => updateVariables()}>Refresh</Button> |
53 |
| - <Table striped bordered hover variant="dark" > |
54 |
| - <thead> |
55 |
| - <tr> |
56 |
| - <th>Backend information</th> |
57 |
| - |
58 |
| - </tr> |
59 |
| - </thead> |
60 |
| - <tbody> |
61 |
| - <tr> |
62 |
| - <td>Uptime</td> |
63 |
| - <td>{backendLiveTime}</td> |
64 |
| - </tr> |
65 |
| - <tr> |
66 |
| - <td>Usercount</td> |
67 |
| - <td>{backendUserCount}</td> |
68 |
| - </tr> |
69 |
| - </tbody> |
70 |
| - </Table> |
71 |
| - </div> |
72 |
| - </Container> |
| 34 | + <Button onClick={() => props.addAccessToken({token:"bva",timestamp:1243})}>test (look in the console)</Button> |
| 35 | + <Button onClick={() => props.addRefreshToken("bgsgfhz")}>Refreshtoken (look in the console)</Button> |
73 | 36 | </div>
|
74 | 37 | );
|
75 | 38 | }
|
76 | 39 |
|
77 |
| -export default App; |
| 40 | +export default connector(App); |
0 commit comments