generated from goitacademy/react-homework-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove chakra styles and add layout.styled.js to resolve problem with routing.
- Loading branch information
1 parent
d9aab48
commit a988c31
Showing
5 changed files
with
112 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,61 +1,64 @@ | ||
import React from 'react'; | ||
import { useDispatch } from 'react-redux'; | ||
import React, { lazy, useEffect } from 'react'; | ||
import { Routes, Route } from 'react-router-dom'; | ||
|
||
import { Layout } from './Layout/Layout'; | ||
import Register from './Register/Register'; | ||
import Login from './Login/Login'; | ||
import Contacts from './Contacts/Contacts'; | ||
import Home from '../Pages/Home'; | ||
import { useEffect } from 'react'; | ||
import { useDispatch } from 'react-redux'; | ||
import { StyledContainer } from './App.styled'; | ||
import PrivateRoute from './PrivateRoute/PrivateRoute'; | ||
import ProtectedRoute from './ProtectedRoute/ProtectedRoute'; | ||
import { currentUser } from '../redux/reducers/auth/operations'; | ||
|
||
// const Home = lazy(() => import('../pages/Home')); | ||
import { StyledContainer } from './App.styled'; | ||
|
||
export function App() { | ||
// const { isLoading, error } = useSelector(selectContacts); | ||
import { useSelector } from 'react-redux/es/hooks/useSelector'; | ||
import { selectLoaderAuth } from 'redux/selectors'; | ||
import Loader from '../components/Loader/Loader'; | ||
|
||
const Home = lazy(() => import('../Pages/Home')); | ||
const Register = lazy(() => import('../components/Register/Register')); | ||
const Login = lazy(() => import('../components/Login/Login')); | ||
const Contacts = lazy(() => import('../components/Contacts/Contacts')); | ||
|
||
export function App() { | ||
const dispatch = useDispatch(); | ||
const isLoadingAuth = useSelector(selectLoaderAuth); | ||
|
||
useEffect(() => { | ||
dispatch(currentUser()); | ||
}, [dispatch]); | ||
|
||
// if (error) { | ||
// Notify.failure(`${error}`); | ||
// return <h1>Something went wrong, please try reloading page...</h1>; | ||
// } | ||
|
||
if (isLoadingAuth) { | ||
return <Loader />; | ||
} | ||
return ( | ||
<StyledContainer> | ||
<Routes> | ||
<Route path="/" element={<Layout />}> | ||
<Route index element={<Home />} /> | ||
|
||
<Route | ||
path="login" | ||
element={ | ||
<ProtectedRoute element={<Login />} redirect="/contacts" /> | ||
} | ||
/> | ||
<Route | ||
path="register" | ||
element={ | ||
<ProtectedRoute element={<Register />} redirect="/contacts" /> | ||
} | ||
/> | ||
<Route | ||
path="contacts" | ||
element={<PrivateRoute element={<Contacts />} redirect="/login" />} | ||
/> | ||
<Route /> | ||
</Route> | ||
|
||
{/* {isLoading && <Loader />} */} | ||
</Routes> | ||
</StyledContainer> | ||
<> | ||
<StyledContainer> | ||
<Routes> | ||
<Route path="/" element={<Layout />}> | ||
<Route index element={<Home />} /> | ||
|
||
<Route | ||
path="login" | ||
element={ | ||
<ProtectedRoute element={<Login />} redirect="/contacts" /> | ||
} | ||
/> | ||
<Route | ||
path="register" | ||
element={ | ||
<ProtectedRoute element={<Register />} redirect="/contacts" /> | ||
} | ||
/> | ||
<Route | ||
path="contacts" | ||
element={ | ||
<PrivateRoute element={<Contacts />} redirect="/login" /> | ||
} | ||
/> | ||
<Route /> | ||
</Route> | ||
<Route path="*" element={<Home />} /> | ||
</Routes> | ||
</StyledContainer> | ||
</> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,29 @@ | ||
// import styled from 'styled-components'; | ||
// import { NavLink } from 'react-router-dom'; | ||
import styled from 'styled-components'; | ||
import { NavLink } from 'react-router-dom'; | ||
|
||
// export const StyledHeader = styled.header` | ||
// display: flex; | ||
// align-items: center; | ||
// justify-content: space-between; | ||
// gap: 12px; | ||
// padding: 8px 0; | ||
// margin-bottom: 16px; | ||
// border-bottom: 1px solid black; | ||
export const StyledLayout = styled.header` | ||
padding: 8px 0; | ||
margin-bottom: 16px; | ||
border-bottom: 1px solid black; | ||
// > nav { | ||
// display: flex; | ||
// } | ||
// `; | ||
> nav { | ||
display: flex; | ||
align-items: center; | ||
gap: 15px; | ||
} | ||
`; | ||
|
||
// export const StyledLink = styled(NavLink)` | ||
// padding: 8px 16px; | ||
// border-radius: 4px; | ||
// text-decoration: none; | ||
// color: black; | ||
// font-weight: 500; | ||
// font-size: 35px; | ||
// transition: all 250ms cubic-bezier(0.4, 0, 0.2, 1); | ||
export const StyledLink = styled(NavLink)` | ||
padding: 8px 16px; | ||
border-radius: 4px; | ||
text-decoration: none; | ||
color: black; | ||
font-weight: 500; | ||
font-size: 18px; | ||
transition: all 250ms cubic-bezier(0.4, 0, 0.2, 1); | ||
// &.active { | ||
// color: white; | ||
// background-color: orangered; | ||
// } | ||
// `; | ||
&.active { | ||
color: white; | ||
background-color: #2196f3; | ||
} | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters