Skip to content

Commit

Permalink
feat: display end boost date
Browse files Browse the repository at this point in the history
  • Loading branch information
rasulov1337 committed Dec 16, 2024
1 parent 7ffa840 commit dc9ebf9
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 3 deletions.
8 changes: 6 additions & 2 deletions src/components/HorizontalAdCard/HorizontalAdCard.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@
<img class='horizontal-ad-card__img' src='{{image.path}}' />

<div class='horizontal-ad-card__info'>
<p class='horizontal-ad-card__city'>{{cityName}}
{{#if priority}} 🚀 {{/if}}</p>
<p class='horizontal-ad-card__city'>{{cityName}}</p>
<p class='horizontal-ad-card__address'>{{address}}</p>
{{#if priority}}
<p class='horizontal-ad-card__address'>🚀 Буст действует еще
{{boostDaysLeft}}
дней</p>
{{/if}}
<div class='horizontal-ad-card__buttons-container'>
<button
class='horizontal-ad-card__open-btn js-open-btn'
Expand Down
9 changes: 8 additions & 1 deletion src/components/HorizontalAdCard/HorizontalAdCard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export interface HorizontalAdCardData {
address: string;
image: string;
priority: number;
endBoostDate: string;
}

export default function HorizontalAdCard(
Expand All @@ -20,7 +21,13 @@ export default function HorizontalAdCard(
const template = Handlebars.templates['HorizontalAdCard.hbs'];
const pageContainer = document.createElement('div');

pageContainer.innerHTML = template(cardData);
pageContainer.innerHTML = template({
...cardData,
boostDaysLeft: Math.round(
(new Date(cardData.endBoostDate).valueOf() - new Date().valueOf()) /
(60 * 60 * 24 * 1000)
).toString(),
});

(pageContainer.querySelector('.js-open-btn') as HTMLButtonElement).onclick =
(e) => {
Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ const renderAdListPage = async (action: 'edit' | undefined, adId: string) => {
address: d.address,
image: d.images[0],
priority: d.priority,
endBoostDate: d.endBoostDate,
});
}
}
Expand Down
1 change: 1 addition & 0 deletions src/pages/AdListPage/AdListPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ function AdListPage(data: HorizontalAdCardData[], isHost: boolean) {
address: d.address,
image: d.image,
priority: d.priority,
endBoostDate: d.endBoostDate,
},
{
onOpen: () => router.navigateTo(`/ads/?id=${d.id}`),
Expand Down

0 comments on commit dc9ebf9

Please sign in to comment.