404
diff --git a/src/pages/offer-screen/offer-screen.tsx b/src/pages/offer-screen/offer-screen.tsx
index 449bee7..2fcab2a 100644
--- a/src/pages/offer-screen/offer-screen.tsx
+++ b/src/pages/offer-screen/offer-screen.tsx
@@ -1,37 +1,34 @@
-import {JSX, useEffect} from 'react';
+import {JSX, useEffect, useMemo} from 'react';
import {Helmet} from 'react-helmet-async';
-import {Link, Navigate, useParams} from 'react-router-dom';
-import {AppRoute, AuthorizationStatus} from '../../const.ts';
-import ReviewForm from '../../components/review-form/review-form.tsx';
+import {Navigate, useParams} from 'react-router-dom';
+import {AuthorizationStatus} from '../../const.ts';
import {Map} from '../../components/map/map.tsx';
-import {ReviewList} from '../../components/review-list/review-list.tsx';
+import MemoizedReviewList from '../../components/review-list/review-list.tsx';
import {OffersList} from '../../components/offers-list/offers-list.tsx';
-import {useAppSelector} from '../../hooks';
-import {store} from '../../store';
-import {setDetailOffer} from '../../store/action.ts';
-import {fetchDetailOffer, fetchNearOffers, fetchReviews, logout} from '../../store/api-actions.ts';
+import {useAppDispatch, useAppSelector} from '../../hooks';
+import {fetchDetailOffer, fetchNearOffers, fetchReviews} from '../../store/api-actions.ts';
import {Loading} from '../../components/loading/loading.tsx';
+import MemoizedHeader from '../../components/header/header.tsx';
+import {setDetailOffer} from '../../store/detail-offer-data/detail-offer-data.ts';
+import {getDetailOffer, getNearOffers, getReviews} from '../../store/detail-offer-data/selectors.ts';
+import {getAuthoriztionStatus} from '../../store/user-data/selectors.ts';
+import MemoizedReviewForm from '../../components/review-form/review-form.tsx';
export function OfferScreen() : JSX.Element {
const {id} = useParams();
+ const dispatch = useAppDispatch();
useEffect(() => {
- store.dispatch(setDetailOffer(null));
- store.dispatch(fetchDetailOffer(id!));
- store.dispatch(fetchNearOffers(id!));
- store.dispatch(fetchReviews(id!));
- }, [id]);
+ dispatch(setDetailOffer(null));
+ dispatch(fetchDetailOffer(id!));
+ dispatch(fetchNearOffers(id!));
+ dispatch(fetchReviews(id!));
+ }, [dispatch, id]);
- const offer = useAppSelector((state) => state.detailOffer);
- const nearOffers = useAppSelector((state) => state.nearOffers).slice(
- 0,
- 3,
- );
- const reviews = useAppSelector((state) => state.reviews);
- const favoriteCount = useAppSelector((state) => state.offers).filter((commonOffer) => commonOffer.isFavorite).length;
- const isAuth = useAppSelector((state) => state.authorizationStatus) === AuthorizationStatus.Authorized;
- const logoutHandle = () => {
- store.dispatch(logout());
- };
+ const offer = useAppSelector(getDetailOffer);
+ const nearOffers = useAppSelector(getNearOffers);
+ const memoizedNearOffers = useMemo(() => nearOffers.slice(0, 3), [nearOffers]);
+ const reviews = useAppSelector(getReviews);
+ const isAuth = useAppSelector(getAuthoriztionStatus) === AuthorizationStatus.Authorized;
if (offer === null){
return (
);
@@ -44,52 +41,9 @@ export function OfferScreen() : JSX.Element {
return (
- 6 sities: {offer.title}
+ 6 cities: {offer.title}
-
-
-
-
-
-
-
-
- {isAuth ? (
-
- ) : (
-
- )}
-
-
-
+
@@ -176,8 +130,8 @@ export function OfferScreen() : JSX.Element {
Reviews · {reviews.length}
-
- {isAuth && }
+
+ {isAuth && }