diff --git a/src/components/app/app.tsx b/src/components/app/app.tsx index 1dd10c2..03137f9 100644 --- a/src/components/app/app.tsx +++ b/src/components/app/app.tsx @@ -5,20 +5,22 @@ import FavoritesScreen from '../../pages/favorites-screen/favorites-screen.tsx'; import NotFoundScreen from '../../pages/not-found-screen/not-found-screen.tsx'; import OfferScreen from '../../pages/offer-screen/offer-screen.tsx'; import PrivateRoute from '../private-route/private-route.tsx'; -import { AppRoute, AuthorizationStatus } from '../../const.ts'; +import { AppRoute } from '../../const.ts'; import { useAppSelector } from '../../hooks/index.ts'; import LoadingScreen from '../../pages/loading-screen/loading-screen.tsx'; import HistoryRouter from '../history-route/history-route.tsx'; import browserHistory from '../../browser-history.ts'; import MainRouteRedirection from '../main-route-redirection/main-route-redirection.tsx'; +import { getAuthorizationStatus } from '../../store/user-process/selectors.ts'; +import { getIsOffersDataLoading } from '../../store/offers-data/selectors.ts'; function App(): JSX.Element { - const isOffersDataLoading = useAppSelector((state) => state.isOffersDataLoading); - const authorizationStatus = useAppSelector((state) => state.authorizationStatus); + const isOffersDataLoading = useAppSelector(getIsOffersDataLoading); + const authorizationStatus = useAppSelector(getAuthorizationStatus); - if (isOffersDataLoading || authorizationStatus === AuthorizationStatus.Unknown) { + if (isOffersDataLoading || !authorizationStatus) { return ( ); diff --git a/src/components/cards-sorting-options/cards-sorting-options.tsx b/src/components/cards-sorting-options/cards-sorting-options.tsx index 732c88d..02a3f9b 100644 --- a/src/components/cards-sorting-options/cards-sorting-options.tsx +++ b/src/components/cards-sorting-options/cards-sorting-options.tsx @@ -1,28 +1,60 @@ -import React from 'react'; +import { memo, useState } from 'react'; import { useAppDispatch, useAppSelector } from '../../hooks'; import { filters } from '../../utils'; -import { changeSortOptions } from '../../store/action'; +import { changeSortType } from '../../store/common-data/common-data'; +import { getSortType } from '../../store/common-data/selectors'; -function CardsSortingOptions(): JSX.Element { - const chosenSortType = useAppSelector((state) => state.sortType); +function CardsSortingOptionsComponent(): JSX.Element { + const chosenSortType = useAppSelector(getSortType); const dispatch = useAppDispatch(); - const [isSortOpened, setIsSortOpened] = React.useState(false); + const [isSortOpened, setIsSortOpened] = useState(false); + + const handleSortOptionClick = (sortType: string) => { + dispatch(changeSortType(sortType)); + setIsSortOpened(false); + }; + return (
- Sort by + Sort by setIsSortOpened(!isSortOpened)}> {chosenSortType} -