Skip to content

Commit

Permalink
rewrite adpage to use reactivity
Browse files Browse the repository at this point in the history
  • Loading branch information
rasulov1337 committed Nov 10, 2024
1 parent d6f10fb commit 0b2a987
Show file tree
Hide file tree
Showing 10 changed files with 304 additions and 309 deletions.
1 change: 0 additions & 1 deletion components/AdCard/AdCard.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
src='{{currentImagePath}}'
alt='Housing card image'
/>
<p>{{toShowIndex}}</p>
<div class='housing-card__image-pagination-div js-pagination-div'>
<!-- Здесь будут кружочки -->
{{#each images}}
Expand Down
17 changes: 9 additions & 8 deletions components/AdCard/AdCard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export default class AdCard extends ReactiveComponent {
toShowIndex: 0,
},
computedValues: {
currentImagePath: (state: Record<string, unknown>) => {
currentImagePath: (state) => {
return data.images[state.toShowIndex as number].path;
},
},
Expand All @@ -43,9 +43,11 @@ export default class AdCard extends ReactiveComponent {
router.navigateTo(`/ads/?id=${this.#data.id}`);
};

this.thisElement
.querySelector('.js-like-button')!
.addEventListener('click', this.#addToFavorite);
(
this.thisElement.querySelector(
'.js-like-button'
) as HTMLButtonElement
).onclick = this.#addToFavorite;

setTimeout(() => {
this.#addImageScrolling();
Expand All @@ -67,10 +69,8 @@ export default class AdCard extends ReactiveComponent {
'housing-card__circle'
);

imgElem.addEventListener('mousemove', (e) =>
this.#onMouseMove(e, areaFraction)
);
imgElem.addEventListener('mouseout', () => this.#onMouseOut());
imgElem.onmousemove = (e) => this.#onMouseMove(e, areaFraction);
imgElem.onmouseout = () => this.#onMouseOut();

this.#circles[this.state.toShowIndex as number].classList.add(
'housing-card__circle--fill'
Expand All @@ -91,6 +91,7 @@ export default class AdCard extends ReactiveComponent {
}
console.log('new to show index:', toShowIndex);

// todo: fix this
// setTimeout(() => {
this.state.toShowIndex = toShowIndex;
// }, SCROLL_DELAY);
Expand Down
13 changes: 10 additions & 3 deletions components/AdPage/AdPage.hbs
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
<div class='ad-page'>
<div class='ad-page' id='{{elementId}}'>
<main>
<div class='advert-images-carousel'>
<div class='advert-images-carousel__main-img-div js-main-img-div'>
<img class='advert-images-carousel__img-background' />
<img class='advert-images-carousel__main-img' />
<img
class='advert-images-carousel__img-background'
src='{{currentImagePath}}'
/>
<img
class='advert-images-carousel__main-img'
src='{{currentImagePath}}'
/>
</div>
<div class='advert-images-carousel__secondary_images'>
{{#each images}}
Expand Down Expand Up @@ -33,6 +39,7 @@
class='ad-page__fullscreen-overlay ad-page__fullscreen-overlay_hidden js-fullscreen-overlay'
>
<img
src='{{currentImagePath}}'
class='ad-page__fullscreen-overlay__image js-main-image-fullscreen'
/>
</div>
Expand Down
206 changes: 0 additions & 206 deletions components/AdPage/AdPage.sass

This file was deleted.

Loading

0 comments on commit 0b2a987

Please sign in to comment.