Skip to content

Commit

Permalink
module5-task2 + fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Mayanzev committed Apr 7, 2024
1 parent 2dcc4d4 commit 75bb2a3
Show file tree
Hide file tree
Showing 13 changed files with 108 additions and 167 deletions.
12 changes: 6 additions & 6 deletions src/components/app/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,29 @@ import OfferScreen from '../../pages/offer-screen/offer-screen.tsx';
import PrivateRoute from '../private-route/private-route.tsx';
import { AppRoute, AuthorizationStatus } from '../../const.ts';
import { Offer } from '../../types/offer';
import { OFFERS } from '../../mocks/offers.ts';

type AppScreenProps = {
placesCount: number;
offers: Offer[];
}

function App({placesCount, offers}: AppScreenProps): JSX.Element {
const favourites: Offer[] = offers.filter((o) => o.isFavorite);
function App({placesCount}: AppScreenProps): JSX.Element {
const favourites: Offer[] = OFFERS.filter((o) => o.isFavorite);
return (
<BrowserRouter>
<Routes>
<Route path="*" element={<NotFoundScreen/>} />
<Route path={AppRoute.Main} element={<MainScreen placesCount={placesCount} offers={offers}/>} />
<Route path={AppRoute.Main} element={<MainScreen placesCount={placesCount} offers={OFFERS}/>} />
<Route
path={AppRoute.Favorites}
element={
<PrivateRoute authorizationStatus={AuthorizationStatus.NoAuth} >
<PrivateRoute authorizationStatus={AuthorizationStatus.Auth} >
<FavoritesScreen offers={favourites}/>
</PrivateRoute>
}
/>
<Route path={AppRoute.Login} element={<LoginScreen/>} />
<Route path={AppRoute.Offer} element={<OfferScreen/>} />
<Route path={AppRoute.Offer} element={<OfferScreen offer={OFFERS[2]}/>} />
</Routes>
</BrowserRouter>
);
Expand Down
5 changes: 3 additions & 2 deletions src/components/city-card/city-card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ import { Link } from 'react-router-dom';

type OfferProps = {
offer: Offer;
isStandartCardType: boolean;
}

function CityCard({offer}: OfferProps): JSX.Element {
function CityCard({offer, isStandartCardType}: OfferProps): JSX.Element {
return (
<article className="cities__card place-card">
<article className={(isStandartCardType) ? 'cities__card place-card' : 'near-places__card place-card'}>
{offer.isPremium ? (
<div className="place-card__mark">
<span>Premium</span>
Expand Down
2 changes: 1 addition & 1 deletion src/components/map/map.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import 'leaflet/dist/leaflet.css';
type MapProps = {
city: City;
points: Point[];
selectedPoint: Point | undefined;
selectedPoint?: Point;
}

function Map(props: MapProps): JSX.Element {
Expand Down
7 changes: 4 additions & 3 deletions src/components/offer-list/offer-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ import CityCard from '../city-card/city-card';

type OfferListProps = {
offers: Offer[];
isStandartCardType: boolean

Check failure on line 6 in src/components/offer-list/offer-list.tsx

View workflow job for this annotation

GitHub Actions / Check

Expected a semicolon
};

function OfferList({offers}: OfferListProps): JSX.Element {
function OfferList({offers, isStandartCardType}: OfferListProps): JSX.Element {
return (
<div className="cities__places-list places__list tabs__content">
<div className={(isStandartCardType) ? 'cities__places-list places__list tabs__content' : 'near-places__list places__list'}>
{offers.map((offer) => (
<CityCard key={offer.id} offer={offer}/>
<CityCard key={offer.id} offer={offer} isStandartCardType={isStandartCardType}/>
))}
</div>
);
Expand Down
33 changes: 33 additions & 0 deletions src/components/reviews-item/reviews-item.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { Review } from '../../types/review';

type ReviewProps = {
review: Review;
}

function ReviewItem({review}: ReviewProps): JSX.Element {
return (
<li className="reviews__item">
<div className="reviews__user user">

Check failure on line 10 in src/components/reviews-item/reviews-item.tsx

View workflow job for this annotation

GitHub Actions / Check

Expected indentation of 6 spaces but found 4
<div className="reviews__avatar-wrapper user__avatar-wrapper">

Check failure on line 11 in src/components/reviews-item/reviews-item.tsx

View workflow job for this annotation

GitHub Actions / Check

Expected indentation of 8 spaces but found 4
<img className="reviews__avatar user__avatar" src={review.avatar} width="54" height="54" alt="Reviews avatar"/>

Check failure on line 12 in src/components/reviews-item/reviews-item.tsx

View workflow job for this annotation

GitHub Actions / Check

Expected indentation of 10 spaces but found 8
</div>

Check failure on line 13 in src/components/reviews-item/reviews-item.tsx

View workflow job for this annotation

GitHub Actions / Check

Expected indentation of 8 spaces but found 4
<span className="reviews__user-name">

Check failure on line 14 in src/components/reviews-item/reviews-item.tsx

View workflow job for this annotation

GitHub Actions / Check

Expected indentation of 8 spaces but found 4
{review.author}

Check failure on line 15 in src/components/reviews-item/reviews-item.tsx

View workflow job for this annotation

GitHub Actions / Check

Expected indentation of 10 spaces but found 8
</span>

Check failure on line 16 in src/components/reviews-item/reviews-item.tsx

View workflow job for this annotation

GitHub Actions / Check

Expected indentation of 8 spaces but found 4
</div>

Check failure on line 17 in src/components/reviews-item/reviews-item.tsx

View workflow job for this annotation

GitHub Actions / Check

Expected indentation of 6 spaces but found 4
<div className="reviews__info">

Check failure on line 18 in src/components/reviews-item/reviews-item.tsx

View workflow job for this annotation

GitHub Actions / Check

Expected indentation of 6 spaces but found 4
<div className="reviews__rating rating">
<div className="reviews__stars rating__stars">
<span style={{width: `${(review.rating / 5) * 100}%`}}></span>
<span className="visually-hidden">Rating</span>
</div>
</div>
<p className="reviews__text">
{review.comment}
</p>
<time className="reviews__time" dateTime="2019-04-24">{review.date}</time>
</div>
</li>
);
}
export default ReviewItem;
23 changes: 23 additions & 0 deletions src/components/reviews-list/reviews-list.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { Review } from '../../types/review';
import ReviewItem from '../reviews-item/reviews-item';
import CommentForm from '../../components/comment-form/comment-form';

type ReviewsListProps = {
reviews: Review[];
};

function ReviewsList({ reviews }: ReviewsListProps): JSX.Element {
return (
<section className="offer__reviews reviews">
<h2 className="reviews__title">Reviews &middot; <span className="reviews__amount">{reviews.length}</span></h2>
<ul className="reviews__list">
{reviews.map((review) => (
<ReviewItem key={review.id} review={review} />
))}
</ul>
<CommentForm />
</section>
);
}

export default ReviewsList;
2 changes: 1 addition & 1 deletion src/hooks/use-map.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ function useMap(
const isRenderedRef = useRef<boolean>(false);

useEffect(() => {
if (mapRef.current !== null && !isRenderedRef.current) {
if (mapRef.current && !isRenderedRef.current) {
const instance = new Map(mapRef.current, {
center: {
lat: city.lat,
Expand Down
3 changes: 1 addition & 2 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@ import React from 'react';
import ReactDOM from 'react-dom/client';
import App from './components/app/app';
import { Settings } from './const';
import { offers } from './mocks/offers';

const root = ReactDOM.createRoot(
document.getElementById('root') as HTMLElement
);

root.render(
<React.StrictMode>
<App placesCount={Settings.placesCount} offers={offers}/>
<App placesCount={Settings.placesCount}/>
</React.StrictMode>
);
14 changes: 7 additions & 7 deletions src/mocks/offers.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Offer } from '../types/offer';
import { reviews } from './reviews';
import { REVIEWS } from './reviews';

export const offers: Offer[] = [
export const OFFERS: Offer[] = [
{
id: '1',
image: ['img/apartment-01.jpg'],
Expand All @@ -11,7 +11,7 @@ export const offers: Offer[] = [
type: 'Apartment',
isFavorite: false,
rating: 4,
reviews: [reviews[0]]
reviews: [REVIEWS[0]]
},
{
id: '2',
Expand All @@ -22,7 +22,7 @@ export const offers: Offer[] = [
type: 'Room',
isFavorite: true,
rating: 4,
reviews: [reviews[1]]
reviews: [REVIEWS[1]]
},
{
id: '3',
Expand All @@ -32,8 +32,8 @@ export const offers: Offer[] = [
title: 'Canal View Prinsengracht',
type: 'Apartment',
isFavorite: false,
rating: 4,
reviews: [reviews[2]]
rating: 4.7,
reviews: [REVIEWS[2]]
},
{
id: '4',
Expand All @@ -44,6 +44,6 @@ export const offers: Offer[] = [
type: 'Apartment',
isFavorite: true,
rating: 5,
reviews: [reviews[3]]
reviews: [REVIEWS[3]]
},
];
2 changes: 1 addition & 1 deletion src/mocks/reviews.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Review } from '../types/review';

export const reviews: Review[] = [
export const REVIEWS: Review[] = [
{
id: '1',
avatar: 'img/avatar-angelina.jpg',
Expand Down
2 changes: 1 addition & 1 deletion src/pages/main-screen/main-screen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ function MainScreen({placesCount, offers}: MainScreenProps): JSX.Element {
<li className="places__option" tabIndex={0}>Top rated first</li>
</ul>
</form>
<OfferList offers={offers} />
<OfferList offers={offers} isStandartCardType/>
</section>
<div className="cities__right-section">
<section className="cities__map map">
Expand Down
Loading

0 comments on commit 75bb2a3

Please sign in to comment.