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

Контроль и ограничения (часть 1) #9

Merged
merged 2 commits into from
Nov 19, 2024
Merged
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
15 changes: 2 additions & 13 deletions src/Pages/offer-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { OfferHost } from '../components/offer/offer-host.tsx';
import { capitalize, pluralizeAndCombine } from '../utils/string-utils.ts';
import { Rating } from '../components/rating.tsx';
import { OfferGallery } from '../components/offer/offer-gallery.tsx';
import { BookmarkButton } from '../components/bookmark-button.tsx';

export function OfferPage(): React.JSX.Element {
const offerId = useParams().id;
Expand All @@ -36,19 +37,7 @@ export function OfferPage(): React.JSX.Element {
)}
<div className="offer__name-wrapper">
<h1 className="offer__name">{currentOffer.title}</h1>
<button
className="offer__bookmark-button button"
type="button"
>
<svg
className="offer__bookmark-icon"
width="31"
height="33"
>
<use xlinkHref="#icon-bookmark"></use>
</svg>
<span className="visually-hidden">To bookmarks</span>
</button>
<BookmarkButton size='big' isFavorite={currentOffer.isFavorite} usagePlace='offer' />
</div>
<Rating
rating={currentOffer.rating}
Expand Down
37 changes: 37 additions & 0 deletions src/components/bookmark-button.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import React from 'react';

interface BookmarkButtonProps {
size: 'big' | 'small';
isFavorite?: boolean;
usagePlace: 'offer' | 'place-card';
}

export function BookmarkButton({size, isFavorite, usagePlace}: BookmarkButtonProps): React.JSX.Element {
const sizes = {
'small': {
'width': 18,
'height': 19,
},
'big': {
'width': 31,
'height': 33,
}
};
return (
<button
className={`${usagePlace}__bookmark-button ${isFavorite ? `${usagePlace}__bookmark-button--active` : ''} button`}
type="button"
>
<svg
className={`${usagePlace}__bookmark-icon`}
width={sizes[size].width}
height={sizes[size].height}
>
<use xlinkHref="#icon-bookmark"></use>
</svg>
<span className="visually-hidden">
{isFavorite ? 'In bookmarks' : 'To bookmarks'}
</span>
</button>
);
}
13 changes: 2 additions & 11 deletions src/components/offer/offer-card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Link } from 'react-router-dom';
import { AppRoutes } from '../../dataTypes/enums/app-routes.ts';
import cn from 'classnames';
import { Rating } from '../rating.tsx';
import { BookmarkButton } from '../bookmark-button.tsx';

interface PlaceCardProps {
id: string;
Expand Down Expand Up @@ -71,17 +72,7 @@ export function OfferCard({
<b className="place-card__price-value">&euro;{price}</b>
<span className="place-card__price-text">&#47;&nbsp;night</span>
</div>
<button
className={`place-card__bookmark-button ${isFavorite ? 'place-card__bookmark-button--active' : ''} button`}
type="button"
>
<svg className="place-card__bookmark-icon" width="18" height="19">
<use xlinkHref="#icon-bookmark"></use>
</svg>
<span className="visually-hidden">
{isFavorite ? 'In bookmarks' : 'To bookmarks'}
</span>
</button>
<BookmarkButton size='small' isFavorite={isFavorite} usagePlace='place-card' />
</div>
<Rating rating={rating} usePlace="place-card" />
<h2 className="place-card__name">
Expand Down
2 changes: 1 addition & 1 deletion src/mocks/detailed-offer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const detailedOfferMocks = [
longitude: 4.673877537499948,
zoom: 8,
},
isFavorite: false,
isFavorite: true,
isPremium: false,
rating: 4,
description:
Expand Down
Loading