From db93c5ad92cccf4c7359ffbc0d5cbe195f9028b0 Mon Sep 17 00:00:00 2001 From: mayonnaise <90057279+Mayanzev@users.noreply.github.com> Date: Mon, 20 May 2024 17:46:47 +0300 Subject: [PATCH 1/3] optimization and fixes --- .../cards-sorting-options.tsx | 51 +++++++++++--- src/components/city-list/city-list.tsx | 1 - src/components/comment-form/comment-form.tsx | 66 +++++++++---------- src/components/header/header.tsx | 5 +- .../login-navigation/login-navigation.tsx | 4 +- src/components/reviews-item/reviews-item.tsx | 3 +- src/components/reviews-list/reviews-list.tsx | 8 ++- .../favorites-screen/favorites-screen.tsx | 4 +- src/pages/loading-screen/loading-screen.css | 24 +++++++ src/pages/loading-screen/loading-screen.tsx | 7 +- src/pages/login-screen/login-screen.tsx | 13 +++- src/pages/main-screen/main-screen.tsx | 4 +- src/pages/offer-screen/offer-screen.tsx | 6 +- src/utils.ts | 11 ++++ 14 files changed, 143 insertions(+), 64 deletions(-) create mode 100644 src/pages/loading-screen/loading-screen.css diff --git a/src/components/cards-sorting-options/cards-sorting-options.tsx b/src/components/cards-sorting-options/cards-sorting-options.tsx index 732c88d..4ecdea7 100644 --- a/src/components/cards-sorting-options/cards-sorting-options.tsx +++ b/src/components/cards-sorting-options/cards-sorting-options.tsx @@ -1,28 +1,59 @@ -import React from 'react'; +import { memo, useState } from 'react'; import { useAppDispatch, useAppSelector } from '../../hooks'; import { filters } from '../../utils'; import { changeSortOptions } from '../../store/action'; -function CardsSortingOptions(): JSX.Element { +function CardsSortingOptionsComponent(): JSX.Element { const chosenSortType = useAppSelector((state) => state.sortType); const dispatch = useAppDispatch(); - const [isSortOpened, setIsSortOpened] = React.useState(false); + const [isSortOpened, setIsSortOpened] = useState(false); + + const handleSortOptionClick = (sortType: string) => { + dispatch(changeSortOptions(sortType)); + setIsSortOpened(false); + }; + return (
- Sort by + Sort by setIsSortOpened(!isSortOpened)}> {chosenSortType} -