-
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.
Merge pull request #11 from ktvtk/module7-task3
- Loading branch information
Showing
10 changed files
with
302 additions
and
201 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
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 |
---|---|---|
@@ -1,14 +1,15 @@ | ||
import {JSX} from 'react'; | ||
import {JSX, useState} from 'react'; | ||
import {Helmet} from 'react-helmet-async'; | ||
import {OffersList} from '../../components/offers-list/offers-list.tsx'; | ||
import {Link} from 'react-router-dom'; | ||
import {AppRoute} from '../../const.ts'; | ||
import {useState} from 'react'; | ||
import {AppRoute, AuthorizationStatus} from '../../const.ts'; | ||
import {Map} from '../../components/map/map.tsx'; | ||
import {CitiesList} from '../../components/cities-list/cities-list.tsx'; | ||
import {useAppSelector} from '../../hooks'; | ||
import {Sorting} from '../../components/sorting/sorting.tsx'; | ||
import {SortOption} from '../../types/sort-option.ts'; | ||
import {store} from '../../store'; | ||
import {logout} from '../../store/api-actions.ts'; | ||
|
||
|
||
export function MainScreen(): JSX.Element { | ||
|
@@ -39,6 +40,11 @@ export function MainScreen(): JSX.Element { | |
setSortingOption(option); | ||
}; | ||
|
||
const isAuth = useAppSelector((state) => state.authorizationStatus) === AuthorizationStatus.Authorized; | ||
|
||
const logoutHandle = () => { | ||
store.dispatch(logout()); | ||
}; | ||
|
||
return ( | ||
<div className="page page--gray page--main"> | ||
|
@@ -53,23 +59,39 @@ export function MainScreen(): JSX.Element { | |
<img className="header__logo" src="img/logo.svg" alt="6 cities logo" width="81" height="41"/> | ||
</a> | ||
</div> | ||
<nav className="header__nav"> | ||
<ul className="header__nav-list"> | ||
<li className="header__nav-item user"> | ||
<Link className="header__nav-link header__nav-link--profile" to={AppRoute.Favorites}> | ||
<div className="header__avatar-wrapper user__avatar-wrapper"> | ||
</div> | ||
<span className="header__user-name user__name">[email protected]</span> | ||
<span className="header__favorite-count">{favoritesCount}</span> | ||
</Link> | ||
</li> | ||
<li className="header__nav-item"> | ||
<a className="header__nav-link" href="#"> | ||
<span className="header__signout">Sign out</span> | ||
</a> | ||
</li> | ||
</ul> | ||
</nav> | ||
{isAuth ? ( | ||
<nav className="header__nav"> | ||
<ul className="header__nav-list"> | ||
<li className="header__nav-item user"> | ||
<Link className="header__nav-link header__nav-link--profile" to={AppRoute.Favorites}> | ||
<div className="header__avatar-wrapper user__avatar-wrapper"> | ||
</div> | ||
<span className="header__user-name user__name">[email protected]</span> | ||
<span className="header__favorite-count">{favoritesCount}</span> | ||
</Link> | ||
</li> | ||
<li className="header__nav-item"> | ||
<a className="header__nav-link" onClick={logoutHandle}> | ||
<span className="header__signout">Sign out</span> | ||
</a> | ||
</li> | ||
</ul> | ||
</nav> | ||
) : ( | ||
<nav className="header__nav"> | ||
<ul className="header__nav-list"> | ||
<li className="header__nav-item user"> | ||
<Link | ||
className="header__nav-link header__nav-link--profile" | ||
to={AppRoute.Login} | ||
> | ||
<div className="header__avatar-wrapper user__avatar-wrapper"></div> | ||
<span className="header__login">Sign in</span> | ||
</Link> | ||
</li> | ||
</ul> | ||
</nav> | ||
)} | ||
</div> | ||
</div> | ||
</header> | ||
|
Oops, something went wrong.