diff --git a/src/components/cities-list.tsx b/src/components/cities-list.tsx index 8b7417e..db071b8 100644 --- a/src/components/cities-list.tsx +++ b/src/components/cities-list.tsx @@ -3,6 +3,7 @@ import { CITIES } from '../consts/cities.ts'; import { City } from '../dataTypes/city.ts'; import { useAppDispatch } from '../store/store.ts'; import { changeCity } from '../store/offers/offers.slice.ts'; +import { fetchOffers } from '../store/async-actions.ts'; interface CitiesListProps { activeCityName: string; @@ -25,7 +26,10 @@ function CitiesListImpl({ ) : (
dispatch(changeCity(city))} + onClick={() => { + dispatch(fetchOffers()); + dispatch(changeCity(city)); + }} > {city.name}
diff --git a/src/components/layout/header.tsx b/src/components/layout/header.tsx index a33fc12..68f246b 100644 --- a/src/components/layout/header.tsx +++ b/src/components/layout/header.tsx @@ -1,22 +1,30 @@ import { Link } from 'react-router-dom'; import { AppRoute } from '../../dataTypes/enums/app-route.ts'; -import { useAppSelector } from '../../store/store.ts'; +import { useAppDispatch, useAppSelector } from '../../store/store.ts'; import { memo } from 'react'; import { UserInfo } from './user-info.tsx'; import { getIsAuthorized } from '../../store/user/user.selectors.ts'; +import { fetchOffers } from '../../store/async-actions.ts'; interface HeaderProps { dontShowUserInfo: boolean; } function HeaderImpl({ dontShowUserInfo }: HeaderProps) { + const dispatch = useAppDispatch(); const isAuthorized = useAppSelector(getIsAuthorized); return (
- + { + dispatch(fetchOffers()); + }} + > { city: AMSTERDAM, offers: getMockOffers(3), sorting: (offers: Offer[]) => - offers.toSorted((a, b) => a.price - b.price), + offers.sort((a, b) => a.price - b.price), favoritesOffers: getMockOffers(4), }, };