diff --git a/src/main.js b/src/main.js index 0605f4f..11793dc 100644 --- a/src/main.js +++ b/src/main.js @@ -17,7 +17,7 @@ import OffersApiService from './api-service/offers-api-server.js'; import { AUTHORIZATION, END_POINT } from './const.js'; -const siteMainElement = document.querySelector('.page-main'); +const siteMainElement = document.querySelector('.trip-events'); const tripInfoElement = document.querySelector('.trip-main'); const filterElement = tripInfoElement.querySelector('.trip-controls__filters'); diff --git a/src/model/point-model.js b/src/model/point-model.js index 5da8d66..6c04122 100644 --- a/src/model/point-model.js +++ b/src/model/point-model.js @@ -5,7 +5,7 @@ export default class PointsModel extends Observable { #pointsApiService = null; #points = []; - constructor({pointsApiService}) { + constructor({ pointsApiService }) { super(); this.#pointsApiService = pointsApiService; } diff --git a/src/presenter/point-presenter.js b/src/presenter/point-presenter.js index a5835e8..338e75f 100644 --- a/src/presenter/point-presenter.js +++ b/src/presenter/point-presenter.js @@ -79,25 +79,26 @@ export default class PointPresenter { remove(prevPointEditComponent); } - setSaving = () => { + setSaving() { if (this.#mode === Mode.EDITING) { this.#pointEditComponent.updateElement({ isDisabled: true, isSaving: true }); } - }; + } - setDeleting = () => { + setDeleting() { this.#pointEditComponent.updateElement({ isDisabled: true, isDeleting: true }); - }; + } - setAborting = () => { + setAborting() { if (this.#mode === Mode.DEFAULT) { this.#pointComponent.shake(); + return; } const resetFormState = () => { @@ -107,9 +108,8 @@ export default class PointPresenter { isDeleting: false, }); }; - this.#pointEditComponent.shake(resetFormState); - }; + } destroy() { remove(this.#pointComponent); diff --git a/src/presenter/trip-presenter.js b/src/presenter/trip-presenter.js index 8207319..2fbc76f 100644 --- a/src/presenter/trip-presenter.js +++ b/src/presenter/trip-presenter.js @@ -183,12 +183,20 @@ export default class TripPresenter { switch(actionType) { case UserAction.UPDATE_POINT: - try { - this.#pointPresenters.get(update.id).setSaving(); - await this.#pointsModel.updatePoint(updateType, update); - } catch (err) { - this.#pointPresenters.get(update.point.id).setAborting(); - } + if(update.point){ + try { + this.#pointPresenters.get(update.point.id).setSaving(); + await this.#pointsModel.updatePoint(updateType, update.point); + } catch (err) { + this.#pointPresenters.get(update.point.id).setAborting(); + } + } else { + try { + this.#pointPresenters.get(update.id).setSaving(); + await this.#pointsModel.updatePoint(updateType, update); + } catch (err) { + this.#pointPresenters.get(update.id).setAborting(); + }} break; case UserAction.ADD_POINT: try { diff --git a/src/template/editing-form-template.js b/src/template/editing-form-template.js index 495a5a3..426a5e2 100644 --- a/src/template/editing-form-template.js +++ b/src/template/editing-form-template.js @@ -13,12 +13,12 @@ function createPointType({ currentType, isDisabled }) { function createPointOffer({ offers, currentOffers, isDisabled }) { return currentOffers.offers?.map((offer) => `
- -
`).join(''); } @@ -79,10 +79,10 @@ function createButtonsTemplate({ pointType, isSaving, isDeleting, isDisabled }) function createEditPointTemplate({state, pointDestinations, pointOffers, pointType}) { const { point, isDisabled, isSaving, isDeleting } = state; - const { type, dateFrom, dateTo, basePrice, offers } = state.point; + const { dateFrom, dateTo, basePrice, offers, type } = point; - const currentDestination = pointDestinations.find((destination) => destination.id === state.point.destination); - const currentOffers = pointOffers.find((offer) => offer.type === state.point.type); + const currentDestination = pointDestinations.find((destination) => destination.id === point.destination); + const currentOffers = pointOffers.find((offer) => offer.type === point.type); const destinationName = (currentDestination) ? currentDestination.name : ''; return (` @@ -128,11 +128,15 @@ function createEditPointTemplate({state, pointDestinations, pointOffers, pointTy ${createButtonsTemplate({ pointType, isSaving, isDeleting, isDisabled })}
+ ${currentOffers.offers.length ? `

Offers

- ${createPointOffer({ offers, currentOffers, isDisabled })} -
- ${currentDestination ? `
+ +
+ ${createPointOffer({ offers, currentOffers, isDisabled })} +
+
` : ''} + ${currentDestination?.description && currentDestination?.pictures.length ? `
${createDestination(currentDestination)}
` : ''}
diff --git a/src/view/event-list-empty-view.js b/src/view/event-list-empty-view.js index a08fa97..b55bcc4 100644 --- a/src/view/event-list-empty-view.js +++ b/src/view/event-list-empty-view.js @@ -4,7 +4,7 @@ import { createEmptyListPointsTemplate } from '../template/event-list-empty-temp export default class EventListEmptyView extends AbstractView { #filterType = null; - constructor({filterType}) { + constructor({ filterType }) { super(); this.#filterType = filterType; } diff --git a/src/view/filter-points-view.js b/src/view/filter-points-view.js index ec47f41..42c1091 100644 --- a/src/view/filter-points-view.js +++ b/src/view/filter-points-view.js @@ -6,7 +6,7 @@ export default class FilterPointsView extends AbstractView { #currentFilter = null; #handleFilterTypeChange = null; - constructor({filters, currentFilter, onFilterTypeChange}) { + constructor({ filters, currentFilter, onFilterTypeChange }) { super(); this.#filters = filters; this.#currentFilter = currentFilter; diff --git a/src/view/trip-info-view.js b/src/view/trip-info-view.js index a06953d..4479542 100644 --- a/src/view/trip-info-view.js +++ b/src/view/trip-info-view.js @@ -4,7 +4,7 @@ import { createTripInfoTemplate } from '../template/trip-info-template.js'; export default class TripInfoView extends AbstractView { #info = null; - constructor({info}) { + constructor({ info }) { super(); this.#info = info; }