Skip to content

Commit

Permalink
hw 8.1
Browse files Browse the repository at this point in the history
  • Loading branch information
ktvtk committed Dec 1, 2024
1 parent 9e40b0f commit 8273a2f
Show file tree
Hide file tree
Showing 7 changed files with 8 additions and 12 deletions.
6 changes: 2 additions & 4 deletions src/components/place-card/place-card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function PlaceCard({offer, onMouseLeave, onMouseEnter}: PlaceCardProps): JSX.Ele
} else {
navigate(AppRoute.Login);
}
}, [isAuth, isFavorite, offer, dispatch, id]);
}, [isAuth, isFavorite, offer, dispatch, id, navigate]);

return (
<article className="cities__card place-card"
Expand Down Expand Up @@ -80,7 +80,5 @@ function PlaceCard({offer, onMouseLeave, onMouseEnter}: PlaceCardProps): JSX.Ele
);
}

const MemoizedPlaceCard = memo(PlaceCard, (prevProps, nextProps) => {
return prevProps.offer.id === nextProps.offer.id && prevProps.offer.isFavorite === nextProps.offer.isFavorite;
});
const MemoizedPlaceCard = memo(PlaceCard, (prevProps, nextProps) => prevProps.offer.id === nextProps.offer.id && prevProps.offer.isFavorite === nextProps.offer.isFavorite);
export default MemoizedPlaceCard;
4 changes: 1 addition & 3 deletions src/components/review-list/review-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,5 @@ function ReviewList({reviews} : ReviewListProps) : JSX.Element {
);
}

const MemoizedReviewList = memo(ReviewList, (prevProps, nextProps) => {
return prevProps.reviews === nextProps.reviews;
});
const MemoizedReviewList = memo(ReviewList, (prevProps, nextProps) => prevProps.reviews === nextProps.reviews);
export default MemoizedReviewList;
2 changes: 1 addition & 1 deletion src/pages/offer-screen/offer-screen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export function OfferScreen() : JSX.Element {
dispatch(fetchDetailOffer(id!));
dispatch(fetchNearOffers(id!));
dispatch(fetchReviews(id!));
}, [id]);
}, [dispatch, id]);

const offer = useAppSelector(getDetailOffer);
const nearOffers = useAppSelector(getNearOffers);
Expand Down
2 changes: 1 addition & 1 deletion src/servises/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export const createAPI = () : AxiosInstance => {
);
}
if (error.response && error.response.status === 404) {
store.dispatch(setDetailOffer('NOT_FOUND'));
store.dispatch(setDetailOffer(undefined));
}
throw error;
},
Expand Down
2 changes: 1 addition & 1 deletion src/store/detail-offer-data/detail-offer-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const detailOfferData = createSlice({
name: Namespace.DetailOffer,
initialState,
reducers:{
setDetailOffer: (state, action: PayloadAction<DetailOffer | null | 'NOT_FOUND'>) => {
setDetailOffer: (state, action: PayloadAction<DetailOffer | null | undefined>) => {
state.detailOffer = action.payload;
},
setNearOffers: (state, action: PayloadAction<Offer[]>) => {
Expand Down
2 changes: 1 addition & 1 deletion src/store/detail-offer-data/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ import {Namespace} from '../../const.ts';
import {Offer} from '../../types/offer.ts';
import {Review} from '../../types/review.ts';

export const getDetailOffer = (state: State): DetailOffer | null => state[Namespace.DetailOffer].detailOffer;
export const getDetailOffer = (state: State): DetailOffer | null | undefined=> state[Namespace.DetailOffer].detailOffer;
export const getNearOffers = (state: State): Offer[] => state[Namespace.DetailOffer].nearOffers;
export const getReviews = (state: State): Review[] => state[Namespace.DetailOffer].reviews;
2 changes: 1 addition & 1 deletion src/types/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export type AppData = {
};

export type DetailOfferData = {
detailOffer: DetailOffer | null | 'NOT_FOUND';
detailOffer: DetailOffer | null | undefined;
nearOffers: Offer[];
reviews: Review[];
};
Expand Down

0 comments on commit 8273a2f

Please sign in to comment.