-
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 #10 from ktvtk/module7-task2
- Loading branch information
Showing
11 changed files
with
176 additions
and
30 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,28 @@ | ||
import {JSX} from 'react'; | ||
import {Navigate} from 'react-router-dom'; | ||
import {AppRoute, AuthorizationStatus} from '../../const'; | ||
import {useAppSelector} from '../../hooks'; | ||
|
||
type PrivateRouteProps = { | ||
authorizationStatus: AuthorizationStatus; | ||
children: JSX.Element; | ||
} | ||
|
||
export function PrivateRoute(props: PrivateRouteProps): JSX.Element { | ||
const {authorizationStatus, children} = props; | ||
|
||
export function PrivateRouteAuthorized(props: PrivateRouteProps): JSX.Element { | ||
const {children} = props; | ||
const isAuthorized = useAppSelector((state) => state.authorizationStatus) === AuthorizationStatus.Authorized; | ||
return ( | ||
authorizationStatus === AuthorizationStatus.Auth | ||
isAuthorized | ||
? children | ||
: <Navigate to={AppRoute.Login} /> | ||
); | ||
} | ||
|
||
export function PrivateRouteUnauthorized(props: PrivateRouteProps): JSX.Element { | ||
const {children} = props; | ||
const isAuthorized = useAppSelector((state) => state.authorizationStatus) === AuthorizationStatus.Unauthorized; | ||
return ( | ||
isAuthorized | ||
? children | ||
: <Navigate to={AppRoute.Main} /> | ||
); | ||
} |
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 |
---|---|---|
|
@@ -27,6 +27,8 @@ export function OfferScreen() : JSX.Element { | |
3, | ||
); | ||
const reviews = useAppSelector((state) => state.reviews); | ||
const favoriteCount = useAppSelector((state) => state.offers).filter((commonOffer) => commonOffer.isFavorite).length; | ||
|
||
if (offer === null){ | ||
return (<Loading />); | ||
} | ||
|
@@ -48,12 +50,13 @@ export function OfferScreen() : JSX.Element { | |
<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> | ||
<div className="header__avatar-wrapper user__avatar-wrapper"></div> | ||
<Link to={AppRoute.Main}> | ||
<span className="header__user-name user__name">[email protected]</span> | ||
<span className="header__favorite-count">3</span> | ||
</a> | ||
</Link> | ||
<Link to={AppRoute.Favorites}> | ||
<span className="header__favorite-count">{favoriteCount}</span> | ||
</Link> | ||
</li> | ||
<li className="header__nav-item"> | ||
<a className="header__nav-link" href="#"> | ||
|
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
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