Skip to content
This repository was archived by the owner on Apr 5, 2024. It is now read-only.

Commit 4328c74

Browse files
committed
Merge branch 'review' into feature/addUser
# Conflicts: # webapp_frontend/package-lock.json # webapp_frontend/package.json # webapp_frontend/src/components/App.tsx # webapp_frontend/src/components/Constants.tsx
2 parents 24c25b7 + 2ff7f00 commit 4328c74

File tree

11 files changed

+189
-6
lines changed

11 files changed

+189
-6
lines changed

webapp_frontend/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,18 @@
1313
"@types/react-bootstrap": "^0.32.24",
1414
"@types/react-dom": "^16.9.8",
1515
"@types/react-router-dom": "^5.1.6",
16+
"@types/react-redux": "^7.1.11",
1617
"axios": "^0.20.0",
1718
"bootstrap": "^4.5.3",
1819
"node-sass": "^4.14.1",
1920
"react": "^16.13.1",
2021
"react-bootstrap": "^1.4.0",
2122
"react-dom": "^16.13.1",
2223
"react-router-dom": "^5.2.0",
24+
"react-redux": "^7.2.2",
2325
"react-scripts": "3.4.3",
2426
"react-toastify": "^6.1.0",
27+
"redux": "^4.0.5",
2528
"typescript": "^3.8.3"
2629
},
2730
"scripts": {

webapp_frontend/src/background/constants.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
interface constants {
32
url: { API_URL: string }
43
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import {TokensState} from "./tokenTypes";
2+
3+
export interface SystemState {
4+
tokens: TokensState
5+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
export const ADD_REFRESH_TOKEN = "ADD_REFRESH_TOKEN";
2+
export const ADD_ACCESS_TOKEN = "ADD_ACCESS_TOKEN";
3+
4+
5+
export interface AccessToken{
6+
token: string | null;
7+
timestamp: number | null;
8+
}
9+
10+
11+
export interface TokensState {
12+
refreshToken: string | null;
13+
accessToken: AccessToken | null;
14+
}
15+
16+
17+
interface AddRefreshToken {
18+
type: typeof ADD_REFRESH_TOKEN
19+
payload: string
20+
}
21+
22+
interface AddAccessToken {
23+
type: typeof ADD_ACCESS_TOKEN
24+
payload: AccessToken
25+
}
26+
27+
export type TokenActionsTypes = AddRefreshToken | AddAccessToken;
28+
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import {ADD_REFRESH_TOKEN, ADD_ACCESS_TOKEN, AccessToken} from "./tokenTypes";
2+
3+
4+
export const addRefreshToken = (content: string) => ({
5+
type: ADD_REFRESH_TOKEN,
6+
payload: content
7+
});
8+
9+
export const addAccessToken = (content: AccessToken) => ({
10+
type: ADD_ACCESS_TOKEN,
11+
payload: content
12+
});
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import {combineReducers} from "redux";
2+
import tokens from "./tokens";
3+
4+
// this combines all the stores from the reducers
5+
export default combineReducers({tokens});
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import {ADD_REFRESH_TOKEN, ADD_ACCESS_TOKEN, TokenActionsTypes, TokensState, AccessToken} from "../actions/tokenTypes";
2+
3+
const initialState: TokensState = {
4+
refreshToken: null,
5+
accessToken: null,
6+
};
7+
8+
export default function (state = initialState, action: TokenActionsTypes) {
9+
switch (action.type) {
10+
case ADD_REFRESH_TOKEN: {
11+
const refreshToken: string = action.payload;
12+
return {
13+
refreshToken: refreshToken,
14+
accessToken: initialState.accessToken
15+
};
16+
}
17+
case ADD_ACCESS_TOKEN: {
18+
const accessToken: AccessToken = action.payload;
19+
return {
20+
refreshToken: initialState.refreshToken,
21+
accessToken: accessToken
22+
};
23+
}
24+
default:
25+
return state;
26+
}
27+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import { createStore } from "redux";
2+
import rootReducer from "./reducers";
3+
4+
export default createStore(rootReducer);

webapp_frontend/src/components/App.tsx

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,35 @@ import Router from "./Router/Router";
88
import PermanentAssets from "./basicElements/PermanentAssets";
99

1010
function App(): ReactElement {
11+
import React, {ReactElement, useEffect, useState} from 'react';
12+
import {connect, ConnectedProps} from 'react-redux'
13+
import {addAccessToken, addRefreshToken} from "../background/redux/actions/tokens";
14+
import {SystemState} from "../background/redux/actions/sytemState";
15+
import {Button} from "react-bootstrap";
16+
17+
18+
// this takes the redux store and maps everything that is needed to the function props
19+
const mapState = (state: SystemState) => ({
20+
tokens: {refreshToken: state.tokens.refreshToken, accessToken: state.tokens.accessToken}
21+
})
22+
23+
// this takes the redux actions and maps them to the props
24+
const mapDispatch = {
25+
addRefreshToken, addAccessToken
26+
}
27+
28+
const connector = connect(mapState, mapDispatch)
29+
30+
type PropsFromRedux = ConnectedProps<typeof connector>
31+
32+
// this defines the component props and also adds the redux imported props
33+
type Props = PropsFromRedux & {}
34+
35+
function App(props: Props): ReactElement {
36+
37+
38+
console.log(props.tokens.refreshToken)
39+
console.log(props.tokens)
1140

1241

1342
return (
@@ -24,4 +53,4 @@ function App(): ReactElement {
2453
);
2554
}
2655

27-
export default App;
56+
export default connector(App);

webapp_frontend/src/components/Constants.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
import React, {ReactElement} from "react";
22
import App from "./App";
33

4-
function Constants():ReactElement{
5-
// userinfos
6-
// url + host of backend
4+
import {Provider} from 'react-redux'
5+
import store from '../background/redux/store'
76

87

8+
function Constants(): ReactElement {
9+
// userinfos
10+
// url + host of backend
911

1012

11-
return(<App/>)
13+
return (<Provider store={store}><App/></Provider>);
1214

1315

1416
}

0 commit comments

Comments
 (0)