Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

правит нейминг обработчиков #15

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/components/favorite-button/favorite-button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function FavoriteButton({componentType, isFavorite, offerId}: FavoriteButtonProp

const isAuth = authStatus === AuthStatus.Auth;

const onClickHandler = () => {
const handleButtonClick = () => {
if (!isAuth) {
navigate(AppRoute.Login);
}
Expand All @@ -59,7 +59,7 @@ function FavoriteButton({componentType, isFavorite, offerId}: FavoriteButtonProp
isFavoriteCurrent && isAuth && `${componentType}__bookmark-button--active`)
}
type="button"
onClick={onClickHandler}
onClick={handleButtonClick}
disabled={isDisabled}
>
<svg className={`${componentType}__bookmark-icon`} {...sizes[componentType]}>
Expand Down
4 changes: 2 additions & 2 deletions src/components/form-login/login-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ function LoginForm() {
const emailRegex = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/;
const passwordRegex = /^(?=.*\d)(?=.*[a-zA-Z]).*$/;

const onSubmitHandler = (e: React.FormEvent<HTMLFormElement>) => {
const handleFormSubmit = (e: React.FormEvent<HTMLFormElement>) => {
e.preventDefault();
if (!emailRegex.test(email)) {
toast.error('Введен неверный email');
Expand All @@ -29,7 +29,7 @@ function LoginForm() {
<section className="login">
<h1 className="login__title">Sign in</h1>
<form
onSubmit={(e) => onSubmitHandler(e)}
onSubmit={(e) => handleFormSubmit(e)}
className="login__form form"
action="#"
method="post"
Expand Down
8 changes: 4 additions & 4 deletions src/components/form-review/form-review.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ function FormReview({offerId}: FormReviewProps) {
const [isFormDisabled, setIsFormDisabled] = useState(false);
const {postComment} = useActionCreators(commentsActions);

const onChangeForm = (evt: FormEvent<HTMLFormElement>) => {
const handleFormChange = (evt: FormEvent<HTMLFormElement>) => {
const form = evt.currentTarget as Form;
const rating = form.rating.value;
const comment = form.review.value;
setIsSubmitDisabled(isValidForm(comment, rating));
};

const onFormSubmit = (evt: FormEvent<HTMLFormElement>) => {
const handleFormSubmit = (evt: FormEvent<HTMLFormElement>) => {
evt.preventDefault();
const form = evt.currentTarget as Form;

Expand Down Expand Up @@ -68,8 +68,8 @@ function FormReview({offerId}: FormReviewProps) {

return (
<form
onSubmit={(evt) => onFormSubmit(evt)}
onChange={(evt) => onChangeForm(evt)}
onSubmit={(evt) => handleFormSubmit(evt)}
onChange={(evt) => handleFormChange(evt)}
className="reviews__form form"
action="#"
method="post"
Expand Down
4 changes: 2 additions & 2 deletions src/components/header-nav-auth-user/header-nav-auth-user.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function HeaderNavAuthUser() {
const {fetchFavorites} = useActionCreators(favoritesActions);
const statusFetchFavorites = useAppSelector(favoritesSelectors.statusFetchFavorites);

const logoutHandler = async (e: React.MouseEvent<HTMLAnchorElement, MouseEvent>) => {
const handleSingOutClick = async (e: React.MouseEvent<HTMLAnchorElement, MouseEvent>) => {
e.preventDefault();
await logout().unwrap().catch((error: Error) => {
toast.warning(error.message);
Expand Down Expand Up @@ -44,7 +44,7 @@ function HeaderNavAuthUser() {
className="header__nav-link"
href="#"
onClick={(e) => {
logoutHandler(e).catch((error: Error) => toast.warning(error.message));
handleSingOutClick(e).catch((error: Error) => toast.warning(error.message));
}}
>
<span className="header__signout">Sign out</span>
Expand Down
12 changes: 6 additions & 6 deletions src/components/offer-card/offer-card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import {memo} from 'react';
interface PlaceCardProps {
offer: OfferShortInfo;
componentType: 'cities' | 'favorites' | 'near-places';
onHoverCard?: (offer: OfferShortInfo | null) => void;
handleCardHover?: (offer: OfferShortInfo | null) => void;
}

function OfferCard_({offer, componentType, onHoverCard}: PlaceCardProps) {
function OfferCard_({offer, componentType, handleCardHover}: PlaceCardProps) {
const {
id,
isPremium,
Expand All @@ -38,14 +38,14 @@ function OfferCard_({offer, componentType, onHoverCard}: PlaceCardProps) {
},
};

const mouseOnHandler = () => onHoverCard?.(offer);
const mouseOfHandler = () => onHoverCard?.(null);
const handleCardMouseOn = () => handleCardHover?.(offer);
const handleCardMouseOff = () => handleCardHover?.(null);

return (
<article
className={`${componentType}__card place-card`}
onMouseEnter={mouseOnHandler}
onMouseLeave={mouseOfHandler}
onMouseEnter={handleCardMouseOn}
onMouseLeave={handleCardMouseOff}
>
{isPremium && (
<div className="place-card__mark">
Expand Down
4 changes: 2 additions & 2 deletions src/components/offers-list/offers-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function OffersList ({offersByCity, city}: OffersListProps) {
}, [setActiveSortOption]);

const {setActiveOffer} = useActionCreators(offersActions);
const onHoverCard = useCallback((offerActive: OfferShortInfo | null) => setActiveOffer(offerActive), [setActiveOffer]);
const handleCardHover = useCallback((offerActive: OfferShortInfo | null) => setActiveOffer(offerActive), [setActiveOffer]);

if (offersByCity.length === 0) {
return (
Expand Down Expand Up @@ -55,7 +55,7 @@ function OffersList ({offersByCity, city}: OffersListProps) {
key={offer.id}
componentType={'cities'}
offer={offer}
onHoverCard={onHoverCard}
handleCardHover={handleCardHover}
/>
))}
</div>
Expand Down
16 changes: 8 additions & 8 deletions src/components/sort/sort.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,29 +14,29 @@ function Sort_({activeSortOption, setActiveSortOption}: Props) {

useEffect(() => {
if (isOn) {
const onEscKeyDown = (evt: KeyboardEvent) => {
const handleEscKeyDown = (evt: KeyboardEvent) => {
if (evt.key === 'Escape') {
evt.preventDefault();
off();
}
};
const onClickOutside = (evt: MouseEvent) => {
const handleClickOutside = (evt: MouseEvent) => {
if (sortFormRef.current && !(sortFormRef.current as HTMLElement).contains(evt.target as Node)) {
off();
}
};

document.addEventListener('keydown', onEscKeyDown);
document.addEventListener('click', onClickOutside);
document.addEventListener('keydown', handleEscKeyDown);
document.addEventListener('click', handleClickOutside);

return () => {
document.removeEventListener('keydown', onEscKeyDown);
document.removeEventListener('click', onClickOutside);
document.removeEventListener('keydown', handleEscKeyDown);
document.removeEventListener('click', handleClickOutside);
};
}
}, [isOn, off, activeSortOption]);

const onClickSortOption = (sortOption: SortOption) => {
const handleSortOptionClick = (sortOption: SortOption) => {
setActiveSortOption(sortOption);
off();
};
Expand All @@ -56,7 +56,7 @@ function Sort_({activeSortOption, setActiveSortOption}: Props) {
key={sortOption}
className={classNames('places__option', activeSortOption === sortOption && 'places__option--active')}
tabIndex={index}
onClick={() => onClickSortOption(sortOption)}
onClick={() => handleSortOptionClick(sortOption)}
>
{sortOption}
</li>
Expand Down
Loading