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 7 commits into from
Oct 18, 2024
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
1 change: 1 addition & 0 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

- Студент: [Анастасия Сайдазимова](https://up.htmlacademy.ru/react-individual/2/user/2554551).
- Наставник: `Артём Новоселов`.
- [Просмотр проекта](https://2554551-six-cities-2-92qvbhbt8-nslyumas-projects.vercel.app/)

---

Expand Down
Binary file added markup/img/not-found.jpeg
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

webp

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
29 changes: 26 additions & 3 deletions src/components/app/app.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,32 @@
/* eslint-disable arrow-body-style */

import Main from '../main/main';
import { Route, BrowserRouter, Routes } from 'react-router-dom';
import { AppRoute, AuthorizationStatus } from '../../const';
import Main from '../../pages/main/main';
import Login from '../../pages/login/login';
import Favorites from '../../pages/favorites/favorites';
import Offer from '../../pages/offer/offer';
import NotFound from '../../pages/not-found/not-found';
import PrivateRoute from '../private-route/private-route';

const App = () => {
return <Main />;
return (
<BrowserRouter>
<Routes>
<Route path={AppRoute.Main} element={<Main />} />
<Route path={AppRoute.Login} element={<Login />} />
<Route
path={AppRoute.Favorites}
element={
<PrivateRoute authorizationStatus={AuthorizationStatus.NoAuth}>
<Favorites />
</PrivateRoute>
}
/>
<Route path={AppRoute.Offer} element={<Offer />} />
<Route path="*" element={<NotFound />} />
</Routes>
</BrowserRouter>
);
};

export default App;
21 changes: 21 additions & 0 deletions src/components/private-route/private-route.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import React from 'react';
import { Navigate } from 'react-router-dom';
import { AppRoute, AuthorizationStatus } from '../../const';

// Сборка не проходит, если испльзовать PropsWithChildren и не указать тип Navigate
// 'PrivateRoute' cannot be used as a JSX component.
// Its return type 'string | number | boolean | Element | Iterable<ReactNode> | null | undefined' is not a valid JSX element.
// Type 'undefined' is not assignable to type 'Element | null'.

// type Props = PropsWithChildren<{ authorizationStatus: AuthorizationStatus }>;
type Props = {
authorizationStatus: AuthorizationStatus;
children: React.JSX.Element;
};

const PrivateRoute = ({ authorizationStatus, children }: Props) =>
authorizationStatus === AuthorizationStatus.Auth
? children
: ((<Navigate to={AppRoute.Login} />) as React.JSX.Element);

export default PrivateRoute;
12 changes: 12 additions & 0 deletions src/const.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export enum AppRoute {
Main = '/',
Login = '/login',
Favorites = '/favorites',
Offer = '/offer/:id',
}

export enum AuthorizationStatus {
Auth = 'AUTH',
NoAuth = 'NO_AUTH',
Unknown = 'UNKNOWN',
}
File renamed without changes.
2 changes: 1 addition & 1 deletion src/components/main/main.tsx → src/pages/main/main.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable arrow-body-style */

import { CARDS } from '../../data/cardsData';
import Card from '../card/card';
import Card from '../../components/card/card';

const Main = () => {
return (
Expand Down
34 changes: 34 additions & 0 deletions src/pages/not-found/not-found.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
.container {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
display: flex;
justify-content: center;
align-items: center;
background-image: url("markup/img/not-found.jpeg");
background-repeat: no-repeat;
background-size: cover;
background-position: center;
}

.box {
background-color: rgba(255, 255, 255, 0.8);
text-align: center;
padding: 0 30px;
border-radius: 16px;
box-shadow: 0px 0px 16px 30px rgba(255, 255, 255, 0.8);
}

.title {
font-size: 5rem;
}

.text {
font-size: 2rem;
}

.link {
color: #4481c3;
}/*# sourceMappingURL=not-found.module.css.map */
1 change: 1 addition & 0 deletions src/pages/not-found/not-found.module.css.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 29 additions & 0 deletions src/pages/not-found/not-found.module.sass
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
.container
position: fixed
top: 0
left: 0
width: 100%
height: 100%
display: flex
justify-content: center
align-items: center
background-image: url('markup/img/not-found.jpeg')
background-repeat: no-repeat
background-size: cover
background-position: center

.box
background-color: rgba(255, 255, 255, 0.8)
text-align: center
padding: 0 30px
border-radius: 16px
box-shadow: 0px 0px 16px 30px rgba(255, 255, 255, 0.8)

.title
font-size: 5rem

.text
font-size: 2rem

.link
color: #4481c3
18 changes: 18 additions & 0 deletions src/pages/not-found/not-found.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Link } from 'react-router-dom';
import styles from './not-found.module.css';

const NotFound = () => (
<div className={styles.container}>
<div className={styles.box}>
<h1 className={styles.title}>404</h1>

<p className={styles.text}>Страница не найдена</p>

<Link to="/">
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

enum маршрутов можно использовать здесь

<span className={styles.link}>Вернуться на главную</span>
</Link>
</div>
</div>
);

export default NotFound;
File renamed without changes.
Loading