Skip to content

Commit

Permalink
refactor: changed the behavior of the input in the form
Browse files Browse the repository at this point in the history
  • Loading branch information
Runar committed Sep 1, 2022
1 parent 4f013c5 commit c98a496
Show file tree
Hide file tree
Showing 11 changed files with 58 additions and 46 deletions.
12 changes: 10 additions & 2 deletions src/components/Cards/CalleryAdsCards/GalleryAdsCards.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,25 @@ const promocards = [
export const GalleryAdsCards: FC = () => {
const navigate = useNavigate()

const onClickHandler = (path: string) => {
navigate(path)
}

return (
<div className={classes.cards}>
{promocards.map((card) => {
return (
<div key={card.id} className={card.classes} style={card.mr ? { marginRight: "30px" } : {}}>
<div
key={card.id}
className={card.classes}
style={card.mr ? { marginRight: "30px" } : {}}
>
<p className={classes.subtitle}>{card.subtitle}</p>
<h3 className={classes.title}>{card.title}</h3>
{card.isButtons && <Badges />}
<img src={card.image} className={classes.image} alt="аренда бань и саун" />
{!card.isButtons &&
<Button className={classes.jumpButton} onClick={() => navigate(card.path)}>
<Button className={classes.jumpButton} onClick={() => onClickHandler(card.path)}>
<IconSvg id={"#arrow"} className={classes.arrow} />
</Button>
}
Expand Down
1 change: 0 additions & 1 deletion src/components/FilterUI/Filter/ButtonGroup/ButtonGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ export const ButtonGroup: FC<IPropsButtons> = ({ onHandleClick }) => {
<Button
type="submit"
className={classes.showSelectedBtn}

>
Показать объекты
</Button>
Expand Down
6 changes: 1 addition & 5 deletions src/components/Form/ContactForm/ContactForm.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
outline: none;
border: 2px solid #f8f8f8;
transition: $transition;
&:focus {
&:hover {
border: 2px solid rgba(102, 78, 249, 0.8);
}
}
Expand Down Expand Up @@ -64,8 +64,4 @@

.error {
border: 2px solid rgba(235, 87, 87, 1);

input:focus {
border: 2px solid rgba(235, 87, 87, 1);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@
display: flex;
justify-content: center;
align-items: center;
height: 400px;
}
4 changes: 2 additions & 2 deletions src/components/ui-kit/Input/Input.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@
outline: transparent;
transition: $transition;

&:focus {
&:hover {
border: 2px solid rgba(102, 78, 249, 0.8);
}
&:focus + svg {
&:hover + svg {
fill: $moderate-blue;
opacity: 1;
}
Expand Down
25 changes: 1 addition & 24 deletions src/hooks/useFilter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ import {
import { useLocation } from "react-router";
import { path } from "../constants/pages";
import { IResponseData } from "../Interfaces/IResponseData";
import { fetchFlats } from "../store/thunks/flatThunk";
import { fetchCottages } from "../store/thunks/cottagesThunk";
import { fetchBaths } from "../store/thunks/bathsThunk";
import { fetchCars } from "../store/thunks/carsThunk";

export const useFilter = () => {
const location = useLocation();
Expand All @@ -25,24 +21,6 @@ export const useFilter = () => {
);
const [currentFetchData, setCurrentFetchData] = useState<IResponseData[]>();

useEffect(() => {
switch (location.pathname) {
case path.APARTMENTS:
dispatch(fetchFlats());
break;
case path.COTTAGES:
dispatch(fetchCottages());
break;
case path.BATHS:
dispatch(fetchBaths());
break;
case path.CARS:
dispatch(fetchCars());
break;
default:
}
}, [dispatch, location.pathname]);

useEffect(() => {
switch (location.pathname) {
case path.HOME:
Expand All @@ -56,7 +34,7 @@ export const useFilter = () => {
case path.CARS:
return setCurrentFetchData(cars);
}
}, [baths, cars, cottages, flats, location.pathname]);
}, [baths, cars, cottages, currentFetchData, flats, location.pathname]);

useEffect(() => {
submitFilteringFunction();
Expand Down Expand Up @@ -157,6 +135,5 @@ export const useFilter = () => {

return {
submitFilteringFunction,
filteredData,
};
};
33 changes: 32 additions & 1 deletion src/pages/Catalog/Catalog.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,42 @@
import { FC } from "react"
import { FC, useEffect } from "react"
import { useLocation } from "react-router-dom"
import { useAppDispatch } from "../../hooks/redux/redux-hooks"
import { useFilter } from "../../hooks/useFilter"

import { Recommended } from "./section-recommended/Recommended"
import { Products } from "./section-products/Products"
import { ShowMap } from "./section-showmap/ShowMap"
import { Filter as FilterUI } from "../../components/FilterUI/Filter/Filter"
import { fetchFlats } from "../../store/thunks/flatThunk";
import { fetchCottages } from "../../store/thunks/cottagesThunk";
import { fetchBaths } from "../../store/thunks/bathsThunk";
import { fetchCars } from "../../store/thunks/carsThunk";


import { path } from "../../constants/pages";

export const Catalog: FC = () => {
const location = useLocation();
const dispatch = useAppDispatch();

useEffect(() => {
switch (location.pathname) {
case path.APARTMENTS:
dispatch(fetchFlats());
break;
case path.COTTAGES:
dispatch(fetchCottages());
break;
case path.BATHS:
dispatch(fetchBaths());
break;
case path.CARS:
dispatch(fetchCars());
break;
default:
}
}, [dispatch, location.pathname]);

const { submitFilteringFunction } = useFilter()

const onHandleSubmit = () => {
Expand Down
16 changes: 8 additions & 8 deletions src/pages/Catalog/section-products/Products.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,15 @@ import { TiledCards } from "../../../components/Cards/TiledCards/TiledCards";
import { ListCards } from "../../../components/Cards/ListCards/ListCards";
import { Pagination } from "../../../components/Pagination/Pagination";
import { ShareButtons } from "../../../components/ShareButtons/ShareButtons";
import { ErrorMessage } from "../../../components/Notification/ErrorMessage/ErrorMessage"
import { Spinner } from "../../../Spinner/Spinner"

import { NothingFound } from "../../../components/Notification/NothingFound/NothingFound";


import { ISelectOption } from "../../../Interfaces/ISelectOption";
import { IResponseData } from "../../../Interfaces/IResponseData";
import classes from "./Products.module.scss"




export const Products: FC = () => {

const dispatch = useAppDispatch()
Expand Down Expand Up @@ -54,18 +53,19 @@ export const Products: FC = () => {
{filteredData && <span> Найдено {filteredData?.length} результата</span>}
</h3>

{slicedArray.length <= 0 ?
{slicedArray.length === 0 ?
<div className={classes.spinwrap}>
<Spinner />
</div> :
<NothingFound />
</div>
:
active === "tiles" &&
<div className={classes.tilesCardWrapper}>
{slicedArray?.map((items: IResponseData) =>
<TiledCards key={items.id} data={items} className={classes.shadow} />
)}
</div>
}

{active === "list" &&
<div className={classes.listCardWrapper}>
{slicedArray?.map((items: IResponseData) =>
Expand Down
3 changes: 1 addition & 2 deletions src/pages/Home/Home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@ import { Rent } from "./section-rent/Rent";
import { Presentation } from "./section-presentation/Presentation";
import { About } from "./section-about/About";


export const Home: FC = () => {

return (
<>
<Filter/>
<Filter />
<Gallery />
<Rent />
<Presentation />
Expand Down
2 changes: 1 addition & 1 deletion src/pages/Home/section-rent/Rent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const Rent: FC = () => {
dispatch(fetchFlats())
}, [dispatch])

const { loading, error, flats } = useAppSelector(state => state.flats)
const { loading, error } = useAppSelector(state => state.flats)
const { stateData, filteredData } = useAppSelector(state => state.filter)
const { rentTitle, totalOffersTitle } = usePageTitle()

Expand Down
1 change: 1 addition & 0 deletions src/store/reducers/filterReducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ const filterSlice = createSlice({
},

resetFilter(state) {
state.sortValue = { value: "По умолчанию", label: "По умолчанию" };
state.stateData.city = "";
state.stateData.room = "";
state.stateData.area = "";
Expand Down

1 comment on commit c98a496

@vercel
Copy link

@vercel vercel bot commented on c98a496 Sep 1, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.