From 89f13961ec82da036246f5d7176c926125f7bb09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leonardo=20Mur=C3=A7a?= Date: Wed, 1 Jun 2022 15:35:34 -0300 Subject: [PATCH] Add routes --- package-lock.json | 58 +++++++++++++++++++++++ package.json | 1 + src/App.js | 11 +++-- src/AuthenticatedApp.js | 14 +++--- src/UnauthenticatedApp.js | 8 +++- src/index.js | 13 +++-- src/screens/Home/index.js | 15 ++++++ src/screens/UnauthenticatedHome/index.js | 17 +++++++ src/screens/UnauthenticatedHome/styles.js | 16 +++++++ 9 files changed, 135 insertions(+), 18 deletions(-) create mode 100644 src/screens/Home/index.js create mode 100644 src/screens/UnauthenticatedHome/index.js create mode 100644 src/screens/UnauthenticatedHome/styles.js diff --git a/package-lock.json b/package-lock.json index ae3fae1..31740d4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -16,6 +16,7 @@ "@testing-library/user-event": "^13.5.0", "react": "^18.1.0", "react-dom": "^18.1.0", + "react-router-dom": "^6.3.0", "react-scripts": "5.0.1", "web-vitals": "^2.1.4" }, @@ -8016,6 +8017,14 @@ "he": "bin/he" } }, + "node_modules/history": { + "version": "5.3.0", + "resolved": "https://registry.npmjs.org/history/-/history-5.3.0.tgz", + "integrity": "sha512-ZqaKwjjrAYUYfLG+htGaIIZ4nioX2L70ZUMIFysS3xvBsSG4x/n1V6TXV3N8ZYNuFGlDirFg32T7B6WOUPDYcQ==", + "dependencies": { + "@babel/runtime": "^7.7.6" + } + }, "node_modules/hoist-non-react-statics": { "version": "3.3.2", "resolved": "https://registry.npmjs.org/hoist-non-react-statics/-/hoist-non-react-statics-3.3.2.tgz", @@ -12250,6 +12259,30 @@ "node": ">=0.10.0" } }, + "node_modules/react-router": { + "version": "6.3.0", + "resolved": "https://registry.npmjs.org/react-router/-/react-router-6.3.0.tgz", + "integrity": "sha512-7Wh1DzVQ+tlFjkeo+ujvjSqSJmkt1+8JO+T5xklPlgrh70y7ogx75ODRW0ThWhY7S+6yEDks8TYrtQe/aoboBQ==", + "dependencies": { + "history": "^5.2.0" + }, + "peerDependencies": { + "react": ">=16.8" + } + }, + "node_modules/react-router-dom": { + "version": "6.3.0", + "resolved": "https://registry.npmjs.org/react-router-dom/-/react-router-dom-6.3.0.tgz", + "integrity": "sha512-uaJj7LKytRxZNQV8+RbzJWnJ8K2nPsOOEuX7aQstlMZKQT0164C+X2w6bnkqU3sjtLvpd5ojrezAyfZ1+0sStw==", + "dependencies": { + "history": "^5.2.0", + "react-router": "6.3.0" + }, + "peerDependencies": { + "react": ">=16.8", + "react-dom": ">=16.8" + } + }, "node_modules/react-scripts": { "version": "5.0.1", "resolved": "https://registry.npmjs.org/react-scripts/-/react-scripts-5.0.1.tgz", @@ -20721,6 +20754,14 @@ "resolved": "https://registry.npmjs.org/he/-/he-1.2.0.tgz", "integrity": "sha512-F/1DnUGPopORZi0ni+CvrCgHQ5FyEAHRLSApuYWMmrbSwoN2Mn/7k+Gl38gJnR7yyDZk6WLXwiGod1JOWNDKGw==" }, + "history": { + "version": "5.3.0", + "resolved": "https://registry.npmjs.org/history/-/history-5.3.0.tgz", + "integrity": "sha512-ZqaKwjjrAYUYfLG+htGaIIZ4nioX2L70ZUMIFysS3xvBsSG4x/n1V6TXV3N8ZYNuFGlDirFg32T7B6WOUPDYcQ==", + "requires": { + "@babel/runtime": "^7.7.6" + } + }, "hoist-non-react-statics": { "version": "3.3.2", "resolved": "https://registry.npmjs.org/hoist-non-react-statics/-/hoist-non-react-statics-3.3.2.tgz", @@ -23666,6 +23707,23 @@ "resolved": "https://registry.npmjs.org/react-refresh/-/react-refresh-0.11.0.tgz", "integrity": "sha512-F27qZr8uUqwhWZboondsPx8tnC3Ct3SxZA3V5WyEvujRyyNv0VYPhoBg1gZ8/MV5tubQp76Trw8lTv9hzRBa+A==" }, + "react-router": { + "version": "6.3.0", + "resolved": "https://registry.npmjs.org/react-router/-/react-router-6.3.0.tgz", + "integrity": "sha512-7Wh1DzVQ+tlFjkeo+ujvjSqSJmkt1+8JO+T5xklPlgrh70y7ogx75ODRW0ThWhY7S+6yEDks8TYrtQe/aoboBQ==", + "requires": { + "history": "^5.2.0" + } + }, + "react-router-dom": { + "version": "6.3.0", + "resolved": "https://registry.npmjs.org/react-router-dom/-/react-router-dom-6.3.0.tgz", + "integrity": "sha512-uaJj7LKytRxZNQV8+RbzJWnJ8K2nPsOOEuX7aQstlMZKQT0164C+X2w6bnkqU3sjtLvpd5ojrezAyfZ1+0sStw==", + "requires": { + "history": "^5.2.0", + "react-router": "6.3.0" + } + }, "react-scripts": { "version": "5.0.1", "resolved": "https://registry.npmjs.org/react-scripts/-/react-scripts-5.0.1.tgz", diff --git a/package.json b/package.json index 842711e..19991b5 100644 --- a/package.json +++ b/package.json @@ -11,6 +11,7 @@ "@testing-library/user-event": "^13.5.0", "react": "^18.1.0", "react-dom": "^18.1.0", + "react-router-dom": "^6.3.0", "react-scripts": "5.0.1", "web-vitals": "^2.1.4" }, diff --git a/src/App.js b/src/App.js index 149a753..4d503dc 100644 --- a/src/App.js +++ b/src/App.js @@ -1,6 +1,7 @@ -import { lazy } from 'react'; +import { lazy, Suspense } from 'react'; import { Container } from '@mui/material'; import { useUser } from './context/user'; +import LoadingIndicator from './components/LoadingIndicator'; const AuthenticatedApp = lazy(() => import('./AuthenticatedApp')); const UnauthenticatedApp = lazy(() => import('./UnauthenticatedApp')); @@ -9,9 +10,11 @@ function App() { const user = useUser(); return ( - - {user ? : } - + }> + + {user ? : } + + ); } diff --git a/src/AuthenticatedApp.js b/src/AuthenticatedApp.js index 7e2a874..2e52cf2 100644 --- a/src/AuthenticatedApp.js +++ b/src/AuthenticatedApp.js @@ -1,14 +1,12 @@ -import { useAuthState } from './context/auth'; +import { Navigate, Route, Routes } from 'react-router-dom'; +import Home from './screens/Home'; function AuthenticatedApp() { - const { logout, isPending } = useAuthState(); - return ( -
-

You're logged in!

- - {isPending &&

Loading...

} -
+ + } /> + } /> + ); } diff --git a/src/UnauthenticatedApp.js b/src/UnauthenticatedApp.js index 557499c..3497159 100644 --- a/src/UnauthenticatedApp.js +++ b/src/UnauthenticatedApp.js @@ -1,11 +1,17 @@ import { Fragment } from 'react'; +import { Route, Routes } from 'react-router-dom'; import Login from './screens/Login'; +import UnauthenticatedHome from './screens/UnauthenticatedHome'; function UnauthenticatedApp() { return ( - + + } /> + } /> + Route not found!} /> + ); } diff --git a/src/index.js b/src/index.js index c758c5d..b0b79d3 100644 --- a/src/index.js +++ b/src/index.js @@ -1,6 +1,7 @@ import React from 'react'; import ReactDOM from 'react-dom/client'; +import { BrowserRouter } from 'react-router-dom'; import { createTheme } from '@mui/material'; import { ThemeProvider } from '@mui/system'; @@ -30,11 +31,13 @@ const theme = createTheme({ const root = ReactDOM.createRoot(document.getElementById('root')); root.render( - - - - - + + + + + + + ); diff --git a/src/screens/Home/index.js b/src/screens/Home/index.js new file mode 100644 index 0000000..48c09ef --- /dev/null +++ b/src/screens/Home/index.js @@ -0,0 +1,15 @@ +import { useAuthState } from '../../context/auth'; + +function Home() { + const { logout, isPending } = useAuthState(); + + return ( +
+

You're logged in!

+ + {isPending &&

Loading...

} +
+ ); +} + +export default Home; diff --git a/src/screens/UnauthenticatedHome/index.js b/src/screens/UnauthenticatedHome/index.js new file mode 100644 index 0000000..3718f2f --- /dev/null +++ b/src/screens/UnauthenticatedHome/index.js @@ -0,0 +1,17 @@ +import { Link } from '@mui/material'; +import { Container } from '@mui/system'; + +import styles from './styles'; + +function UnauthenticatedHome() { + const { container } = styles.desktop; + + return ( + +

Seja bem-vindo!

+ Ir para login +
+ ); +} + +export default UnauthenticatedHome; diff --git a/src/screens/UnauthenticatedHome/styles.js b/src/screens/UnauthenticatedHome/styles.js new file mode 100644 index 0000000..77cc906 --- /dev/null +++ b/src/screens/UnauthenticatedHome/styles.js @@ -0,0 +1,16 @@ +const desktopContainer = { + height: '100vh', + margin: 0, + padding: 0, + display: 'flex', + justifyContent: 'center', + flexDirection: 'column', + alignItems: 'center', +}; + +const desktop = { + container: desktopContainer, +}; + +const styles = { desktop }; +export default styles;