-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.tsx
114 lines (112 loc) · 5 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
import React from "react";
import AppBar from "./components/Other/AppBar";
import {BrowserRouter as Router, Switch, Route, Redirect} from "react-router-dom";
import LoginPage from "./components/LoginRoute/LoginPage";
import StockPage from "./components/BuyStocksRoute/StockPage";
import SideBar from "./components/Other/SideBar";
import MyProfile from "./components/MyProfileRoute/MyProfile";
import ReactNotification from "react-notifications-component";
import DefaultPage from "./components/Other/DefaultPage";
import { FOLLOWEVENT, STOCKEVENT } from "./graphql/queries";
import ExplorePage from "./components/ExploreRoute/ExplorePage";
import SpecificExplore from "./components/ExploreRoute/SpecificExplore";
import { useSelector } from "react-redux";
import { useSubscription } from "@apollo/client";
import { RootState } from ".";
import ActionsPage from "./components/ActionsRoute/ActionsPage";
import Reset from "./components/Other/Reset";
import HealthCheck from "./components/Other/HealthCheck";
function App(): JSX.Element {
const userLogged = useSelector<RootState, string>((state) => state.user.username);
const stockEvent = useSubscription(STOCKEVENT, {variables: {username: userLogged}});
const followEvent = useSubscription(FOLLOWEVENT, {variables: {username: userLogged}});
const stockSubscription = {trans: stockEvent.data?.stockEvent?.transaction, me: stockEvent.data?.stockEvent.me};
return (
<div>
<ReactNotification />
<Router>
<Switch>
<Route path="/actions" exact>
<div>
<SideBar />
<AppBar stockSubscription={stockSubscription} />
<ActionsPage />
</div>
</Route>
<Route path="/login" exact>
<div>
<SideBar />
<AppBar stockSubscription={stockSubscription} />
<LoginPage />
</div>
</Route>
<Route path="/myprofile" exact>
{
userLogged ?
<div>
<SideBar />
<AppBar stockSubscription={stockSubscription}/>
<MyProfile
stockSubscription={stockEvent.data?.stockEvent?.transaction.transactionDate}
followSubscriptions={followEvent.data?.followEvent?.date}
/>
</div>
: <Redirect to="/login" />
}
</Route>
<Route path="/buystocks" exact>
{
userLogged ?
<div>
<SideBar />
<AppBar stockSubscription={stockSubscription} />
<StockPage />
</div>
: <Redirect to="/login" />
}
</Route>
<Route path="/login" exact>
<div>
<SideBar />
<AppBar stockSubscription={stockSubscription} />
</div>
<LoginPage />
</Route>
<Route path="/explore" exact>
<div>
<SideBar />
<AppBar stockSubscription={stockSubscription} />
</div>
<ExplorePage />
</Route>
<Route path="/explore/:id" exact>
<div>
<SideBar />
<AppBar stockSubscription={stockSubscription} />
<SpecificExplore
followSubscriptions={followEvent.data?.followEvent?.date}
/>
</div>
</Route>
<Route path="/" exact>
<div>
<SideBar />
<AppBar stockSubscription={stockSubscription} />
<DefaultPage />
</div>
</Route>
<Route path="/resetdatabase" exact>
<Reset />
</Route>
<Route path="/healthcheck" exact>
<HealthCheck />
</Route>
<Route path="/">
<Redirect to="/" />
</Route>
</Switch>
</Router>
</div>
);
}
export default App;