Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Маршрут по тайным тропам #3

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions constants.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
export enum AppRoute {
Login = '/login',
Root = '/',
Favorites = '/favorites',
OfferWithId = '/offer/:id'
}

export enum AuthorizationStatus {
Auth = 'AUTH',
NoAuth = 'NO_AUTH',
Unknown = 'UNKNOWN',
}


32 changes: 31 additions & 1 deletion src/components/app/app.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,42 @@
import MainScreen from '../../pages/main';
import {BrowserRouter, Route, Routes} from 'react-router-dom';
import NotFound from '../../pages/not_found';
import Login from '../../pages/login';
import Offer from '../../pages/offer';
import {AppRoute, AuthorizationStatus} from '../../../constants';
import PrivateRoute from '../private-route/private-route';
import Favorites from '../../pages/favorites';

type AppScreenPros = {
offersAmount: number;
}

function App({offersAmount}: AppScreenPros): JSX.Element {
return (
<MainScreen offersAmount={offersAmount}/>
<BrowserRouter>
<Routes>
<Route
path={AppRoute.Root}
element={<MainScreen offersAmount={offersAmount} /> }
/>
<Route
path={AppRoute.Login}
element={<Login />}
/>
<Route
path={AppRoute.Favorites}
element={<PrivateRoute authorizationStatus={AuthorizationStatus.NoAuth}><Favorites /></PrivateRoute> }
/>
<Route
path={AppRoute.OfferWithId}
element={<Offer />}
/>
<Route
path={'*'}
element={<NotFound />}
/>
</Routes>
</BrowserRouter>
);
}

Expand Down
15 changes: 15 additions & 0 deletions src/components/private-route/private-route.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import {Navigate} from 'react-router-dom';
import {AppRoute, AuthorizationStatus} from '../../../constants';

type PrivateRouteProps = {
authorizationStatus: AuthorizationStatus;
children: JSX.Element;
}

function PrivateRoute({authorizationStatus, children}: PrivateRouteProps): JSX.Element {
return (
authorizationStatus === AuthorizationStatus.Auth ? children : <Navigate to={AppRoute.Login} />
);
}

export default PrivateRoute;
1 change: 0 additions & 1 deletion src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ const offersAmount = 312;

root.render(
<React.StrictMode>
<h1>Hello, World!</h1>
<App offersAmount={offersAmount} />
</React.StrictMode>
);
10 changes: 5 additions & 5 deletions src/pages/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -118,17 +118,17 @@ function MainScreen({offersAmount}: MainScreenPros): JSX.Element {
<b className="places__found">{offersAmount} places to stay in Amsterdam</b>
<form className="places__sorting" action="#" method="get">
<span className="places__sorting-caption">Sort by</span>
<span className="places__sorting-type" tabIndex="0">
<span className="places__sorting-type" tabIndex={0}>
Popular
<svg className="places__sorting-arrow" width="7" height="4">
<use xlinkHref="#icon-arrow-select"></use>
</svg>
</span>
<ul className="places__options places__options--custom places__options--opened">
<li className="places__option places__option--active" tabIndex="0">Popular</li>
<li className="places__option" tabIndex="0">Price: low to high</li>
<li className="places__option" tabIndex="0">Price: high to low</li>
<li className="places__option" tabIndex="0">Top rated first</li>
<li className="places__option places__option--active" tabIndex={0}>Popular</li>
<li className="places__option" tabIndex={0}>Price: low to high</li>
<li className="places__option" tabIndex={0}>Price: high to low</li>
<li className="places__option" tabIndex={0}>Top rated first</li>
</ul>
</form>
<div className="cities__places-list places__list tabs__content">
Expand Down
14 changes: 14 additions & 0 deletions src/pages/not_found.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import {Link} from 'react-router-dom';
import {Fragment} from 'react';


function NotFound(): JSX.Element {
return (
<Fragment>
<h1>404 Not Found</h1>
<Link to={'/'}>Go to main page</Link>
</Fragment>
);
}

export default NotFound;
NotAmigo marked this conversation as resolved.
Show resolved Hide resolved
Loading