From 125af5d4d94c8492b712da46c06bb151a7484b18 Mon Sep 17 00:00:00 2001 From: Gurikov Maxim Date: Tue, 12 Nov 2024 19:52:40 +0500 Subject: [PATCH] fixes --- .../{ => favorites-page}/favorites-page.tsx | 6 ++--- src/Pages/{ => login-page}/login-page.tsx | 0 src/Pages/{ => main-page}/main-page.tsx | 22 +++++++++-------- src/Pages/{ => offer-page}/offer-page.tsx | 24 +++++++++---------- src/components/app.tsx | 8 +++---- src/store/actions.ts | 6 ++--- src/store/store.ts | 4 ++-- 7 files changed, 36 insertions(+), 34 deletions(-) rename src/Pages/{ => favorites-page}/favorites-page.tsx (86%) rename src/Pages/{ => login-page}/login-page.tsx (100%) rename src/Pages/{ => main-page}/main-page.tsx (75%) rename src/Pages/{ => offer-page}/offer-page.tsx (83%) diff --git a/src/Pages/favorites-page.tsx b/src/Pages/favorites-page/favorites-page.tsx similarity index 86% rename from src/Pages/favorites-page.tsx rename to src/Pages/favorites-page/favorites-page.tsx index f8a3e67..e605929 100644 --- a/src/Pages/favorites-page.tsx +++ b/src/Pages/favorites-page/favorites-page.tsx @@ -1,7 +1,7 @@ import { Helmet } from 'react-helmet-async'; -import { Layout } from '../components/layout.tsx'; -import { OfferGroup } from '../components/offer/offer-group.tsx'; -import { Offer } from '../dataTypes/offer.ts'; +import { Layout } from '../../components/layout.tsx'; +import { OfferGroup } from '../../components/offer/offer-group.tsx'; +import { Offer } from '../../dataTypes/offer.ts'; interface FavoritesPageProps { offers: Offer[]; diff --git a/src/Pages/login-page.tsx b/src/Pages/login-page/login-page.tsx similarity index 100% rename from src/Pages/login-page.tsx rename to src/Pages/login-page/login-page.tsx diff --git a/src/Pages/main-page.tsx b/src/Pages/main-page/main-page.tsx similarity index 75% rename from src/Pages/main-page.tsx rename to src/Pages/main-page/main-page.tsx index 907666f..a78219c 100644 --- a/src/Pages/main-page.tsx +++ b/src/Pages/main-page/main-page.tsx @@ -1,15 +1,15 @@ /* eslint-disable react-hooks/exhaustive-deps */ import React, { useState } from 'react'; -import { Offer } from '../dataTypes/offer.ts'; -import { OffersList } from '../components/offer/offers-list.tsx'; -import { Layout } from '../components/layout.tsx'; +import { Offer } from '../../dataTypes/offer.ts'; +import { OffersList } from '../../components/offer/offers-list.tsx'; +import { Layout } from '../../components/layout.tsx'; import { Helmet } from 'react-helmet-async'; import { Nullable } from 'vitest'; -import { Map } from '../components/map/map.tsx'; -import { useAppSelector } from '../store/store.ts'; -import { CitiesList } from '../components/cities-list.tsx'; -import { pluralizeAndCombine } from '../utils/string-utils.ts'; -import { OfferSortSelect } from '../components/offer/offer-sort-select.tsx'; +import { Map } from '../../components/map/map.tsx'; +import { useAppSelector } from '../../store/store.ts'; +import { CitiesList } from '../../components/cities-list.tsx'; +import { pluralizeAndCombine } from '../../utils/string-utils.ts'; +import { OfferSortSelect } from '../../components/offer/offer-sort-select.tsx'; export function MainPage(): React.JSX.Element { const [activeOffer, setActiveOffer] = useState>(null); @@ -19,6 +19,9 @@ export function MainPage(): React.JSX.Element { ); const sort = useAppSelector((state) => state.sorting); const offers = sort(unsortedOffers); + const offersCountCaption = offers.length === 0 + ? 'No places to stay available' + : `${pluralizeAndCombine('place', offers.length)} to stay in ${city.name}`; return (
@@ -31,8 +34,7 @@ export function MainPage(): React.JSX.Element {

Places

- {pluralizeAndCombine('place', offers.length)} to stay in{' '} - {city.name} + {offersCountCaption} ('mainPage/changeCity'); +export const changeCity = createAction('offers/changeCity'); -export const fillOffers = createAction('mainPage/fillOffers'); +export const setOffers = createAction('offers/setOffers'); -export const setSorting = createAction('mainPage/setSorting'); +export const setSorting = createAction('offers/setSorting'); diff --git a/src/store/store.ts b/src/store/store.ts index c9c756a..a46b772 100644 --- a/src/store/store.ts +++ b/src/store/store.ts @@ -1,5 +1,5 @@ import { configureStore, createReducer } from '@reduxjs/toolkit'; -import {changeCity, fillOffers, setSorting} from './actions.ts'; +import {changeCity, setOffers, setSorting} from './actions.ts'; import { offerMocks } from '../mocks/offers.ts'; import { TypedUseSelectorHook, useDispatch, useSelector } from 'react-redux'; import { AppDispatch, State } from '../dataTypes/store-types.ts'; @@ -17,7 +17,7 @@ const reducer = createReducer(initialState, (builder) => { .addCase(changeCity, (state, action) => { state.city = action.payload; }) - .addCase(fillOffers, (state, action) => { + .addCase(setOffers, (state, action) => { state.offers = action.payload; }) .addCase(setSorting, (state, action) => {