From bf41dc6ee341ff3757a8aecad5a3c76bd4e0d4ea Mon Sep 17 00:00:00 2001 From: alo Date: Wed, 19 Jun 2024 14:27:44 +0500 Subject: [PATCH] =?UTF-8?q?=D0=BF=D0=BE=D1=81=D0=BB=D0=B5=D0=B4=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5=20=D0=BF=D1=80=D0=B0=D0=B2=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/model/cities-model.js | 6 +++--- src/model/offers-model.js | 6 +++--- src/model/point-model.js | 8 ++++---- src/presenter/board-presenter.js | 8 ++++---- src/presenter/filter-presenter.js | 20 ++++++++++---------- src/presenter/new-point-presenter.js | 1 - src/presenter/point-presenter.js | 4 ++++ src/view/point-view.js | 3 ++- 8 files changed, 30 insertions(+), 26 deletions(-) diff --git a/src/model/cities-model.js b/src/model/cities-model.js index dc92112..113c5a4 100644 --- a/src/model/cities-model.js +++ b/src/model/cities-model.js @@ -6,12 +6,12 @@ export default class CitiesModel { this.#pointApiService = pointApiService; } - async init() { - this.#cities = await this.#pointApiService.destinations; + get cities() { return this.#cities; } - get cities() { + async init() { + this.#cities = await this.#pointApiService.destinations; return this.#cities; } diff --git a/src/model/offers-model.js b/src/model/offers-model.js index 8e124f9..c173d9f 100644 --- a/src/model/offers-model.js +++ b/src/model/offers-model.js @@ -6,12 +6,12 @@ export default class OffersModel { this.#pointApiService = pointApiService; } - async init() { - this.#offers = await this.#pointApiService.offers; + get offers() { return this.#offers; } - get offers() { + async init() { + this.#offers = await this.#pointApiService.offers; return this.#offers; } diff --git a/src/model/point-model.js b/src/model/point-model.js index d5ae90f..68703c4 100644 --- a/src/model/point-model.js +++ b/src/model/point-model.js @@ -13,6 +13,10 @@ export default class TaskModel extends Observable { this.#points = []; } + get points() { + return this.#points.sort(sortByDay); + } + async init() { try { const points = await this.#pointApiService.points; @@ -24,10 +28,6 @@ export default class TaskModel extends Observable { this._notify(UpdateType.INIT); } - get points() { - return this.#points.sort(sortByDay); - } - async updatePoint(updateType, update) { try { const response = await this.#pointApiService.updatePoint(update); diff --git a/src/presenter/board-presenter.js b/src/presenter/board-presenter.js index 2e77a9c..4931657 100644 --- a/src/presenter/board-presenter.js +++ b/src/presenter/board-presenter.js @@ -56,10 +56,6 @@ export default class BoardPresenter { this.#filterModel.addObserver(this.#handleModelPoint); } - init() { - this.#renderBoard(); - } - get points() { this.#filterType = this.#filterModel.filter; const points = this.#pointModel.points; @@ -75,6 +71,10 @@ export default class BoardPresenter { return filteredPoints; } + init() { + this.#renderBoard(); + } + createPoint() { this.#currentSortType = SortType.DAY; this.#filterModel.setFilter(UpdateType.MAJOR, FilterType.EVERYTHING); diff --git a/src/presenter/filter-presenter.js b/src/presenter/filter-presenter.js index f96ea94..538c9e3 100644 --- a/src/presenter/filter-presenter.js +++ b/src/presenter/filter-presenter.js @@ -18,6 +18,16 @@ export default class FilterPresenter { this.#filterModel.addObserver(this.#handleModelPoint); } + get filters() { + const points = this.#pointModel.points; + + return Object.values(FilterType).map((type) => ({ + type, + name: type.toUpperCase(), + count: filters[type](points).length + })); + } + init() { const filter = this.filters; const prevFilterComponent = this.#filterComponent; @@ -37,16 +47,6 @@ export default class FilterPresenter { remove(prevFilterComponent); } - get filters() { - const points = this.#pointModel.points; - - return Object.values(FilterType).map((type) => ({ - type, - name: type.toUpperCase(), - count: filters[type](points).length - })); - } - #handleModelPoint = () => { this.init(); }; diff --git a/src/presenter/new-point-presenter.js b/src/presenter/new-point-presenter.js index e1806b2..d43fdb4 100644 --- a/src/presenter/new-point-presenter.js +++ b/src/presenter/new-point-presenter.js @@ -78,7 +78,6 @@ export default class NewPointPresenter { UpdateType.MINOR, point, ); - this.destroy(); }; #handleResetClick = () => { diff --git a/src/presenter/point-presenter.js b/src/presenter/point-presenter.js index 6b15c10..092fa1d 100644 --- a/src/presenter/point-presenter.js +++ b/src/presenter/point-presenter.js @@ -98,6 +98,10 @@ export default class PointPresenter { } setAborting() { + if (this.#mode === Mode.DEFAULT){ + this.#pointComponent.shake(); + return; + } const resetFormState = () => { this.#pointEditComponent.updateElement({ isDisabled: false, diff --git a/src/view/point-view.js b/src/view/point-view.js index b647bfc..35771d1 100644 --- a/src/view/point-view.js +++ b/src/view/point-view.js @@ -4,6 +4,7 @@ import { getDateDifference, getMonthAndDate, getTime } from '../utils/point-util function createPointTemplate(point, pointCity, pointOffers) { const { type, offers, dateFrom, dateTo, basePrice, isFavorite } = point; + const favoriteClass = isFavorite ? 'event_favorite-btn--active' : ''; return ( `
  • @@ -32,7 +33,7 @@ function createPointTemplate(point, pointCity, pointOffers) { ${offer.price}
  • ` : '').join('')} -