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.
- Loading branch information
1 parent
89aa7a4
commit ce96b13
Showing
45 changed files
with
3,023 additions
and
121 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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,38 +1,77 @@ | ||
import Section from './Section'; | ||
import ContactForm from './ContactForm'; | ||
import ContactList from './ContactList'; | ||
import Filter from './Filter'; | ||
import { useDispatch, useSelector } from 'react-redux'; | ||
import { useEffect } from 'react'; | ||
import { fetchContacts } from 'redux/contactsOperations'; | ||
import { selectError } from 'redux/selectors'; | ||
import { useEffect, lazy } from 'react'; | ||
import { useDispatch } from 'react-redux'; | ||
import { Route, Routes } from 'react-router-dom'; | ||
import { Layout } from './Layout'; | ||
import { PrivateRoute } from './PrivateRoute'; | ||
import { RestrictedRoute } from './RestrictedRoute'; | ||
import { refreshUser } from 'redux/auth/operations'; | ||
import { useAuth } from 'hooks'; | ||
import { Toaster } from 'react-hot-toast'; | ||
|
||
const HomePage = lazy(() => import('../pages/Home')); | ||
const RegisterPage = lazy(() => import('../pages/Register')); | ||
const LoginPage = lazy(() => import('../pages/Login')); | ||
const ContactsPage = lazy(() => import('../pages/Contacts')); | ||
|
||
export const App = () => { | ||
const dispatch = useDispatch(); | ||
// const isLoading = useSelector(selectIsLoading); | ||
const error = useSelector(selectError); | ||
const { isRefreshing } = useAuth(); | ||
|
||
useEffect(() => { | ||
dispatch(fetchContacts()); | ||
dispatch(refreshUser()); | ||
}, [dispatch]); | ||
return ( | ||
<div> | ||
<Section title="Phonebook"> | ||
<ContactForm /> | ||
</Section> | ||
|
||
<Section title="Contacts"> | ||
<Filter /> | ||
{/* {isLoading && !error && ( | ||
<b style={{ marginLeft: 70 }}>Request in progress...</b> | ||
)} */} | ||
{error && ( | ||
<b style={{ marginLeft: 70 }}> | ||
The operation failed with error: ${error} | ||
</b> | ||
)} | ||
{!error && <ContactList />} | ||
</Section> | ||
return isRefreshing ? ( | ||
<div style={{ position: 'relative' }}> | ||
<h1 | ||
style={{ | ||
position: 'absolute', | ||
left: '50%', | ||
top: '50%', | ||
transform: 'translate(-50%, -50%)', | ||
}} | ||
> | ||
Refreshing user... | ||
</h1> | ||
</div> | ||
) : ( | ||
<> | ||
<Routes> | ||
<Route path="/" element={<Layout />}> | ||
<Route index element={<HomePage />} /> | ||
<Route | ||
path="/register" | ||
element={ | ||
<RestrictedRoute | ||
redirectTo="/contacts" | ||
component={<RegisterPage />} | ||
/> | ||
} | ||
/> | ||
<Route | ||
path="/login" | ||
element={ | ||
<RestrictedRoute | ||
redirectTo="/contacts" | ||
component={<LoginPage />} | ||
/> | ||
} | ||
/> | ||
<Route | ||
path="/contacts" | ||
element={ | ||
<PrivateRoute redirectTo="/login" component={<ContactsPage />} /> | ||
} | ||
/> | ||
</Route> | ||
</Routes> | ||
<Toaster | ||
position="top-center" | ||
reverseOrder={false} | ||
toastOptions={{ | ||
duration: 5000, | ||
}} | ||
/> | ||
</> | ||
); | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { Navigation } from '../Navigation/Navigation'; | ||
import { UserMenu } from '../UserMenu/UserMenu'; | ||
import { AuthNav } from '../AuthNav/AuthNav'; | ||
import { useAuth } from 'hooks'; | ||
import { Header } from './AppBar.styled'; | ||
|
||
export const AppBar = () => { | ||
const { isLoggedIn } = useAuth(); | ||
|
||
return ( | ||
<Header> | ||
<Navigation /> | ||
{isLoggedIn ? <UserMenu /> : <AuthNav />} | ||
</Header> | ||
); | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import styled from 'styled-components'; | ||
|
||
export const Header = styled.header` | ||
display: flex; | ||
justify-content: space-between; | ||
align-items: center; | ||
margin-bottom: 20px; | ||
border-bottom: 1px solid #2a363b; | ||
padding: 10px; | ||
`; |
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { Link } from './AuthNav.styled'; | ||
|
||
export const AuthNav = () => { | ||
return ( | ||
<div> | ||
<Link to="/register">Register</Link> | ||
<Link to="/login">Log In</Link> | ||
</div> | ||
); | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { NavLink } from 'react-router-dom'; | ||
import styled from 'styled-components'; | ||
|
||
export const Link = styled(NavLink)` | ||
display: inline-block; | ||
text-decoration: none; | ||
padding: 12px; | ||
font-weight: 700; | ||
color: black; | ||
&:hover { | ||
color: teal; | ||
} | ||
&.active { | ||
color: white; | ||
text-shadow: teal 2px 4px 3px, teal 6px 8px 30px, teal 1px 3px 30px; | ||
font-weight: 900; | ||
} | ||
`; |
Oops, something went wrong.