|
1 | 1 | import React, { useContext } from "react"; |
2 | | -import { store, dispatch, actions } from "./store"; |
| 2 | +import { TransitionGroup, CSSTransition } from "react-transition-group"; |
3 | 3 |
|
4 | | -function App() { |
5 | | - const { state, dispatch } = useContext(store); |
| 4 | +import { store, actions } from "./store"; |
| 5 | +import { useTrivia, useStore } from "./hooks"; |
6 | 6 |
|
7 | | - const handleReverse = () => { |
8 | | - dispatch(actions.setUserFetching(false)); |
9 | | - }; |
| 7 | +import { |
| 8 | + BrowserRouter as Router, |
| 9 | + Switch, |
| 10 | +} from "react-router-dom"; |
| 11 | + |
| 12 | +import { ProtectedRoute, PublicRoute } from "./navigations"; |
| 13 | +import Dashboard from "./pages/Dashboard"; |
| 14 | +import Account from "./pages/Account"; |
| 15 | +import Login from "./pages/Login"; |
| 16 | + |
| 17 | +const App = () => { |
| 18 | + |
| 19 | + const { state } = useStore(); |
| 20 | + |
| 21 | + const { |
| 22 | + authenticationState: { isAuthenticated }, |
| 23 | + } = state; |
| 24 | + |
| 25 | + const AuthenticatedNavigations = () => ( |
| 26 | + <TransitionGroup> |
| 27 | + <CSSTransition classNames="fade" timeout={3000}> |
| 28 | + <Switch> |
| 29 | + <ProtectedRoute |
| 30 | + path="/dashboard" |
| 31 | + component={Dashboard} |
| 32 | + isAuthenticated={isAuthenticated} |
| 33 | + /> |
| 34 | + <ProtectedRoute |
| 35 | + path="/account" |
| 36 | + component={Account} |
| 37 | + isAuthenticated={isAuthenticated} |
| 38 | + /> |
| 39 | + </Switch> |
| 40 | + </CSSTransition> |
| 41 | + </TransitionGroup> |
| 42 | + ); |
| 43 | + |
| 44 | + const PublicNavigations = () => ( |
| 45 | + <TransitionGroup> |
| 46 | + <CSSTransition classNames="fade" timeout={3000}> |
| 47 | + <Switch> |
| 48 | + <PublicRoute |
| 49 | + path="/login" |
| 50 | + exact |
| 51 | + isAuthenticated={isAuthenticated} |
| 52 | + component={Login} |
| 53 | + /> |
| 54 | + </Switch> |
| 55 | + </CSSTransition> |
| 56 | + </TransitionGroup> |
| 57 | + ); |
10 | 58 |
|
11 | 59 | return ( |
12 | | - <div className="App"> |
13 | | - authenticated:isLoading: |
14 | | - {state.authenticationState.isLoading ? " true\n" : "false\n"} |
15 | | - <br /> |
16 | | - <button |
17 | | - onClick={() => { |
18 | | - dispatch(actions.setLoadingLogin()); |
19 | | - dispatch(actions.setUserFetching(true)); |
20 | | - }} |
21 | | - > |
22 | | - State Management |
23 | | - </button> |
24 | | - <br /> |
25 | | - user:isFetching: {state.userState.isFetching ? " true\n" : "false\n"} |
26 | | - <br /> |
27 | | - <button onClick={handleReverse}>Reverse fetching</button> |
28 | | - </div> |
| 60 | + <> |
| 61 | + <>{JSON.stringify(state)}</> |
| 62 | + <Router> |
| 63 | + <AuthenticatedNavigations /> |
| 64 | + <PublicNavigations /> |
| 65 | + </Router> |
| 66 | + </> |
29 | 67 | ); |
30 | | -} |
| 68 | +}; |
31 | 69 |
|
32 | 70 | export default App; |
0 commit comments