+
{
- activeCity &&
+ activeCity && offersByCity.length > 0 &&
}
diff --git a/src/pages/offer/offer.tsx b/src/pages/offer/offer.tsx
index 6ea9891..8217f56 100644
--- a/src/pages/offer/offer.tsx
+++ b/src/pages/offer/offer.tsx
@@ -11,7 +11,6 @@ import {AuthStatus, CITIES} from '../../const.ts';
import Map from '../../components/map/map.tsx';
import OfferCard from '../../components/offer-card/offer-card.tsx';
import {useActionCreators, useAppSelector} from '../../hooks/store.ts';
-import {offersActions} from '../../store/slices/offers.ts';
import {useEffect} from 'react';
import {offerFullInfoActions, offerFullInfoSelectors} from '../../store/slices/offer-full-info.ts';
import {offersNearActions, offersNearSelectors} from '../../store/slices/offers-near.ts';
@@ -22,9 +21,11 @@ interface OfferProps {
title?: string;
}
+const MAX_COUNT_IMAGES = 6;
+const MAX_COUNT_NEAR_OFFERS = 3;
+
function Offer({title = 'Offer'}: OfferProps) {
useDocumentTitle(title);
- const {setActiveOffer} = useActionCreators(offersActions);
const {fetchOfferFullInfo} = useActionCreators(offerFullInfoActions);
const {fetchOffersNear} = useActionCreators(offersNearActions);
@@ -40,7 +41,7 @@ function Offer({title = 'Offer'}: OfferProps) {
}, [fetchOfferFullInfo, fetchOffersNear, offerId]);
const offerFullInfo = useAppSelector(offerFullInfoSelectors.offerFullInfo);
- const offersNear = useAppSelector(offersNearSelectors.offersNear);
+ const offersNear = useAppSelector(offersNearSelectors.offersNear).slice(0, MAX_COUNT_NEAR_OFFERS);
if (!offerFullInfo) {
@@ -72,11 +73,13 @@ function Offer({title = 'Offer'}: OfferProps) {
- {images.map((image) => (
-
-
-
- ))}
+ {
+ images.slice(0, MAX_COUNT_IMAGES).map((image) => (
+
+
+
+ ))
+ }
@@ -98,10 +101,10 @@ function Offer({title = 'Offer'}: OfferProps) {
{capitalizeFirstLetter(type)}
- {bedrooms} Bedrooms
+ {`${bedrooms} Bedroom${bedrooms > 1 ? 's' : ''}`}
- Max {maxAdults} adults
+ {`Max ${maxAdults} adult${maxAdults > 1 ? 's' : ''}`}
@@ -128,7 +131,7 @@ function Offer({title = 'Offer'}: OfferProps) {
- {cityFullInfo &&
@@ -140,7 +143,6 @@ function Offer({title = 'Offer'}: OfferProps) {
key={nearOffer.id}
offer={nearOffer}
componentType="near-places"
- hoverHandler={() => setActiveOffer(nearOffer)}
/>
)
)}
diff --git a/src/store/slices/comments.ts b/src/store/slices/comments.ts
index 09bb646..74a2061 100644
--- a/src/store/slices/comments.ts
+++ b/src/store/slices/comments.ts
@@ -1,7 +1,8 @@
-import {createSlice} from '@reduxjs/toolkit';
+import {createSelector, createSlice} from '@reduxjs/toolkit';
import {RequestStatus} from '../../const.ts';
import {Comment} from '../../types/comment.ts';
import {fetchCommentsAction, postCommentAction} from '../thunks/comments.ts';
+import {sortCommentsByDate} from '../../utils/sort.ts';
interface CommentsState {
comments: Comment[];
@@ -52,6 +53,13 @@ const commentsActions = {
fetchComments: fetchCommentsAction,
postComment: postCommentAction,
};
-const commentsSelectors = commentsSlice.selectors;
+const commentsSelectors = {
+ ...commentsSlice.selectors,
+ sortedComments:
+ createSelector(
+ commentsSlice.selectors.comments,
+ (comments) => comments.toSorted(sortCommentsByDate)
+ ),
+};
export { commentsSlice, commentsActions, commentsSelectors };
diff --git a/src/utils/common.ts b/src/utils/common.ts
index eed0abe..699ae07 100644
--- a/src/utils/common.ts
+++ b/src/utils/common.ts
@@ -1,7 +1,7 @@
import {CityName, OfferShortInfo} from '../types/offer.ts';
import {CITIES} from '../const.ts';
-const getRatingValue = (rating: OfferShortInfo['rating']) => (rating * 100) / 5;
+const getRatingValue = (rating: OfferShortInfo['rating']) => (Math.round(rating) * 100) / 5;
const capitalizeFirstLetter = (string: string) => string.charAt(0).toUpperCase() + string.slice(1);
diff --git a/src/utils/sort.ts b/src/utils/sort.ts
index 8dd14b1..29425ea 100644
--- a/src/utils/sort.ts
+++ b/src/utils/sort.ts
@@ -1,5 +1,6 @@
import {OfferShortInfo} from '../types/offer.ts';
import {SortOption} from '../components/sort/const.ts';
+import {Comment} from '../types/comment.ts';
function sortOffers (sortType: SortOption, offers: OfferShortInfo[]) {
switch (sortType) {
@@ -16,4 +17,8 @@ function sortOffers (sortType: SortOption, offers: OfferShortInfo[]) {
}
}
+export function sortCommentsByDate(commentA: Comment, commentB: Comment) {
+ return new Date(commentB.date).getTime() - new Date(commentA.date).getTime();
+}
+
export {sortOffers};