-
Notifications
You must be signed in to change notification settings - Fork 1
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
Showing
19 changed files
with
312 additions
and
156 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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import {createBrowserHistory} from 'history'; | ||
|
||
const browserHistory = createBrowserHistory(); | ||
|
||
export default browserHistory; |
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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { Link } from 'react-router-dom'; | ||
import LoginNavigation from '../login-navigation/login-navigation'; | ||
import { AppRoute } from '../../const'; | ||
|
||
function Header(): JSX.Element { | ||
return ( | ||
<header className="header"> | ||
<div className="container"> | ||
<div className="header__wrapper"> | ||
<div className="header__left"> | ||
<Link to={AppRoute.Main} className="header__logo-link header__logo-link--active"> | ||
<img className="header__logo" src="img/logo.svg" alt="6 cities logo" width="81" height="41" /> | ||
</Link> | ||
</div> | ||
<LoginNavigation /> | ||
</div> | ||
</div> | ||
</header> | ||
); | ||
} | ||
|
||
export default 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,35 @@ | ||
import {useState, useLayoutEffect} from 'react'; | ||
import {Router} from 'react-router-dom'; | ||
import type {BrowserHistory} from 'history'; | ||
|
||
export interface HistoryRouterProps { | ||
history: BrowserHistory; | ||
basename?: string; | ||
children?: React.ReactNode; | ||
} | ||
|
||
function HistoryRouter({ | ||
basename, | ||
children, | ||
history, | ||
}: HistoryRouterProps) { | ||
const [state, setState] = useState({ | ||
action: history.action, | ||
location: history.location, | ||
}); | ||
|
||
useLayoutEffect(() => history.listen(setState), [history]); | ||
|
||
return ( | ||
<Router | ||
basename={basename} | ||
location={state.location} | ||
navigationType={state.action} | ||
navigator={history} | ||
> | ||
{children} | ||
</Router> | ||
); | ||
} | ||
|
||
export default HistoryRouter; |
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,49 @@ | ||
import { Link } from 'react-router-dom'; | ||
import { logoutAction } from '../../store/api-actions'; | ||
import { useAppDispatch, useAppSelector } from '../../hooks'; | ||
import { AppRoute, AuthorizationStatus } from '../../const'; | ||
|
||
function HeaderNavigation(): JSX.Element { | ||
const dispatch = useAppDispatch(); | ||
const offers = useAppSelector((state) => state.offers); | ||
const favoriteOffers = offers.filter((offer) => offer.isFavorite); | ||
const userData = useAppSelector((state) => state.userData); | ||
const authorizationStatus = useAppSelector((state) => state.authorizationStatus); | ||
return ( | ||
<nav className="header__nav"> | ||
{authorizationStatus === AuthorizationStatus.Auth ? ( | ||
<ul className="header__nav-list"> | ||
<li className="header__nav-item user"> | ||
<a className="header__nav-link header__nav-link--profile" > | ||
<div className="header__avatar-wrapper user__avatar-wrapper"> | ||
</div> | ||
<Link to={AppRoute.Favorites}> | ||
<span className="header__user-name user__name">{userData?.email}</span> | ||
<span className="header__favorite-count">{favoriteOffers.length}</span> | ||
</Link> | ||
</a> | ||
</li> | ||
<li className="header__nav-item"> | ||
<a className="header__nav-link" onClick={() => dispatch(logoutAction())}> | ||
<span className="header__signout">Sign out</span> | ||
</a> | ||
</li> | ||
</ul> | ||
) : ( | ||
<ul className="header__nav-list"> | ||
<li className="header__nav-item user"> | ||
<a className="header__nav-link header__nav-link--profile" > | ||
<div className="header__avatar-wrapper user__avatar-wrapper"> | ||
</div> | ||
<Link to={AppRoute.Login}> | ||
<span className="header__login">Sign in</span> | ||
</Link> | ||
</a> | ||
</li> | ||
</ul> | ||
)} | ||
</nav> | ||
); | ||
} | ||
|
||
export default HeaderNavigation; |
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
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 |
---|---|---|
|
@@ -2,41 +2,15 @@ import { Link } from 'react-router-dom'; | |
import { typeOfCardList } from '../../utils'; | ||
import OfferList from '../../components/offer-list/offer-list'; | ||
import { useAppSelector } from '../../hooks'; | ||
import Header from '../../components/header/header'; | ||
import { AppRoute } from '../../const'; | ||
|
||
|
||
function FavoritesScreen(): JSX.Element { | ||
const favoriteOffers = useAppSelector((state) => state.offers).filter((offer) => offer.isFavorite); | ||
return ( | ||
<div className="page"> | ||
<header className="header"> | ||
<div className="container"> | ||
<div className="header__wrapper"> | ||
<div className="header__left"> | ||
<Link to="/" className="header__logo-link"> | ||
<img className="header__logo" src="img/logo.svg" alt="6 cities logo" width="81" height="41"/> | ||
</Link> | ||
</div> | ||
<nav className="header__nav"> | ||
<ul className="header__nav-list"> | ||
<li className="header__nav-item user"> | ||
<a className="header__nav-link header__nav-link--profile" href="#"> | ||
<div className="header__avatar-wrapper user__avatar-wrapper"> | ||
</div> | ||
<span className="header__user-name user__name">[email protected]</span> | ||
<span className="header__favorite-count">3</span> | ||
</a> | ||
</li> | ||
<li className="header__nav-item"> | ||
<a className="header__nav-link" href="#"> | ||
<span className="header__signout">Sign out</span> | ||
</a> | ||
</li> | ||
</ul> | ||
</nav> | ||
</div> | ||
</div> | ||
</header> | ||
|
||
<Header /> | ||
<main className="page__main page__main--favorites"> | ||
<div className="page__favorites-container container"> | ||
<section className="favorites"> | ||
|
@@ -57,8 +31,8 @@ function FavoritesScreen(): JSX.Element { | |
</div> | ||
</main> | ||
<footer className="footer container"> | ||
<Link to="/" className="header__logo-link"> | ||
<img className="footer__logo" src="img/logo.svg" alt="6 cities logo" width="64" height="33"/> | ||
<Link to={AppRoute.Main} className="header__logo-link"> | ||
<img className="footer__logo" src="img/logo.svg" alt="6 cities logo" width="64" height="33" /> | ||
</Link> | ||
</footer> | ||
</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
Oops, something went wrong.